@ikas/storefront 2.0.42 → 2.0.45

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{makeAutoObservable as e}from"mobx";import{IkasThemeComponent as o}from"./component/index.js";import{IkasThemeComponentProp as n,IkasThemeComponentPropType as t}from"./component/prop/index.js";import{IkasThemeCustomData as r}from"./custom-data/index.js";import{IkasThemePage as i,IkasThemePageType as s}from"./page/index.js";import{IkasThemePageComponent as a}from"./page/component/index.js";import{IkasThemeSettings as p}from"./settings/index.js";var u="checkout",m=function(){function u(n){var t;void 0===n&&(n={}),this.name=n.name||"",this.components=n.components?n.components.map((function(e){return new o(e)})):[],this.pages=n.pages?n.pages.map((function(e){return new i(e)})):[],this.settings=n.settings?new p(n.settings):new p,this.customData=n.customData?null===(t=n.customData)||void 0===t?void 0:t.map((function(e){return new r(e)})):[],this.createCheckoutData(),e(this)}return Object.defineProperty(u.prototype,"headerComponent",{get:function(){return this.components.find((function(e){return e.isHeader}))},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"footerComponent",{get:function(){return this.components.find((function(e){return e.isFooter}))},enumerable:!1,configurable:!0}),u.prototype.createCheckoutData=function(){var e=this.components.find((function(e){return"checkout"===e.id})),r=this.pages.find((function(e){return"checkout"===e.id}));e||(e=new o({id:"checkout",dir:"",displayName:"",props:[new n({name:"buttonBgColor",isRequired:!1,type:t.COLOR}),new n({name:"buttonTextColor",isRequired:!1,type:t.COLOR}),new n({name:"buttonDisabledBgColor",isRequired:!1,type:t.COLOR}),new n({name:"buttonDisabledTextColor",isRequired:!1,type:t.COLOR}),new n({name:"primaryTextColor",isRequired:!1,type:t.COLOR}),new n({name:"secondaryTextColor",isRequired:!1,type:t.COLOR}),new n({name:"primaryBgColor",isRequired:!1,type:t.COLOR}),new n({name:"secondaryBgColor",isRequired:!1,type:t.COLOR}),new n({name:"borderColor",isRequired:!1,type:t.COLOR}),new n({name:"cardBgColor",isRequired:!1,type:t.COLOR}),new n({name:"errorColor",isRequired:!1,type:t.COLOR}),new n({name:"errorLightColor",isRequired:!1,type:t.COLOR}),new n({name:"warningColor",isRequired:!1,type:t.COLOR}),new n({name:"warningLightColor",isRequired:!1,type:t.COLOR}),new n({name:"successColor",isRequired:!1,type:t.COLOR}),new n({name:"successLightColor",isRequired:!1,type:t.COLOR})]}),this.components.push(e)),r||this.pages.push(new i({id:"checkout",type:s.CHECKOUT,components:[new a({componentId:e.id,propValues:{buttonBgColor:c,buttonTextColor:C,buttonDisabledBgColor:d,buttonDisabledTextColor:l,primaryTextColor:g,secondaryTextColor:F,primaryBgColor:O,secondaryBgColor:R,borderColor:y,cardBgColor:h,errorColor:f,errorLightColor:w,warningColor:L,warningLightColor:b,successColor:q,successLightColor:x}})]}))},u}(),c="#272727",C="#FFFFFF",d="#F7F7F9",l="#8A8B94",g="#272727",F="#8A8B94",O="#FFFFFF",R="#F7F7F9",y="#E5E4E9",h="#F7F7F9",f="#FB4E4E",w="#FCF3F4",L="#FFBC1F",b="#FFFAEE",q="#2DCA73",x="#F6FFED";export{u as CHECKOUT_ID,m as IkasTheme};
1
+ import{makeAutoObservable as e}from"mobx";import{IkasThemeComponent as o}from"./component/index.js";import{IkasThemeComponentProp as n,IkasThemeComponentPropType as t}from"./component/prop/index.js";import{IkasThemeCustomData as r}from"./custom-data/index.js";import{IkasThemePage as i,IkasThemePageType as s}from"./page/index.js";import{IkasThemePageComponent as a}from"./page/component/index.js";import{IkasThemeSettings as p}from"./settings/index.js";var u="checkout",m=function(){function u(n){var t;void 0===n&&(n={}),this.name=n.name||"",this.components=n.components?n.components.map((function(e){return new o(e)})):[],this.pages=n.pages?n.pages.map((function(e){return new i(e)})):[],this.settings=n.settings?new p(n.settings):new p,this.customData=n.customData?null===(t=n.customData)||void 0===t?void 0:t.map((function(e){return new r(e)})):[],this.createCheckoutData(),e(this)}return Object.defineProperty(u.prototype,"headerComponent",{get:function(){return this.components.find((function(e){return e.isHeader}))},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"footerComponent",{get:function(){return this.components.find((function(e){return e.isFooter}))},enumerable:!1,configurable:!0}),u.prototype.createCheckoutData=function(){var e=this.components.find((function(e){return"checkout"===e.id})),r=this.pages.find((function(e){return"checkout"===e.id}));e||(e=new o({id:"checkout",dir:"",displayName:"",props:[new n({name:"showTax",isRequired:!1,type:t.BOOLEAN}),new n({name:"buttonBgColor",isRequired:!1,type:t.COLOR}),new n({name:"buttonTextColor",isRequired:!1,type:t.COLOR}),new n({name:"buttonDisabledBgColor",isRequired:!1,type:t.COLOR}),new n({name:"buttonDisabledTextColor",isRequired:!1,type:t.COLOR}),new n({name:"primaryTextColor",isRequired:!1,type:t.COLOR}),new n({name:"secondaryTextColor",isRequired:!1,type:t.COLOR}),new n({name:"primaryBgColor",isRequired:!1,type:t.COLOR}),new n({name:"secondaryBgColor",isRequired:!1,type:t.COLOR}),new n({name:"borderColor",isRequired:!1,type:t.COLOR}),new n({name:"cardBgColor",isRequired:!1,type:t.COLOR}),new n({name:"errorColor",isRequired:!1,type:t.COLOR}),new n({name:"errorLightColor",isRequired:!1,type:t.COLOR}),new n({name:"warningColor",isRequired:!1,type:t.COLOR}),new n({name:"warningLightColor",isRequired:!1,type:t.COLOR}),new n({name:"successColor",isRequired:!1,type:t.COLOR}),new n({name:"successLightColor",isRequired:!1,type:t.COLOR})]}),this.components.push(e)),r||this.pages.push(new i({id:"checkout",type:s.CHECKOUT,components:[new a({componentId:e.id,propValues:{showTax:!0,buttonBgColor:c,buttonTextColor:C,buttonDisabledBgColor:d,buttonDisabledTextColor:l,primaryTextColor:O,secondaryTextColor:g,primaryBgColor:F,secondaryBgColor:R,borderColor:y,cardBgColor:h,errorColor:w,errorLightColor:f,warningColor:L,warningLightColor:b,successColor:x,successLightColor:q}})]}))},u}(),c="#272727",C="#FFFFFF",d="#F7F7F9",l="#8A8B94",O="#272727",g="#8A8B94",F="#FFFFFF",R="#F7F7F9",y="#E5E4E9",h="#F7F7F9",w="#FB4E4E",f="#FCF3F4",L="#FFBC1F",b="#FFFAEE",x="#2DCA73",q="#F6FFED";export{u as CHECKOUT_ID,m as IkasTheme};
@@ -1 +1 @@
1
- import{__awaiter as e,__generator as t}from'../../../../ext/tslib/tslib.es6.js';import{makeObservable as r,computed as s,observable as i,action as a}from"mobx";import{Validator as o}from"../index.js";import{RequiredRule as n,EmailRule as l,MinRule as u}from"../rules/index.js";import{Analytics as m}from"../../../../analytics/analytics.js";import"../../../../analytics/head/index.js";var d=function(){function d(e){var t=this;this.model={firstName:"",lastName:"",email:"",password:"",attributes:void 0,isMarketingAccepted:!1},this.onFirstNameChange=function(e){t.firstName=e},this.onLastNameChange=function(e){t.lastName=e},this.onEmailChange=function(e){t.email=e},this.onPasswordChange=function(e){t.password=e},r(this,{emailErrorMessage:s,passwordErrorMessage:s,firstNameErrorMessage:s,lastNameErrorMessage:s,hasError:s,redirect:s,model:i,validateAll:a,register:a}),this.store=e.store,this.validator=new o(this.model,[new n({fieldKey:"firstName",valuePath:"firstName",message:e.message.requiredRule}),new n({fieldKey:"lastName",valuePath:"lastName",message:e.message.requiredRule}),new n({fieldKey:"email",valuePath:"email",message:e.message.requiredRule}),new n({fieldKey:"password",valuePath:"password",message:e.message.requiredRule}),new l({fieldKey:"email",valuePath:"email",message:e.message.emailRule}),new u({fieldKey:"password",valuePath:"password",minValue:6,message:e.message.minRule})])}return Object.defineProperty(d.prototype,"firstName",{get:function(){return this.model.firstName},set:function(e){this.model.firstName=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"lastName",{get:function(){return this.model.lastName},set:function(e){this.model.lastName=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"email",{get:function(){return this.model.email},set:function(e){this.model.email=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"password",{get:function(){return this.model.password},set:function(e){this.model.password=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"isMarketingAccepted",{get:function(){return this.model.isMarketingAccepted},set:function(e){this.model.isMarketingAccepted=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"hasError",{get:function(){return this.validator.hasError},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"firstNameErrorMessage",{get:function(){return this.validator.results.firstName.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"lastNameErrorMessage",{get:function(){return this.validator.results.lastName.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"emailErrorMessage",{get:function(){return this.validator.results.email.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"passwordErrorMessage",{get:function(){return this.validator.results.password.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"attributes",{get:function(){return this.model.attributes},set:function(e){this.model.attributes=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"redirect",{get:function(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("redirect")},enumerable:!1,configurable:!0}),d.prototype.validateAll=function(){return this.validator.validateAll()},d.prototype.register=function(){var r;return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return e={isFormError:!1,isSuccess:!1},[4,this.validateAll()];case 1:if(t.sent())return e.isFormError=!0,[2,e];t.label=2;case 2:return t.trys.push([2,4,,5]),[4,this.store.customerStore.register(this.model.firstName,this.model.lastName,this.model.email,this.model.password,this.model.isMarketingAccepted,this.model.attributes)];case 3:return t.sent()&&(e.isSuccess=!0,m.completeRegistration(this.model.email,null===(r=this.store.customerStore.customer)||void 0===r?void 0:r.id)),[2,e];case 4:return t.sent(),[2,e];case 5:return[2]}}))}))},d}();export{d as RegisterForm};
1
+ import{__awaiter as e,__generator as t}from'../../../../ext/tslib/tslib.es6.js';import{makeObservable as r,computed as s,observable as i,action as a}from"mobx";import{Validator as o}from"../index.js";import{RequiredRule as n,EmailRule as l,MinRule as u}from"../rules/index.js";import{Analytics as m}from"../../../../analytics/analytics.js";import"../../../../analytics/head/index.js";var d=function(){function d(e){var t=this;this.model={firstName:"",lastName:"",email:"",password:"",attributes:void 0,isMarketingAccepted:!1},this.onFirstNameChange=function(e){t.firstName=e},this.onLastNameChange=function(e){t.lastName=e},this.onEmailChange=function(e){t.email=e},this.onPasswordChange=function(e){t.password=e},r(this,{emailErrorMessage:s,passwordErrorMessage:s,firstNameErrorMessage:s,lastNameErrorMessage:s,hasError:s,redirect:s,model:i,validateAll:a,register:a}),this.store=e.store,this.validator=new o(this.model,[new n({fieldKey:"firstName",valuePath:"firstName",message:e.message.requiredRule}),new n({fieldKey:"lastName",valuePath:"lastName",message:e.message.requiredRule}),new n({fieldKey:"email",valuePath:"email",message:e.message.requiredRule}),new n({fieldKey:"password",valuePath:"password",message:e.message.requiredRule}),new l({fieldKey:"email",valuePath:"email",message:e.message.emailRule}),new u({fieldKey:"password",valuePath:"password",minValue:6,message:e.message.minRule})])}return Object.defineProperty(d.prototype,"firstName",{get:function(){return this.model.firstName},set:function(e){this.model.firstName=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"lastName",{get:function(){return this.model.lastName},set:function(e){this.model.lastName=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"email",{get:function(){return this.model.email},set:function(e){this.model.email=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"password",{get:function(){return this.model.password},set:function(e){this.model.password=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"isMarketingAccepted",{get:function(){return this.model.isMarketingAccepted},set:function(e){this.model.isMarketingAccepted=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"hasError",{get:function(){return this.validator.hasError},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"firstNameErrorMessage",{get:function(){return this.validator.results.firstName.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"lastNameErrorMessage",{get:function(){return this.validator.results.lastName.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"emailErrorMessage",{get:function(){return this.validator.results.email.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"passwordErrorMessage",{get:function(){return this.validator.results.password.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"attributes",{get:function(){return this.model.attributes},set:function(e){this.model.attributes=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"redirect",{get:function(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("redirect")},enumerable:!1,configurable:!0}),d.prototype.validateAll=function(){return this.validator.validateAll()},d.prototype.register=function(){return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return e={isFormError:!1,isSuccess:!1},[4,this.validateAll()];case 1:if(t.sent())return e.isFormError=!0,[2,e];t.label=2;case 2:return t.trys.push([2,4,,5]),[4,this.store.customerStore.register(this.model.firstName,this.model.lastName,this.model.email,this.model.password,this.model.isMarketingAccepted,this.model.attributes)];case 3:return t.sent()&&(e.isSuccess=!0,this.store.customerStore.customer&&m.completeRegistration(this.store.customerStore.customer)),[2,e];case 4:return t.sent(),[2,e];case 5:return[2]}}))}))},d}();export{d as RegisterForm};
@@ -1 +1 @@
1
- import{__awaiter as e,__generator as t,__assign as o,__spreadArray as r}from'../ext/tslib/tslib.es6.js';import i from"fs";import n from"next/config.js";import"../models/data/blog/index.js";import"../models/data/brand/index.js";import"../models/data/category/index.js";import"../models/data/checkout/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/index.js";import"../models/data/customer-review/index.js";import"mobx";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/installment-info/index.js";import"../models/data/order/index.js";import"../models/data/order/line-item/index.js";import"../api/product-option-file/index.js";import"../models/data/product/index.js";import"../models/data/variant-type/index.js";import"../models/data/product/variant/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product-attribute/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product-filter/index.js";import"../models/data/variant-type/variant-value/index.js";import"../models/data/order-transaction/index.js";import"../models/data/product-option-set/index.js";import"../models/data/raffle/index.js";import"../models/data/product-campaing/campaign/index.js";import"../models/data/customer-attribute/index.js";import"../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import{IkasTheme as s}from"../models/theme/theme.js";import{IkasThemePageType as a}from"../models/theme/page/index.js";import"../models/theme/component/prop/index.js";import"../models/theme/page/component/prop-value/link.js";import"../models/ui/brand-list/index.js";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-detail/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/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/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import"../models/theme/settings/index.js";import"../models/theme/custom-data/index.js";import{IkasStorefront as d}from"../models/data/storefront/index.js";import{IkasSalesChannel as l}from"../models/data/sales-channel/index.js";import{IkasStorefrontRouting as m}from"../models/data/storefront/routing/index.js";import{IkasStorefrontConfig as c}from"../storefront/index.js";import{IkasPageDataProvider as p}from"./page-data-get.js";import{IkasStorefrontThemeLocalization as u}from"../models/data/storefront/theme-localization/index.js";import{IkasStorefrontAPI as f}from"../api/storefront/index.js";import{I18NFileReader as g}from"../utils/i18n.js";import"../api/blog/index.js";import"../api/brand/index.js";import"../api/cart/index.js";import"../api/category/index.js";import{IkasCheckoutAPI as j}from"../api/checkout/index.js";import"../api/city/index.js";import"../api/country/index.js";import"../api/customer/index.js";import"../api/customer-review/index.js";import"../api/customer-review-summary/index.js";import"../api/district/index.js";import"../api/html-meta-data/index.js";import"../api/merchant/index.js";import"../api/product-search/index.js";import"../api/apollo.js";import"../api/favorite-product/index.js";import"../api/contact-form/index.js";import"../api/state/index.js";import"../api/product-option-set/index.js";import"../api/raffle/index.js";import"../api/back-in-stock-reminder/index.js";import"../api/product-campaign/index.js";import{getGoogleFontHref as x}from"../utils/google-fonts.js";var v=function(){function v(){}return v.readLocalTheme=function(){return new Promise((function(e,t){i.readFile("./src/theme.json",{flag:"a+"},(function(o,r){if(o)return t(o);var i=r.length?JSON.parse(r.toString()):{};e(new s(i))}))}))},v.readSettingsFile=function(){return new Promise((function(e){var t=n().serverRuntimeConfig.SETTINGS;i.readFile(t,{flag:"a+"},(function(t,o){if(t)return console.error("SETTINGS FILE READ ERROR!!!"),console.error(t),e(null);var r=o.length?JSON.parse(o.toString()):{};e(r)}))}))},v.getSettings=function(o){var r=this;return new Promise((function(n){return e(r,void 0,void 0,(function(){var e,r,s,a,p,g,j,x,h,S,C,y,I,b,w,k;return t(this,(function(t){switch(t.label){case 0:return"local"===process.env.NEXT_PUBLIC_ENV?c.storefrontId?[4,f.getStorefront(c.storefrontId)]:(console.error("Missing storefrontId in the config.json file!"),[2,n(null)]):[3,3];case 1:return(e=t.sent())?(r=e,[4,v.readLocalTheme()]):[2,n(null)];case 2:return s=t.sent(),a=v.createColorScript(s.settings),p=v.createFontScript(s.settings),g=[],a&&g.push(a),p&&g.push(p),n({storefront:r,themeLocalization:new u({themeJson:s}),salesChannel:new l({id:r.salesChannelId}),routing:r.routings.length?r.routings.find((function(e){return e.locale===o||e.id===o}))||r.routings[0]:new m({}),favicon:s.settings.favicon,stockPreference:s.settings.stockPreference,storefrontJSScripts:g,domain:"",productBackInStockSettings:{customerLoginRequired:!0},customerReviewSettings:{customerLoginRequired:!0,customerPurchaseRequired:!1}}),[3,5];case 3:return[4,v.readSettingsFile()];case 4:if(!(j=t.sent())||!j.localizationMap)return[2,n(null)];if(x=new d(j.storefront),h=new l(j.salesChannel),S=j.localizationMap,C=j.storefrontJSScripts||[],y=j.domain,I=j.productBackInStockSettings?{customerLoginRequired:j.productBackInStockSettings.customerLoginRequired}:null,b=j.customerReviewSettings?{customerLoginRequired:j.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:j.customerReviewSettings.customerPurchaseRequired||!1}:null,w=S[o],k=x.routings.find((function(e){return e.id===o||e.path===o})),!w||!k)return console.error("THEME LOCALIZATION PATH OR ROUTING MISSING!!!"),[2,n(null)];i.readFile(w,{flag:"a+"},(function(e,t){if(e)return console.error("THEME LOCALZIATION FILE READ ERROR!!!"),console.error(e),n(null);var o=t.length?JSON.parse(t.toString()):{},r=new u(o),i=r.themeJson.settings.favicon,s=r.themeJson.settings.stockPreference;if(r.themeJson.settings){var a=v.createColorScript(r.themeJson.settings),d=v.createFontScript(r.themeJson.settings);a&&C.push(a),d&&C.push(d)}n({storefront:x,themeLocalization:r,salesChannel:h,routing:k,favicon:i,stockPreference:s,storefrontJSScripts:C,domain:y,productBackInStockSettings:I,customerReviewSettings:b})})),t.label=5;case 5:return[2]}}))}))}))},v.getPageData=function(i,s,d,l,m){var u,f;return e(this,void 0,void 0,(function(){var e,x,h,S,C,y,I,b,w,k,P,R,L,T,B,E,V,J,F,O,N,D,A,q,z,M;return t(this,(function(t){switch(t.label){case 0:return e="local"===process.env.NEXT_PUBLIC_ENV,x=!e&&m,h=n().serverRuntimeConfig,x?[3,7]:(S=i.locale)?[4,v.getSettings(S)]:[2,{props:{},notFound:!0}];case 1:return(C=t.sent())&&C.storefront.mainStorefrontThemeId&&C.storefront.salesChannelId?(y=C.storefront,I=C.themeLocalization,b=C.salesChannel,w=C.routing,k=C.favicon,P=C.stockPreference,R=C.storefrontJSScripts,L=C.domain,T=C.productBackInStockSettings,B=C.customerReviewSettings,c.storefrontId=y.id,c.storefrontRoutingId=w.id,c.storefrontThemeId=y.mainStorefrontThemeId,c.salesChannelId=y.salesChannelId,c.priceListId=w.priceListId||void 0,c.stockLocationIds=null===(u=b.stockLocations)||void 0===u?void 0:u.map((function(e){return e.id})),c.routings=y.routings,c.paymentGateways=b.paymentGateways||[],c.gtmId=y.gtmId||void 0,c.fbpId=y.fbpId||void 0,c.analytics4Id=y.analytics4Id||void 0,c.universalAnalyticsId=y.universalAnalyticsId||void 0,c.favicon=k||null,c.stockPreference=P||null,c.storefrontJSScripts=R||[],c.domain=L,c.productBackInStockSettings=T,c.customerReviewSettings=B,(E=new p(I.themeJson,i.params,d)).possiblePageTypes=l||(d?[d]:[]),m?[3,3]:[4,E.getPageData()]):[2,{props:{},notFound:!0}];case 2:if(t.sent(),!E.page)return[2,{props:{},notFound:!0}];t.label=3;case 3:return V=m?E.theme.components.map((function(e){return e.id})):E.page.components.map((function(e){return e.componentId})),J=I.themeJson.components.filter((function(e){return m||V.includes(e.id)})),F=r(["common"],J.map((function(e){return e.dir})),!0),(d===a.CHECKOUT||m)&&F.push("checkout-page"),O=h.nextI18nConf,N=w.locale,[4,new g(N,F,e?void 0:O.localePath).read()];case 4:return D=t.sent(),c.translations=D,A={},d!==a.CHECKOUT?[3,6]:(q=null===(f=E.page)||void 0===f?void 0:f.components[0])?[4,j.listCheckoutSettings()]:[3,6];case 5:z=t.sent(),M={buttonBgColor:q.propValues.buttonBgColor,buttonTextColor:q.propValues.buttonTextColor,buttonDisabledBgColor:q.propValues.buttonDisabledBgColor,buttonDisabledTextColor:q.propValues.buttonDisabledTextColor,primaryTextColor:q.propValues.primaryTextColor,secondaryTextColor:q.propValues.secondaryTextColor,primaryBgColor:q.propValues.primaryBgColor,secondaryBgColor:q.propValues.secondaryBgColor,borderColor:q.propValues.borderColor,cardBgColor:q.propValues.cardBgColor,errorColor:q.propValues.errorColor,errorLightColor:q.propValues.errorLightColor,warningColor:q.propValues.warningColor,warningLightColor:q.propValues.warningLightColor,successColor:q.propValues.successColor,successLightColor:q.propValues.successLightColor},A.customizationProps=M,A.returnPolicy=I.returnPolicy,A.privacyPolicy=I.privacyPolicy,A.termsOfService=I.termsOfService,A.checkoutSettingsStr=(null==z?void 0:z.length)?JSON.stringify(z[0]):null,t.label=6;case 6:return s?[2,{props:o(o({},E.nextPageData.props),A)}]:[2,{props:o(o({},E.nextPageData.props),A),revalidate:60}];case 7:return[2,{props:{}}];case 8:return[2]}}))}))},v.getStaticProps=function(o,r,i,n){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,v.getPageData(o,!1,r,i,n)];case 1:return[2,e.sent()]}}))}))},v.getServerSideProps=function(o,r){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,v.getPageData(o,!0,r)];case 1:return[2,e.sent()]}}))}))},v.createColorScript=function(e){if(e.colors)return"<script>".concat(e.colors.map((function(e){return'document.documentElement.style.setProperty("'.concat(e.key,'","').concat(e.color,'");')})).join("\r\n"),"<\/script> \n ")},v.createFontScript=function(e){var t=x(e.fontFamily);if(t)return'<link id="ikas-font" rel="stylesheet" href="'.concat(t,"\"> \n <style>\n body { \n font-family: '").concat(e.fontFamily.name,'\', -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;\n } \n </style>')},v}();export{v as IkasNextPageDataProvider};
1
+ import{__awaiter as e,__generator as t,__assign as o,__spreadArray as r}from'../ext/tslib/tslib.es6.js';import i from"fs";import n from"next/config.js";import"../models/data/blog/index.js";import"../models/data/brand/index.js";import"../models/data/category/index.js";import"../models/data/checkout/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/index.js";import"../models/data/customer-review/index.js";import"mobx";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/installment-info/index.js";import"../models/data/order/index.js";import"../models/data/order/line-item/index.js";import"../api/product-option-file/index.js";import"../models/data/product/index.js";import"../models/data/variant-type/index.js";import"../models/data/product/variant/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product-attribute/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product-filter/index.js";import"../models/data/variant-type/variant-value/index.js";import"../models/data/order-transaction/index.js";import"../models/data/product-option-set/index.js";import"../models/data/raffle/index.js";import"../models/data/product-campaing/campaign/index.js";import"../models/data/customer-attribute/index.js";import"../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import{IkasTheme as s}from"../models/theme/theme.js";import{IkasThemePageType as a}from"../models/theme/page/index.js";import"../models/theme/component/prop/index.js";import"../models/theme/page/component/prop-value/link.js";import"../models/ui/brand-list/index.js";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-detail/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/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/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import"../models/theme/settings/index.js";import"../models/theme/custom-data/index.js";import{IkasStorefront as d}from"../models/data/storefront/index.js";import{IkasSalesChannel as l}from"../models/data/sales-channel/index.js";import{IkasStorefrontRouting as m}from"../models/data/storefront/routing/index.js";import{IkasStorefrontConfig as c}from"../storefront/index.js";import{IkasPageDataProvider as p}from"./page-data-get.js";import{IkasStorefrontThemeLocalization as u}from"../models/data/storefront/theme-localization/index.js";import{IkasStorefrontAPI as f}from"../api/storefront/index.js";import{I18NFileReader as g}from"../utils/i18n.js";import"../api/blog/index.js";import"../api/brand/index.js";import"../api/cart/index.js";import"../api/category/index.js";import{IkasCheckoutAPI as j}from"../api/checkout/index.js";import"../api/city/index.js";import"../api/country/index.js";import"../api/customer/index.js";import"../api/customer-review/index.js";import"../api/customer-review-summary/index.js";import"../api/district/index.js";import"../api/html-meta-data/index.js";import"../api/merchant/index.js";import"../api/product-search/index.js";import"../api/apollo.js";import"../api/favorite-product/index.js";import"../api/contact-form/index.js";import"../api/state/index.js";import"../api/product-option-set/index.js";import"../api/raffle/index.js";import"../api/back-in-stock-reminder/index.js";import"../api/product-campaign/index.js";import{getGoogleFontHref as x}from"../utils/google-fonts.js";var v=function(){function v(){}return v.readLocalTheme=function(){return new Promise((function(e,t){i.readFile("./src/theme.json",{flag:"a+"},(function(o,r){if(o)return t(o);var i=r.length?JSON.parse(r.toString()):{};e(new s(i))}))}))},v.readSettingsFile=function(){return new Promise((function(e){var t=n().serverRuntimeConfig.SETTINGS;i.readFile(t,{flag:"a+"},(function(t,o){if(t)return console.error("SETTINGS FILE READ ERROR!!!"),console.error(t),e(null);var r=o.length?JSON.parse(o.toString()):{};e(r)}))}))},v.getSettings=function(o){var r=this;return new Promise((function(n){return e(r,void 0,void 0,(function(){var e,r,s,a,p,g,j,x,h,S,C,y,I,b,w,k;return t(this,(function(t){switch(t.label){case 0:return"local"===process.env.NEXT_PUBLIC_ENV?c.storefrontId?[4,f.getStorefront(c.storefrontId)]:(console.error("Missing storefrontId in the config.json file!"),[2,n(null)]):[3,3];case 1:return(e=t.sent())?(r=e,[4,v.readLocalTheme()]):[2,n(null)];case 2:return s=t.sent(),a=v.createColorScript(s.settings),p=v.createFontScript(s.settings),g=[],a&&g.push(a),p&&g.push(p),n({storefront:r,themeLocalization:new u({themeJson:s}),salesChannel:new l({id:r.salesChannelId}),routing:r.routings.length?r.routings.find((function(e){return e.locale===o||e.id===o}))||r.routings[0]:new m({}),favicon:s.settings.favicon,stockPreference:s.settings.stockPreference,storefrontJSScripts:g,domain:"",productBackInStockSettings:{customerLoginRequired:!0},customerReviewSettings:{customerLoginRequired:!0,customerPurchaseRequired:!1}}),[3,5];case 3:return[4,v.readSettingsFile()];case 4:if(!(j=t.sent())||!j.localizationMap)return[2,n(null)];if(x=new d(j.storefront),h=new l(j.salesChannel),S=j.localizationMap,C=j.storefrontJSScripts||[],y=j.domain,I=j.productBackInStockSettings?{customerLoginRequired:j.productBackInStockSettings.customerLoginRequired}:null,b=j.customerReviewSettings?{customerLoginRequired:j.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:j.customerReviewSettings.customerPurchaseRequired||!1}:null,w=S[o],k=x.routings.find((function(e){return e.id===o||e.path===o})),!w||!k)return console.error("THEME LOCALIZATION PATH OR ROUTING MISSING!!!"),[2,n(null)];i.readFile(w,{flag:"a+"},(function(e,t){if(e)return console.error("THEME LOCALZIATION FILE READ ERROR!!!"),console.error(e),n(null);var o=t.length?JSON.parse(t.toString()):{},r=new u(o),i=r.themeJson.settings.favicon,s=r.themeJson.settings.stockPreference;if(r.themeJson.settings){var a=v.createColorScript(r.themeJson.settings),d=v.createFontScript(r.themeJson.settings);a&&C.push(a),d&&C.push(d)}n({storefront:x,themeLocalization:r,salesChannel:h,routing:k,favicon:i,stockPreference:s,storefrontJSScripts:C,domain:y,productBackInStockSettings:I,customerReviewSettings:b})})),t.label=5;case 5:return[2]}}))}))}))},v.getPageData=function(i,s,d,l,m){var u,f,x;return e(this,void 0,void 0,(function(){var e,h,S,C,y,I,b,w,k,P,R,T,L,B,E,V,J,F,O,N,D,A,q,z,M,G;return t(this,(function(t){switch(t.label){case 0:return e="local"===process.env.NEXT_PUBLIC_ENV,h=!e&&m,S=n().serverRuntimeConfig,h?[3,7]:(C=i.locale)?[4,v.getSettings(C)]:[2,{props:{},notFound:!0}];case 1:return(y=t.sent())&&y.storefront.mainStorefrontThemeId&&y.storefront.salesChannelId?(I=y.storefront,b=y.themeLocalization,w=y.salesChannel,k=y.routing,P=y.favicon,R=y.stockPreference,T=y.storefrontJSScripts,L=y.domain,B=y.productBackInStockSettings,E=y.customerReviewSettings,c.storefrontId=I.id,c.storefrontRoutingId=k.id,c.storefrontThemeId=I.mainStorefrontThemeId,c.salesChannelId=I.salesChannelId,c.priceListId=k.priceListId||void 0,c.stockLocationIds=null===(u=w.stockLocations)||void 0===u?void 0:u.map((function(e){return e.id})),c.routings=I.routings,c.paymentGateways=w.paymentGateways||[],c.gtmId=I.gtmId||void 0,c.fbpId=I.fbpId||void 0,c.analytics4Id=I.analytics4Id||void 0,c.universalAnalyticsId=I.universalAnalyticsId||void 0,c.favicon=P||null,c.stockPreference=R||null,c.storefrontJSScripts=T||[],c.domain=L,c.productBackInStockSettings=B,c.customerReviewSettings=E,(V=new p(b.themeJson,i.params,d)).possiblePageTypes=l||(d?[d]:[]),m?[3,3]:[4,V.getPageData()]):[2,{props:{},notFound:!0}];case 2:if(t.sent(),!V.page)return[2,{props:{},notFound:!0}];t.label=3;case 3:return J=m?V.theme.components.map((function(e){return e.id})):V.page.components.map((function(e){return e.componentId})),F=b.themeJson.components.filter((function(e){return m||J.includes(e.id)})),O=r(["common"],F.map((function(e){return e.dir})),!0),(d===a.CHECKOUT||m)&&O.push("checkout-page"),N=S.nextI18nConf,D=k.locale,[4,new g(D,O,e?void 0:N.localePath).read()];case 4:return A=t.sent(),c.translations=A,q={},d!==a.CHECKOUT?[3,6]:(z=null===(f=V.page)||void 0===f?void 0:f.components[0])?[4,j.listCheckoutSettings()]:[3,6];case 5:M=t.sent(),G={showTax:null===(x=z.propValues.showTax)||void 0===x||x,buttonBgColor:z.propValues.buttonBgColor,buttonTextColor:z.propValues.buttonTextColor,buttonDisabledBgColor:z.propValues.buttonDisabledBgColor,buttonDisabledTextColor:z.propValues.buttonDisabledTextColor,primaryTextColor:z.propValues.primaryTextColor,secondaryTextColor:z.propValues.secondaryTextColor,primaryBgColor:z.propValues.primaryBgColor,secondaryBgColor:z.propValues.secondaryBgColor,borderColor:z.propValues.borderColor,cardBgColor:z.propValues.cardBgColor,errorColor:z.propValues.errorColor,errorLightColor:z.propValues.errorLightColor,warningColor:z.propValues.warningColor,warningLightColor:z.propValues.warningLightColor,successColor:z.propValues.successColor,successLightColor:z.propValues.successLightColor},q.customizationProps=G,q.returnPolicy=b.returnPolicy,q.privacyPolicy=b.privacyPolicy,q.termsOfService=b.termsOfService,q.checkoutSettingsStr=(null==M?void 0:M.length)?JSON.stringify(M[0]):null,t.label=6;case 6:return s?[2,{props:o(o({},V.nextPageData.props),q)}]:[2,{props:o(o({},V.nextPageData.props),q),revalidate:60}];case 7:return[2,{props:{}}];case 8:return[2]}}))}))},v.getStaticProps=function(o,r,i,n){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,v.getPageData(o,!1,r,i,n)];case 1:return[2,e.sent()]}}))}))},v.getServerSideProps=function(o,r){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,v.getPageData(o,!0,r)];case 1:return[2,e.sent()]}}))}))},v.createColorScript=function(e){if(e.colors)return"<script>".concat(e.colors.map((function(e){return'document.documentElement.style.setProperty("'.concat(e.key,'","').concat(e.color,'");')})).join("\r\n"),"<\/script> \n ")},v.createFontScript=function(e){var t=x(e.fontFamily);if(t)return'<link id="ikas-font" rel="stylesheet" href="'.concat(t,"\"> \n <style>\n body { \n font-family: '").concat(e.fontFamily.name,'\', -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;\n } \n </style>')},v}();export{v as IkasNextPageDataProvider};
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as r}from'../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import{apollo as o}from"../api/apollo.js";import"../models/data/blog/index.js";import"../models/data/brand/index.js";import"../models/data/category/index.js";import"../models/data/checkout/index.js";import"../models/data/customer/address/index.js";import{IkasCustomer as s,IkasCustomerEmailSubscriptionStatus as n}from"../models/data/customer/index.js";import"../models/data/customer-review/index.js";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/installment-info/index.js";import"../models/data/order/index.js";import"../models/data/order/line-item/index.js";import"../api/product-option-file/index.js";import"../models/data/product/index.js";import"../models/data/variant-type/index.js";import"../models/data/product/variant/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product-attribute/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product-filter/index.js";import"../models/data/variant-type/variant-value/index.js";import"../models/data/order-transaction/index.js";import"../models/data/product-option-set/index.js";import"../models/data/raffle/index.js";import"../models/data/product-campaing/campaign/index.js";import"../models/data/customer-attribute/index.js";import"../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import"../models/theme/theme.js";import"../models/theme/page/index.js";import"../models/theme/component/prop/index.js";import"../models/theme/page/component/prop-value/link.js";import"../models/ui/brand-list/index.js";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-detail/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/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/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import"../models/theme/settings/index.js";import"../models/theme/custom-data/index.js";import"../api/blog/index.js";import"../api/brand/index.js";import"../api/cart/index.js";import"../api/category/index.js";import"../api/checkout/index.js";import"../api/city/index.js";import"../api/country/index.js";import{IkasCustomerAPI as a}from"../api/customer/index.js";import{IkasCustomerReviewAPI as u}from"../api/customer-review/index.js";import"../api/customer-review-summary/index.js";import"../api/district/index.js";import"../api/html-meta-data/index.js";import"../api/merchant/index.js";import{IkasProductSearchAPI as c}from"../api/product-search/index.js";import{IkasFavoriteProductAPI as d}from"../api/favorite-product/index.js";import{IkasContactFormAPI as l}from"../api/contact-form/index.js";import"../api/state/index.js";import"../api/product-option-set/index.js";import{IkasRaffleAPI as m}from"../api/raffle/index.js";import"../api/back-in-stock-reminder/index.js";import"../api/product-campaign/index.js";import{Analytics as p}from"../analytics/analytics.js";import"../analytics/head/index.js";import{IkasStorefrontConfig as h}from"../storefront/index.js";import{populateRaffleProducts as f}from"../providers/helpers/raffles.js";import v from'../ext/lodash/uniqBy.js';import{IkasCustomerAttributeAPI as w}from"../api/customer-attribute/index.js";var g="undefined"==typeof localStorage,b=function(){function b(o){var s=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.login=function(r,i){return t(s,void 0,void 0,(function(){var t,o,s;return e(this,(function(e){switch(e.label){case 0:return[4,a.login(r,i)];case 1:return(t=e.sent())?(this.setToken(t.token,t.tokenExpiry),this.setCustomer(t.customer),this.customer&&p.customerLogin(),(o=null===(s=this.baseStore)||void 0===s?void 0:s.cartStore.cart)?[4,this.baseStore.cartStore.changeItemQuantity(o.items[0],o.items[0].quantity)]:[3,3]):[3,4];case 2:e.sent(),e.label=3;case 3:return this.saveLocalLastViewedProducts(),[2,!0];case 4:return[2,!1]}}))}))},this.register=function(r,i,o,n,u,c){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,a.register(o,n,r,i,u,c)];case 1:return(t=e.sent())?(this.setToken(t.token,t.tokenExpiry),this.setCustomer(t.customer),this.saveLocalLastViewedProducts(),[2,!0]):[2,!1]}}))}))},this.saveContactForm=function(r){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return p.contactForm(r),[4,l.sendContactFormToMerchant(r)];case 1:return[2,t.sent()]}}))}))},this.checkEmail=function(r){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.checkEmail(r)];case 1:return[2,t.sent()]}}))}))},this.forgotPassword=function(r){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.forgotPassword(r)];case 1:return[2,t.sent()]}}))}))},this.recoverPassword=function(r,i,o){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.recoverPassword(r,i,o)];case 1:return[2,t.sent()]}}))}))},this.logout=function(){var t;s.clearLocalData(),null===(t=s.baseStore)||void 0===t||t.cartStore.removeCart(),p.customerLogout()},this.saveCustomer=function(r){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,a.saveCustomer(r)];case 1:return(t=e.sent())?(this.setCustomer(t),[2,!0]):[2,!1]}}))}))},this.getOrders=function(){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.getOrders()];case 1:return[2,t.sent()]}}))}))},this.getOrder=function(r){return t(s,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,a.getOrders(r)];case 1:return t=e.sent(),Array.isArray(t)&&t.length?((i=t[0])._refundSettings=this._refundSettings,[2,i]):[2,null]}}))}))},this.getOrderTransactions=function(r){return void 0===r&&(r={}),t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.getOrderTransactions(r)];case 1:return[2,t.sent()]}}))}))},this.getFavoriteProductsIds=function(){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,d.listFavoriteProducts()];case 1:return[2,t.sent()];case 2:return t.sent(),[2,[]];case 3:return[2]}}))}))},this.getFavoriteProducts=function(){return t(s,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,d.listFavoriteProducts()];case 1:return(t=e.sent()).length?[4,c.searchProducts({productIdList:t.map((function(t){return t.productId})),priceListId:h.priceListId,salesChannelId:h.salesChannelId})]:[2,[]];case 2:return[2,(null==(r=e.sent())?void 0:r.data)||[]];case 3:return e.sent(),[2,[]];case 4:return[2]}}))}))},this.getOrderRefundSettings=function(){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this._refundSettings?[3,2]:(t=this,[4,a.getOrderRefundSettings()]);case 1:t._refundSettings=e.sent(),e.label=2;case 2:return[2]}}))}))},this.addItemToFavorite=function(r){return t(s,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.customer)||void 0===i?void 0:i.id))throw Error("Unauthorized");e.label=1;case 1:return e.trys.push([1,3,,4]),[4,d.saveFavoriteProduct(!0,r)];case 2:return t=e.sent(),p.addToWishlist(r),[2,t];case 3:return e.sent(),[2,!1];case 4:return[2]}}))}))},this.removeItemFromFavorite=function(r){return t(s,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");e.label=1;case 1:return e.trys.push([1,3,,4]),[4,d.saveFavoriteProduct(!1,r)];case 2:return[2,e.sent()];case 3:return e.sent(),[2,!1];case 4:return[2]}}))}))},this.isProductFavorite=function(r){return t(s,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,d.isFavoriteProduct(r)];case 1:return[2,e.sent()]}}))}))},this.createEmailSubscription=function(r){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,a.createCustomerEmailSubscription(r)];case 1:return(t=e.sent())&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,n.SUBSCRIBED):this._visitorSubscribedEmail=!0),[2,t]}}))}))},this.sendReview=function(i){return t(s,void 0,void 0,(function(){var t,o,s,n,a;return e(this,(function(e){switch(e.label){case 0:if(e.trys.push([0,2,,3]),t=h.customerReviewSettings,o=h.salesChannelId,!t)return[2];if(!(s=null===(a=this.customer)||void 0===a?void 0:a.id)&&t.customerLoginRequired)throw Error("Unauthorized");return[4,u.createCustomerReview(r(r({},i),{customerId:t.customerLoginRequired?s:void 0,salesChannelId:o||""}))];case 1:return[2,e.sent()];case 2:return n=e.sent(),console.log(n),[3,3];case 3:return[2]}}))}))},this.onCustomerConsentGrant=function(){s.saveCustomerConsent()},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){s.initialized&&(clearInterval(e),t(null))}),100)}))},this.getRaffles=function(){return t(s,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,m.getRafflesByCustomerId()];case 1:return t=e.sent(),[4,m.getRafflesByCustomerId(!0)];case 2:return r=e.sent(),null==t||t.forEach((function(t){(null==r?void 0:r.find((function(e){return e.id===t.id})))&&(t.isCustomerWinner=!0)})),t?[4,f(t)]:[3,4];case 3:e.sent(),e.label=4;case 4:return[2,t]}}))}))},this.getCustomerAttributes=function(){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,w.listCustomerAttributes()];case 1:return t=e.sent(),this.customer&&this.customer.attributes.forEach((function(e){var r,i;e.customerAttribute=t.find((function(t){return t.id===e.customerAttributeId})),e.customerAttributeOptionId&&(e.customerAttributeOption=null===(i=null===(r=e.customerAttribute)||void 0===r?void 0:r.options)||void 0===i?void 0:i.find((function(t){return t.id===e.customerAttributeOptionId})))})),[2,t]}}))}))},this.getOrderByEmail=function(r,i){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.getOrderByEmail(r,i)];case 1:return[2,t.sent()]}}))}))},this.baseStore=o,this.init(),i(this)}return Object.defineProperty(b.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(b.prototype,"canCreateEmailSubscription",{get:function(){var t;return!((null===(t=this.customer)||void 0===t?void 0:t.isSubscribed)||g||this._visitorSubscribedEmail)&&!window.localStorage.getItem("customerEmailSubscription")},enumerable:!1,configurable:!0}),Object.defineProperty(b.prototype,"customerConsentGranted",{get:function(){return this._customerConsentGranted},enumerable:!1,configurable:!0}),b.prototype.socialLogin=function(r){return t(this,void 0,void 0,(function(){var t,i,o;return e(this,(function(e){switch(e.label){case 0:return"undefined"==typeof window?[2]:(t=new URLSearchParams(window.location.search).get("redirect")||"",i="".concat(process.env.NEXT_PUBLIC_BASE_URL,"/ms/").concat(r,"/login/authenticate?redirect=").concat(t),[4,fetch(i,{headers:{"x-api-key":h.config.apiKey||"","x-sfid":h.storefrontId||"","x-sfrid":h.storefrontRoutingId||""}})]);case 1:return[4,e.sent().json()];case 2:return o=e.sent(),h.router?h.router.replace(o.redirectUrl):window.location.href=o.redirectUrl,[2]}}))}))},b.prototype.socialLoginToken=function(r){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,a.socialLogin(r)];case 1:return(null==(t=e.sent())?void 0:t.customer)?(this.setToken(t.token,t.tokenExpiry),this.setCustomer(t.customer),this.customer&&p.customerLogin(),[2,!0]):[2,!1]}}))}))},b.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(),[4,this.getOrderRefundSettings()];case 3:return t.sent(),this._initialized=!0,this.customer&&p.customerVisit(),[2]}}))}))},b.prototype.routeChangeInit=function(){this.customer||(this.loadToken(),this.getCustomer())},b.prototype.getCustomer=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return g||!this.token?[2]:[4,a.getCustomer()];case 1:return(t=e.sent())&&this.setCustomer(t),[2]}}))}))},b.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,a.refreshToken(this.token)]:[2];case 1:return(null==(t=e.sent())?void 0:t.token)||(null==t?void 0:t.tokenExpiry)?this.setToken(t.token,t.tokenExpiry):(this.token=null,this.tokenExpiry=null,this.clearLocalData()),[2]}}))}))},b.prototype.setCustomer=function(t){this.customer=new s(t)},b.prototype.getLastViewedProducts=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.customer?(t=this,[4,a.getLastViewedProducts(this.customer.id)]):[3,2];case 1:return t._lastViewedProducts=e.sent(),[3,3];case 2:this.loadLastViewedProducts(),e.label=3;case 3:return[2,this._lastViewedProducts]}}))}))},b.prototype.saveLastViewedProducts=function(){g||window.localStorage.setItem("lastViewedProducts",JSON.stringify(this._lastViewedProducts))},b.prototype.loadLastViewedProducts=function(){if(!g)try{var t=window.localStorage.getItem("lastViewedProducts");t&&(this._lastViewedProducts=JSON.parse(t),this._lastViewedProducts=this._lastViewedProducts.reverse(),this._lastViewedProducts=v(this._lastViewedProducts,"variantId"))}catch(t){}},b.prototype.removeLastViewedProducts=function(){g||window.localStorage.removeItem("lastViewedProducts")},b.prototype.onProductView=function(r,i){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===r}))?[2]:[4,a.saveLastViewedProducts({customerId:this.customer.id,products:[{productId:r,variantId:i}]})]:[3,2];case 1:return t.sent()&&this._lastViewedProducts.push({productId:r,variantId:i}),[3,3];case 2:this._lastViewedProducts.push({productId:r,variantId:i}),this._lastViewedProducts=this._lastViewedProducts.slice(0,20),this._lastViewedProducts=v(this._lastViewedProducts,"variantId"),this.saveLastViewedProducts(),t.label=3;case 3:return[2]}}))}))},b.prototype.saveLocalLastViewedProducts=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:if(g)return[2];t.label=1;case 1:return t.trys.push([1,4,,5]),this.loadLastViewedProducts(),this._lastViewedProducts.length?[4,a.saveLastViewedProducts({customerId:this.customer.id,products:this._lastViewedProducts})]:[3,3];case 2:t.sent()&&this.removeLastViewedProducts(),t.label=3;case 3:return[3,5];case 4:return t.sent(),[3,5];case 5:return[2]}}))}))},b.prototype.saveCustomerConsent=function(){g||(this._customerConsentGranted=!0,window.localStorage.setItem("customerConsent","true"))},b.prototype.loadCustomerConsent=function(){g||(this._customerConsentGranted=!!window.localStorage.getItem("customerConsent"))},b.prototype.removeCustomerConsent=function(){g||window.localStorage.removeItem("customerConsent")},b.prototype.setToken=function(t,e){g||(this.token=t,this.tokenExpiry=e,localStorage.setItem("customerToken",t),localStorage.setItem("customerTokenExpiry",e+""),o.setCustomerToken(t))},b.prototype.loadToken=function(){if(!g){var t=localStorage.getItem("customerToken"),e=localStorage.getItem("customerTokenExpiry");t&&e&&this.setToken(t,parseInt(e))}},b.prototype.clearLocalTokenData=function(){localStorage.removeItem("customerToken"),localStorage.removeItem("customerTokenExpiry"),this.token=void 0,this.tokenExpiry=void 0},b.prototype.clearLocalData=function(){this.clearLocalTokenData(),this.customer=void 0,o.setCustomerToken()},b}();export{b as IkasCustomerStore};
1
+ import{__awaiter as t,__generator as e,__assign as r}from'../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import{apollo as o}from"../api/apollo.js";import"../models/data/blog/index.js";import"../models/data/brand/index.js";import"../models/data/category/index.js";import"../models/data/checkout/index.js";import"../models/data/customer/address/index.js";import{IkasCustomer as s,IkasCustomerEmailSubscriptionStatus as n}from"../models/data/customer/index.js";import"../models/data/customer-review/index.js";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/installment-info/index.js";import"../models/data/order/index.js";import"../models/data/order/line-item/index.js";import"../api/product-option-file/index.js";import"../models/data/product/index.js";import"../models/data/variant-type/index.js";import"../models/data/product/variant/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product-attribute/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product-filter/index.js";import"../models/data/variant-type/variant-value/index.js";import"../models/data/order-transaction/index.js";import"../models/data/product-option-set/index.js";import"../models/data/raffle/index.js";import"../models/data/product-campaing/campaign/index.js";import"../models/data/customer-attribute/index.js";import"../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import"../models/theme/theme.js";import"../models/theme/page/index.js";import"../models/theme/component/prop/index.js";import"../models/theme/page/component/prop-value/link.js";import"../models/ui/brand-list/index.js";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-detail/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/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/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import"../models/theme/settings/index.js";import"../models/theme/custom-data/index.js";import"../api/blog/index.js";import"../api/brand/index.js";import"../api/cart/index.js";import"../api/category/index.js";import"../api/checkout/index.js";import"../api/city/index.js";import"../api/country/index.js";import{IkasCustomerAPI as a}from"../api/customer/index.js";import{IkasCustomerReviewAPI as u}from"../api/customer-review/index.js";import"../api/customer-review-summary/index.js";import"../api/district/index.js";import"../api/html-meta-data/index.js";import"../api/merchant/index.js";import{IkasProductSearchAPI as c}from"../api/product-search/index.js";import{IkasFavoriteProductAPI as d}from"../api/favorite-product/index.js";import{IkasContactFormAPI as l}from"../api/contact-form/index.js";import"../api/state/index.js";import"../api/product-option-set/index.js";import{IkasRaffleAPI as m}from"../api/raffle/index.js";import"../api/back-in-stock-reminder/index.js";import"../api/product-campaign/index.js";import{Analytics as p}from"../analytics/analytics.js";import"../analytics/head/index.js";import{IkasStorefrontConfig as h}from"../storefront/index.js";import{populateRaffleProducts as f}from"../providers/helpers/raffles.js";import v from'../ext/lodash/uniqBy.js';import{IkasCustomerAttributeAPI as w}from"../api/customer-attribute/index.js";var g="undefined"==typeof localStorage,b=function(){function b(o){var s=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.login=function(r,i){return t(s,void 0,void 0,(function(){var t,o,s;return e(this,(function(e){switch(e.label){case 0:return[4,a.login(r,i)];case 1:return(t=e.sent())?(this.setToken(t.token,t.tokenExpiry),this.setCustomer(t.customer),this.customer&&p.customerLogin(),(o=null===(s=this.baseStore)||void 0===s?void 0:s.cartStore.cart)?[4,this.baseStore.cartStore.changeItemQuantity(o.items[0],o.items[0].quantity)]:[3,3]):[3,4];case 2:e.sent(),e.label=3;case 3:return this.saveLocalLastViewedProducts(),[2,!0];case 4:return[2,!1]}}))}))},this.register=function(r,i,o,n,u,c){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,a.register(o,n,r,i,u,c)];case 1:return(t=e.sent())?(this.setToken(t.token,t.tokenExpiry),this.setCustomer(t.customer),this.saveLocalLastViewedProducts(),[2,!0]):[2,!1]}}))}))},this.saveContactForm=function(r){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return p.contactForm(r),[4,l.sendContactFormToMerchant(r)];case 1:return[2,t.sent()]}}))}))},this.checkEmail=function(r){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.checkEmail(r)];case 1:return[2,t.sent()]}}))}))},this.forgotPassword=function(r){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.forgotPassword(r)];case 1:return[2,t.sent()]}}))}))},this.recoverPassword=function(r,i,o){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.recoverPassword(r,i,o)];case 1:return[2,t.sent()]}}))}))},this.logout=function(){var t;s.clearLocalData(),null===(t=s.baseStore)||void 0===t||t.cartStore.removeCart(),p.customerLogout()},this.saveCustomer=function(r){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,a.saveCustomer(r)];case 1:return(t=e.sent())?(this.setCustomer(t),[2,!0]):[2,!1]}}))}))},this.getOrders=function(){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.getOrders()];case 1:return[2,t.sent()]}}))}))},this.getOrder=function(r){return t(s,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,a.getOrders(r)];case 1:return t=e.sent(),Array.isArray(t)&&t.length?((i=t[0])._refundSettings=this._refundSettings,[2,i]):[2,null]}}))}))},this.getOrderTransactions=function(r){return void 0===r&&(r={}),t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.getOrderTransactions(r)];case 1:return[2,t.sent()]}}))}))},this.getFavoriteProductsIds=function(){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,d.listFavoriteProducts()];case 1:return[2,t.sent()];case 2:return t.sent(),[2,[]];case 3:return[2]}}))}))},this.getFavoriteProducts=function(){return t(s,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,d.listFavoriteProducts()];case 1:return(t=e.sent()).length?[4,c.searchProducts({productIdList:t.map((function(t){return t.productId})),priceListId:h.priceListId,salesChannelId:h.salesChannelId})]:[2,[]];case 2:return[2,(null==(r=e.sent())?void 0:r.data)||[]];case 3:return e.sent(),[2,[]];case 4:return[2]}}))}))},this.getOrderRefundSettings=function(){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this._refundSettings?[3,2]:(t=this,[4,a.getOrderRefundSettings()]);case 1:t._refundSettings=e.sent(),e.label=2;case 2:return[2]}}))}))},this.addItemToFavorite=function(r){return t(s,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.customer)||void 0===i?void 0:i.id))throw Error("Unauthorized");e.label=1;case 1:return e.trys.push([1,3,,4]),[4,d.saveFavoriteProduct(!0,r)];case 2:return t=e.sent(),p.addToWishlist(r),[2,t];case 3:return e.sent(),[2,!1];case 4:return[2]}}))}))},this.removeItemFromFavorite=function(r){return t(s,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");e.label=1;case 1:return e.trys.push([1,3,,4]),[4,d.saveFavoriteProduct(!1,r)];case 2:return[2,e.sent()];case 3:return e.sent(),[2,!1];case 4:return[2]}}))}))},this.isProductFavorite=function(r){return t(s,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,d.isFavoriteProduct(r)];case 1:return[2,e.sent()]}}))}))},this.createEmailSubscription=function(r){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,a.createCustomerEmailSubscription(r)];case 1:return(t=e.sent())&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,n.SUBSCRIBED):this._visitorSubscribedEmail=!0,p.createEmailSubscripition(r)),[2,t]}}))}))},this.sendReview=function(i){return t(s,void 0,void 0,(function(){var t,o,s,n,a;return e(this,(function(e){switch(e.label){case 0:if(e.trys.push([0,2,,3]),t=h.customerReviewSettings,o=h.salesChannelId,!t)return[2];if(!(s=null===(a=this.customer)||void 0===a?void 0:a.id)&&t.customerLoginRequired)throw Error("Unauthorized");return[4,u.createCustomerReview(r(r({},i),{customerId:t.customerLoginRequired?s:void 0,salesChannelId:o||""}))];case 1:return[2,e.sent()];case 2:return n=e.sent(),console.log(n),[3,3];case 3:return[2]}}))}))},this.onCustomerConsentGrant=function(){s.saveCustomerConsent()},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){s.initialized&&(clearInterval(e),t(null))}),100)}))},this.getRaffles=function(){return t(s,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,m.getRafflesByCustomerId()];case 1:return t=e.sent(),[4,m.getRafflesByCustomerId(!0)];case 2:return r=e.sent(),null==t||t.forEach((function(t){(null==r?void 0:r.find((function(e){return e.id===t.id})))&&(t.isCustomerWinner=!0)})),t?[4,f(t)]:[3,4];case 3:e.sent(),e.label=4;case 4:return[2,t]}}))}))},this.getCustomerAttributes=function(){return t(s,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,w.listCustomerAttributes()];case 1:return t=e.sent(),this.customer&&this.customer.attributes.forEach((function(e){var r,i;e.customerAttribute=t.find((function(t){return t.id===e.customerAttributeId})),e.customerAttributeOptionId&&(e.customerAttributeOption=null===(i=null===(r=e.customerAttribute)||void 0===r?void 0:r.options)||void 0===i?void 0:i.find((function(t){return t.id===e.customerAttributeOptionId})))})),[2,t]}}))}))},this.getOrderByEmail=function(r,i){return t(s,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,a.getOrderByEmail(r,i)];case 1:return[2,t.sent()]}}))}))},this.baseStore=o,this.init(),i(this)}return Object.defineProperty(b.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(b.prototype,"canCreateEmailSubscription",{get:function(){var t;return!((null===(t=this.customer)||void 0===t?void 0:t.isSubscribed)||g||this._visitorSubscribedEmail)&&!window.localStorage.getItem("customerEmailSubscription")},enumerable:!1,configurable:!0}),Object.defineProperty(b.prototype,"customerConsentGranted",{get:function(){return this._customerConsentGranted},enumerable:!1,configurable:!0}),b.prototype.socialLogin=function(r){return t(this,void 0,void 0,(function(){var t,i,o;return e(this,(function(e){switch(e.label){case 0:return"undefined"==typeof window?[2]:(t=new URLSearchParams(window.location.search).get("redirect")||"",i="".concat(process.env.NEXT_PUBLIC_BASE_URL,"/ms/").concat(r,"/login/authenticate?redirect=").concat(t),[4,fetch(i,{headers:{"x-api-key":h.config.apiKey||"","x-sfid":h.storefrontId||"","x-sfrid":h.storefrontRoutingId||""}})]);case 1:return[4,e.sent().json()];case 2:return o=e.sent(),h.router?h.router.replace(o.redirectUrl):window.location.href=o.redirectUrl,[2]}}))}))},b.prototype.socialLoginToken=function(r){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,a.socialLogin(r)];case 1:return(null==(t=e.sent())?void 0:t.customer)?(this.setToken(t.token,t.tokenExpiry),this.setCustomer(t.customer),this.customer&&p.customerLogin(),[2,!0]):[2,!1]}}))}))},b.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(),[4,this.getOrderRefundSettings()];case 3:return t.sent(),this._initialized=!0,this.customer&&p.customerVisit(),[2]}}))}))},b.prototype.routeChangeInit=function(){this.customer||(this.loadToken(),this.getCustomer())},b.prototype.getCustomer=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return g||!this.token?[2]:[4,a.getCustomer()];case 1:return(t=e.sent())&&this.setCustomer(t),[2]}}))}))},b.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,a.refreshToken(this.token)]:[2];case 1:return(null==(t=e.sent())?void 0:t.token)||(null==t?void 0:t.tokenExpiry)?this.setToken(t.token,t.tokenExpiry):(this.token=null,this.tokenExpiry=null,this.clearLocalData()),[2]}}))}))},b.prototype.setCustomer=function(t){this.customer=new s(t)},b.prototype.getLastViewedProducts=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.customer?(t=this,[4,a.getLastViewedProducts(this.customer.id)]):[3,2];case 1:return t._lastViewedProducts=e.sent(),[3,3];case 2:this.loadLastViewedProducts(),e.label=3;case 3:return[2,this._lastViewedProducts]}}))}))},b.prototype.saveLastViewedProducts=function(){g||window.localStorage.setItem("lastViewedProducts",JSON.stringify(this._lastViewedProducts))},b.prototype.loadLastViewedProducts=function(){if(!g)try{var t=window.localStorage.getItem("lastViewedProducts");t&&(this._lastViewedProducts=JSON.parse(t),this._lastViewedProducts=this._lastViewedProducts.reverse(),this._lastViewedProducts=v(this._lastViewedProducts,"variantId"))}catch(t){}},b.prototype.removeLastViewedProducts=function(){g||window.localStorage.removeItem("lastViewedProducts")},b.prototype.onProductView=function(r,i){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===r}))?[2]:[4,a.saveLastViewedProducts({customerId:this.customer.id,products:[{productId:r,variantId:i}]})]:[3,2];case 1:return t.sent()&&this._lastViewedProducts.push({productId:r,variantId:i}),[3,3];case 2:this._lastViewedProducts.push({productId:r,variantId:i}),this._lastViewedProducts=this._lastViewedProducts.slice(0,20),this._lastViewedProducts=v(this._lastViewedProducts,"variantId"),this.saveLastViewedProducts(),t.label=3;case 3:return[2]}}))}))},b.prototype.saveLocalLastViewedProducts=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:if(g)return[2];t.label=1;case 1:return t.trys.push([1,4,,5]),this.loadLastViewedProducts(),this._lastViewedProducts.length?[4,a.saveLastViewedProducts({customerId:this.customer.id,products:this._lastViewedProducts})]:[3,3];case 2:t.sent()&&this.removeLastViewedProducts(),t.label=3;case 3:return[3,5];case 4:return t.sent(),[3,5];case 5:return[2]}}))}))},b.prototype.saveCustomerConsent=function(){g||(this._customerConsentGranted=!0,window.localStorage.setItem("customerConsent","true"))},b.prototype.loadCustomerConsent=function(){g||(this._customerConsentGranted=!!window.localStorage.getItem("customerConsent"))},b.prototype.removeCustomerConsent=function(){g||window.localStorage.removeItem("customerConsent")},b.prototype.setToken=function(t,e){g||(this.token=t,this.tokenExpiry=e,localStorage.setItem("customerToken",t),localStorage.setItem("customerTokenExpiry",e+""),o.setCustomerToken(t))},b.prototype.loadToken=function(){if(!g){var t=localStorage.getItem("customerToken"),e=localStorage.getItem("customerTokenExpiry");t&&e&&this.setToken(t,parseInt(e))}},b.prototype.clearLocalTokenData=function(){localStorage.removeItem("customerToken"),localStorage.removeItem("customerTokenExpiry"),this.token=void 0,this.tokenExpiry=void 0},b.prototype.clearLocalData=function(){this.clearLocalTokenData(),this.customer=void 0,o.setCustomerToken()},b}();export{b as IkasCustomerStore};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "2.0.42",
3
+ "version": "2.0.45",
4
4
  "main": "./build/index.js",
5
5
  "module": "./build/index.js",
6
6
  "author": "Umut Ozan Yıldırım",