@ikas/storefront 2.0.42 → 2.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/_virtual/index.js_commonjs-proxy2.js +1 -1
- package/build/_virtual/index.js_commonjs-proxy3.js +1 -1
- package/build/_virtual/index.js_commonjs-proxy4.js +1 -1
- package/build/analytics/analytics.d.ts +3 -2
- package/build/analytics/analytics.js +1 -1
- package/build/analytics/events.d.ts +2 -1
- package/build/analytics/events.js +1 -1
- package/build/ikas.js +2 -2
- package/build/models/ui/validator/form/register.js +1 -1
- package/build/store/customer.js +1 -1
- package/package.json +1 -1
|
@@ -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(){
|
|
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};
|
package/build/store/customer.js
CHANGED
|
@@ -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};
|