@ikas/storefront 4.4.0-beta.6 → 4.4.0-beta.8

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.
@@ -13,6 +13,7 @@ import { IkasVariantType } from "../variant-type";
13
13
  import { IkasProductAttributeMap } from "./attribute-value";
14
14
  import { IkasProductBaseUnit } from "./base-unit";
15
15
  import { IkasCustomerReviewList } from "../../ui/customer-review-list";
16
+ import { IkasProductStar } from "./star";
16
17
  export declare class IkasProduct implements IProduct {
17
18
  id: string;
18
19
  name: string;
@@ -30,6 +31,7 @@ export declare class IkasProduct implements IProduct {
30
31
  baseUnit: IkasProductBaseUnit | null;
31
32
  averageRating: number | null;
32
33
  reviewCount: number | null;
34
+ stars: IkasProductStar[] | null;
33
35
  groupVariantsByVariantTypeId: string | null;
34
36
  productOptionSet?: IkasProductOptionSet | null;
35
37
  campaigns?: IkasProductCampaign[] | null;
@@ -1 +1 @@
1
- import{__spreadArray as t,__awaiter as e,__generator as i}from'./../../../ext/tslib/tslib.es6.js';import n from"lodash/sortBy";import{IkasCategory as r}from"../category/index.js";import{IkasProductVariant as a}from"./variant/index.js";import{IkasProductAttributeValue as o}from"./attribute-value/index.js";import{IkasProductVariantType as s}from"./variant-type/index.js";import{IkasBrand as u}from"../brand/index.js";import{IkasHTMLMetaData as c}from"../html-meta-data/index.js";import{IkasProductTag as d}from"./tag/index.js";import{IkasProductType as l}from"@ikas/storefront-models";export{IkasProductType}from"@ikas/storefront-models";import{IkasProductOptionSet as p}from"./option-set/index.js";import{makeObservable as f,observable as m,computed as v}from"mobx";import{IkasProductFunctions as h}from"@ikas/storefront-model-functions";import{IkasProductCampaign as g}from"./campaign/index.js";import{IkasStorefrontConfig as b}from"@ikas/storefront-config";import{Analytics as y}from"../../../analytics/analytics.js";import"../../../analytics/head/index.js";import{IkasBaseStore as V}from"../../../store/base.js";import O from"lodash/groupBy";import{IkasProductBaseUnit as P}from"./base-unit/index.js";import{formatCurrency as j}from"../../../utils/currency.js";import"lodash/get";import S from"../../../store/product/index.js";import{IkasCustomerReviewList as I}from"../../ui/customer-review-list/index.js";var T=function(){function T(h){void 0===h&&(h={});var O,T,w,x=this;this.metaData=null,this.brand=null,this.tags=null,this.productOptionSetId=null,this.productOptionSet=null,this.campaigns=null,this.selectedVariantValues=[],this.isFiltered=!1,this.selectVariantValue=function(e,i){var n,r=x.metaData,a=x.selectedVariantValues.map((function(t){return t.variantTypeId===e.variantTypeId?e:t})),o=x.variants.find((function(t){return t.isActive&&a.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))}));if(o)x.selectedVariantValues=a;else{var s=x.variantTypes.findIndex((function(t){return t.variantType.id===e.variantTypeId}));if(s>0){var u=x.variantTypes.slice(0,s),c=x.selectedVariantValues.filter((function(t){return u.some((function(e){return e.variantType.id===t.variantTypeId}))})),d=t(t([],c,!0),[e],!1);o=x.variants.find((function(t){return t.isActive&&d.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))}))}else{var l=a.slice(0,a.length-1);(o=x.variants.find((function(t){return t.isActive&&l.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))})))||(o=x.variants.find((function(t){return t.isActive&&t.variantValues.some((function(t){return t.id===e.id}))})))}if(!o)return;x.selectedVariantValues=o.variantValues}var p=x.variantTypes.map((function(t){var e=t.variantType,i=e.values.find((function(t){return x.selectedVariantValues.some((function(e){return e.id===t.id}))}));if(i)return"".concat(e.slug,"=").concat(i.slug)})).filter((function(t){return!!t})).join("&");if(!i){var f="/".concat(r.slug);if(p&&(f="/".concat(r.slug,"?").concat(p)),f===window.location.pathname)return;var m="production"!==process.env.NODE_ENV;null===(n=V.getInstance().router)||void 0===n||n.replace(f,void 0,{shallow:m,scroll:!1})}y.productView(x)},this.getVariantUnitPriceText=function(t){var e,i,n=t.price;if(n.unitPrice&&x.baseUnit){var r=x.baseUnit.baseAmount,a=(null===(i=null===(e=x.baseUnit)||void 0===e?void 0:e.unit)||void 0===i?void 0:i.name)||"";return"".concat(j(n.unitPrice,n.currency||"",n.currencySymbol||"")," / ").concat(r&&1!==r?r:"").concat(a)}},this.getCampaigns=function(){return e(x,void 0,void 0,(function(){var t,e,n,r,a,o=this;return i(this,(function(i){switch(i.label){case 0:return t=V.getInstance(),e=t.customerStore.customer,n=e?e.customerGroupIds:null,r=this.variants.map((function(t){return t.id})),[4,S.getProductCampaigns({input:{customerGroupIds:n,salesChannelId:b.getSalesChannelId()||"",variantIds:r}})];case 1:return a=i.sent(),this.campaigns=a.data,this.campaigns?(this.campaigns.map((function(t){o.variants.map((function(e){var i;t.variantIds.some((function(t){return t===e.id}))&&(null===(i=e.campaigns)||void 0===i||i.push(t))}))})),[2,this.campaigns]):[2]}}))}))},this.getAvailableStockLocations=function(){return e(x,void 0,void 0,(function(){var t,e;return i(this,(function(i){switch(i.label){case 0:return t=this.variants.map((function(t){return t.id})),e=b.getPickupStockLocationIds(),[4,S.getVariantStockLocations({stockLocationIdList:e,variantIds:t})];case 1:return[2,i.sent().data||[]]}}))}))},this.getCustomerReviews=function(t){return e(x,void 0,void 0,(function(){var e;return i(this,(function(i){switch(i.label){case 0:return[4,(e=new I({productId:this.id,limit:null==t?void 0:t.limit,page:null==t?void 0:t.page})).getInitial()];case 1:return i.sent(),[2,e]}}))}))},this.getProductOptionSet=function(){return e(x,void 0,void 0,(function(){var t,e;return i(this,(function(i){switch(i.label){case 0:return this.productOptionSet?[2,!0]:this.productOptionSetId?[4,S.listProductOptionSet({id:{eq:this.productOptionSetId}})]:[2,!1];case 1:return(t=i.sent()).isSuccess&&(null===(e=t.data)||void 0===e?void 0:e.length)?(this.productOptionSet=t.data[0],this.setOptionPrices(),[2,!0]):[2,!1]}}))}))},this.setOptionPrices=function(){var t,e=x.variants[0];if(e){var i=e.price.currency;null===(t=x.productOptionSet)||void 0===t||t.options.forEach((function(t){var e;t.selectSettings&&t.selectSettings.values.forEach((function(t){var e;t.otherPrices&&(t.price=(null===(e=t.otherPrices.find((function(t){return t.currencyCode===i})))||void 0===e?void 0:e.price)||t.price)})),t.otherPrices&&(t.price=(null===(e=t.otherPrices.find((function(t){return t.currencyCode===i})))||void 0===e?void 0:e.price)||t.price)}))}},this.id=h.id||Date.now()+"",this.name=h.name||"",this.type=h.type||l.PHYSICAL,this.description=h.description||"",this.shortDescription=h.shortDescription||"",this.metaData=h.metaData?new c(h.metaData):null,this.brand=h.brand?new u(h.brand):null,this.categories=h.categories?h.categories.map((function(t){return new r(t)})):[],this.tags=h.tags?h.tags.map((function(t){return new d(t)})):[],this.variants=h.variants?h.variants.map((function(t){return new a(t)})):[],this.attributes=h.attributes?h.attributes.map((function(t){return new o(t)})):[],this.variantTypes=h.variantTypes?h.variantTypes.map((function(t){return new s(t)})):[],this.productOptionSetId=h.productOptionSetId||null,this.averageRating=null!==(O=h.averageRating)&&void 0!==O?O:null,this.reviewCount=null!==(T=h.reviewCount)&&void 0!==T?T:null,this.baseUnit=h.baseUnit?new P(h.baseUnit):null,this.productOptionSet=h.productOptionSet?new p(h.productOptionSet):null,this.campaigns=(null===(w=h.campaigns)||void 0===w?void 0:w.map((function(t){return new g(t)})))||null,this.selectedVariantValues=h.selectedVariantValues||[],this.variantTypes=n(this.variantTypes,"order"),this.groupVariantsByVariantTypeId=h.groupVariantsByVariantTypeId||null,this.setOptionPrices(),f(this,{selectedVariantValues:m,isFiltered:m,hasVariant:v,hasStock:v,hasValidProductOptionValues:v,href:v,productHref:v,mainVariantType:v,mainVariantValue:v,selectedVariant:v,displayedVariantTypes:v,isCustomerReviewEnabled:v,isCustomerReviewLoginRequired:v,isAddToCartEnabled:v,groupedAttributeValues:v,selectedVariantUnitPriceText:v})}return Object.defineProperty(T.prototype,"hasVariant",{get:function(){return h.hasVariant(this)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"hasStock",{get:function(){return h.hasStock(this)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"hasValidProductOptionValues",{get:function(){return!this.productOptionSet||this.productOptionSet.hasValidValues},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"href",{get:function(){return h.getSelectedVariantHref(this,this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"productHref",{get:function(){return this.groupVariantsByVariantTypeId||this.isFiltered?this.href:h.getProductHref(this)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"mainVariantType",{get:function(){return h.getMainVariantType(this)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"mainVariantValue",{get:function(){return h.getMainVariantValue(this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"selectedVariant",{get:function(){if(!this.hasVariant)return this.variants[0];var t=this.selectedVariantValues.map((function(t){return t.id}));return this.variants.find((function(e){return e.variantValues.every((function(e){return t.includes(e.id)}))}))},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"displayedVariantTypes",{get:function(){return h.getDisplayedVariantTypes(this,this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"isCustomerReviewEnabled",{get:function(){return b.isCustomerReviewEnabled()},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"isCustomerReviewLoginRequired",{get:function(){return b.isCustomerReviewLoginRequired()},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"isAddToCartEnabled",{get:function(){return this.hasValidProductOptionValues&&(this.selectedVariant.hasStock||this.selectedVariant.sellIfOutOfStock)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"groupedAttributeValues",{get:function(){var t,e=O(this.attributes,"productAttributeId");return(null===(t=this.attributes)||void 0===t?void 0:t.map((function(t){var i=t.productAttributeId;if(i){var n=e[i];return(null==n?void 0:n.length)&&n[0].productAttribute?{attribute:n[0].productAttribute,values:n}:void 0}})).filter((function(t){return!!t})))||[]},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"selectedVariantUnitPriceText",{get:function(){return this.getVariantUnitPriceText(this.selectedVariant)},enumerable:!1,configurable:!0}),T}();export{T as IkasProduct};
1
+ import{__spreadArray as t,__awaiter as e,__generator as i}from'./../../../ext/tslib/tslib.es6.js';import n from"lodash/sortBy";import{IkasCategory as r}from"../category/index.js";import{IkasProductVariant as a}from"./variant/index.js";import{IkasProductAttributeValue as o}from"./attribute-value/index.js";import{IkasProductVariantType as s}from"./variant-type/index.js";import{IkasBrand as u}from"../brand/index.js";import{IkasHTMLMetaData as c}from"../html-meta-data/index.js";import{IkasProductTag as d}from"./tag/index.js";import{IkasProductType as l}from"@ikas/storefront-models";export{IkasProductType}from"@ikas/storefront-models";import{IkasProductOptionSet as p}from"./option-set/index.js";import{makeObservable as f,observable as m,computed as h}from"mobx";import{IkasProductFunctions as v}from"@ikas/storefront-model-functions";import{IkasProductCampaign as g}from"./campaign/index.js";import{IkasStorefrontConfig as b}from"@ikas/storefront-config";import{Analytics as y}from"../../../analytics/analytics.js";import"../../../analytics/head/index.js";import{IkasBaseStore as V}from"../../../store/base.js";import O from"lodash/groupBy";import{IkasProductBaseUnit as P}from"./base-unit/index.js";import{formatCurrency as j}from"../../../utils/currency.js";import"lodash/get";import S from"../../../store/product/index.js";import{IkasCustomerReviewList as w}from"../../ui/customer-review-list/index.js";import{IkasProductStar as I}from"./star/index.js";var T=function(){function T(v){void 0===v&&(v={});var O,T,x,C=this;this.metaData=null,this.brand=null,this.tags=null,this.productOptionSetId=null,this.productOptionSet=null,this.campaigns=null,this.selectedVariantValues=[],this.isFiltered=!1,this.selectVariantValue=function(e,i){var n,r=C.metaData,a=C.selectedVariantValues.map((function(t){return t.variantTypeId===e.variantTypeId?e:t})),o=C.variants.find((function(t){return t.isActive&&a.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))}));if(o)C.selectedVariantValues=a;else{var s=C.variantTypes.findIndex((function(t){return t.variantType.id===e.variantTypeId}));if(s>0){var u=C.variantTypes.slice(0,s),c=C.selectedVariantValues.filter((function(t){return u.some((function(e){return e.variantType.id===t.variantTypeId}))})),d=t(t([],c,!0),[e],!1);o=C.variants.find((function(t){return t.isActive&&d.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))}))}else{var l=a.slice(0,a.length-1);(o=C.variants.find((function(t){return t.isActive&&l.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))})))||(o=C.variants.find((function(t){return t.isActive&&t.variantValues.some((function(t){return t.id===e.id}))})))}if(!o)return;C.selectedVariantValues=o.variantValues}var p=C.variantTypes.map((function(t){var e=t.variantType,i=e.values.find((function(t){return C.selectedVariantValues.some((function(e){return e.id===t.id}))}));if(i)return"".concat(e.slug,"=").concat(i.slug)})).filter((function(t){return!!t})).join("&");if(!i){var f="/".concat(r.slug);if(p&&(f="/".concat(r.slug,"?").concat(p)),f===window.location.pathname)return;var m="production"!==process.env.NODE_ENV;null===(n=V.getInstance().router)||void 0===n||n.replace(f,void 0,{shallow:m,scroll:!1})}y.productView(C)},this.getVariantUnitPriceText=function(t){var e,i,n=t.price;if(n.unitPrice&&C.baseUnit){var r=C.baseUnit.baseAmount,a=(null===(i=null===(e=C.baseUnit)||void 0===e?void 0:e.unit)||void 0===i?void 0:i.name)||"";return"".concat(j(n.unitPrice,n.currency||"",n.currencySymbol||"")," / ").concat(r&&1!==r?r:"").concat(a)}},this.getCampaigns=function(){return e(C,void 0,void 0,(function(){var t,e,n,r,a,o=this;return i(this,(function(i){switch(i.label){case 0:return t=V.getInstance(),e=t.customerStore.customer,n=e?e.customerGroupIds:null,r=this.variants.map((function(t){return t.id})),[4,S.getProductCampaigns({input:{customerGroupIds:n,salesChannelId:b.getSalesChannelId()||"",variantIds:r}})];case 1:return a=i.sent(),this.campaigns=a.data,this.campaigns?(this.campaigns.map((function(t){o.variants.map((function(e){var i;t.variantIds.some((function(t){return t===e.id}))&&(null===(i=e.campaigns)||void 0===i||i.push(t))}))})),[2,this.campaigns]):[2]}}))}))},this.getAvailableStockLocations=function(){return e(C,void 0,void 0,(function(){var t,e;return i(this,(function(i){switch(i.label){case 0:return t=this.variants.map((function(t){return t.id})),e=b.getPickupStockLocationIds(),[4,S.getVariantStockLocations({stockLocationIdList:e,variantIds:t})];case 1:return[2,i.sent().data||[]]}}))}))},this.getCustomerReviews=function(t){return e(C,void 0,void 0,(function(){var e;return i(this,(function(i){switch(i.label){case 0:return[4,(e=new w({productId:this.id,limit:null==t?void 0:t.limit,page:null==t?void 0:t.page})).getInitial()];case 1:return i.sent(),[2,e]}}))}))},this.getProductOptionSet=function(){return e(C,void 0,void 0,(function(){var t,e;return i(this,(function(i){switch(i.label){case 0:return this.productOptionSet?[2,!0]:this.productOptionSetId?[4,S.listProductOptionSet({id:{eq:this.productOptionSetId}})]:[2,!1];case 1:return(t=i.sent()).isSuccess&&(null===(e=t.data)||void 0===e?void 0:e.length)?(this.productOptionSet=t.data[0],this.setOptionPrices(),[2,!0]):[2,!1]}}))}))},this.setOptionPrices=function(){var t,e=C.variants[0];if(e){var i=e.price.currency;null===(t=C.productOptionSet)||void 0===t||t.options.forEach((function(t){var e;t.selectSettings&&t.selectSettings.values.forEach((function(t){var e;t.otherPrices&&(t.price=(null===(e=t.otherPrices.find((function(t){return t.currencyCode===i})))||void 0===e?void 0:e.price)||t.price)})),t.otherPrices&&(t.price=(null===(e=t.otherPrices.find((function(t){return t.currencyCode===i})))||void 0===e?void 0:e.price)||t.price)}))}},this.id=v.id||Date.now()+"",this.name=v.name||"",this.type=v.type||l.PHYSICAL,this.description=v.description||"",this.shortDescription=v.shortDescription||"",this.metaData=v.metaData?new c(v.metaData):null,this.brand=v.brand?new u(v.brand):null,this.categories=v.categories?v.categories.map((function(t){return new r(t)})):[],this.tags=v.tags?v.tags.map((function(t){return new d(t)})):[],this.variants=v.variants?v.variants.map((function(t){return new a(t)})):[],this.attributes=v.attributes?v.attributes.map((function(t){return new o(t)})):[],this.variantTypes=v.variantTypes?v.variantTypes.map((function(t){return new s(t)})):[],this.productOptionSetId=v.productOptionSetId||null,this.averageRating=null!==(O=v.averageRating)&&void 0!==O?O:null,this.reviewCount=null!==(T=v.reviewCount)&&void 0!==T?T:null,this.stars=v.stars?v.stars.map((function(t){return new I(t)})):null,this.baseUnit=v.baseUnit?new P(v.baseUnit):null,this.productOptionSet=v.productOptionSet?new p(v.productOptionSet):null,this.campaigns=(null===(x=v.campaigns)||void 0===x?void 0:x.map((function(t){return new g(t)})))||null,this.selectedVariantValues=v.selectedVariantValues||[],this.variantTypes=n(this.variantTypes,"order"),this.groupVariantsByVariantTypeId=v.groupVariantsByVariantTypeId||null,this.setOptionPrices(),f(this,{selectedVariantValues:m,isFiltered:m,hasVariant:h,hasStock:h,hasValidProductOptionValues:h,href:h,productHref:h,mainVariantType:h,mainVariantValue:h,selectedVariant:h,displayedVariantTypes:h,isCustomerReviewEnabled:h,isCustomerReviewLoginRequired:h,isAddToCartEnabled:h,groupedAttributeValues:h,selectedVariantUnitPriceText:h})}return Object.defineProperty(T.prototype,"hasVariant",{get:function(){return v.hasVariant(this)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"hasStock",{get:function(){return v.hasStock(this)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"hasValidProductOptionValues",{get:function(){return!this.productOptionSet||this.productOptionSet.hasValidValues},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"href",{get:function(){return v.getSelectedVariantHref(this,this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"productHref",{get:function(){return this.groupVariantsByVariantTypeId||this.isFiltered?this.href:v.getProductHref(this)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"mainVariantType",{get:function(){return v.getMainVariantType(this)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"mainVariantValue",{get:function(){return v.getMainVariantValue(this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"selectedVariant",{get:function(){if(!this.hasVariant)return this.variants[0];var t=this.selectedVariantValues.map((function(t){return t.id}));return this.variants.find((function(e){return e.variantValues.every((function(e){return t.includes(e.id)}))}))},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"displayedVariantTypes",{get:function(){return v.getDisplayedVariantTypes(this,this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"isCustomerReviewEnabled",{get:function(){return b.isCustomerReviewEnabled()},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"isCustomerReviewLoginRequired",{get:function(){return b.isCustomerReviewLoginRequired()},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"isAddToCartEnabled",{get:function(){return this.hasValidProductOptionValues&&(this.selectedVariant.hasStock||this.selectedVariant.sellIfOutOfStock)},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"groupedAttributeValues",{get:function(){var t,e=O(this.attributes,"productAttributeId");return(null===(t=this.attributes)||void 0===t?void 0:t.map((function(t){var i=t.productAttributeId;if(i){var n=e[i];return(null==n?void 0:n.length)&&n[0].productAttribute?{attribute:n[0].productAttribute,values:n}:void 0}})).filter((function(t){return!!t})))||[]},enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype,"selectedVariantUnitPriceText",{get:function(){return this.getVariantUnitPriceText(this.selectedVariant)},enumerable:!1,configurable:!0}),T}();export{T as IkasProduct};
@@ -0,0 +1,6 @@
1
+ import { IkasProductStar as IProductStar } from "@ikas/storefront-models";
2
+ export declare class IkasProductStar implements IProductStar {
3
+ count: number;
4
+ star: number;
5
+ constructor(data: IProductStar);
6
+ }
@@ -0,0 +1 @@
1
+ var t=function(t){this.count=t.count,this.star=t.star};export{t as IkasProductStar};
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import o from"lodash/xorBy";import s from"lodash/cloneDeep";import n from"./api.js";import{IkasCustomer as a}from"../../models/data/customer/index.js";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasCustomerEmailSubscriptionStatus as c}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout/country-settings-model.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import{IkasRaffleParticipant as d}from"../../models/data/raffle/index.js";import"../../models/data/state/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import u from"../raffle/index.js";import'./../../ext/@ikas/fe-api-client/build/utils/api.js';import'./../../ext/axios/index.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_defineProperty.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseGetTag.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_stringToPath.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseToString.js';import l from"../product/index.js";import{Analytics as h}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{IkasStorefrontConfig as m}from"@ikas/storefront-config";import{SaveMyCustomerInput as p}from"@ikas/storefront-api";import{populateRaffleParticipantProducts as f}from"@ikas/storefront-providers";var v="undefined"==typeof localStorage,g=function(){function g(o){var a=this;this.customer=null,this.token=null,this.tokenExpiry=null,this.baseStore=null,this._initialized=!1,this._visitorSubscribedEmail=!1,this._lastViewedProducts=[],this._customerConsentGranted=!1,this._refundSettings=null,this._captchaToken=null,this._savedLastViewedProducts=[],this._savedLastViewedProductsResponse=null,this.toAnalyticsCustomer=function(t){return i(i({},t),{consentGranted:a._customerConsentGranted})},this.login=function(i,r){return t(a,void 0,void 0,(function(){var t,o;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:i,password:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(o=t.data,this.setToken(o.token,o.tokenExpiry),o.customer&&this.setCustomer(o.customer),this.customer&&h.customerLogin(),this.saveLocalLastViewedProducts(),[2,!0]):[2,!1]}}))}))},this.logout=function(){var t;a.clearLocalData(),null===(t=a.baseStore)||void 0===t||t.cartStore.removeCart(),h.customerLogout()},this.register=function(i,r,o,s,c,d){return t(a,void 0,void 0,(function(){var t,a;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.register({email:o,password:s,firstName:i,lastName:r,isAcceptMarketing:c,attributes:d,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&(null===(a=t.data)||void 0===a?void 0:a.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.saveLocalLastViewedProducts(),h.completeRegistration(this.toAnalyticsCustomer(this.customer)),[2,!0]):[2,!1]}}))}))},this.saveContactForm=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return h.contactForm(r),[4,this.getCaptcha()];case 1:return e.sent(),[4,n.sendContactFormToMerchant(i(i({},r),{captchaToken:this._captchaToken}))];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.checkEmail=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.checkEmail({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!!t.isSuccess&&!!(null===(r=t.data)||void 0===r?void 0:r.exists)]}}))}))},this.forgotPassword=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.forgotPassword({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.recoverPassword=function(i,r,o){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.recoverPassword({password:i,passwordAgain:r,token:o,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.saveCustomer=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.saveCustomer({input:new p(i)})];case 1:return(t=e.sent()).isSuccess&&t.data?(this.setCustomer(t.data),[2,!0]):[2,!1]}}))}))},this.getOrders=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.getOrders({})];case 1:return[2,t.sent().data||[]]}}))}))},this.getOrder=function(i){return t(a,void 0,void 0,(function(){var t,r,o;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrders({orderId:i})];case 1:return(t=e.sent()).isSuccess&&(null===(o=t.data)||void 0===o?void 0:o.length)?(r=t.data[0],[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),r.refundSettings=this._refundSettings,[2,r]}}))}))},this.getOrderByEmail=function(i,r){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.getOrderByEmail({email:i,orderNumber:r})];case 1:return[2,t.sent().data||null]}}))}))},this.getOrderTransactions=function(i){return void 0===i&&(i={}),t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.listOrderTransactions({checkoutId:{eq:i.checkoutId},id:{eq:i.checkoutId},orderId:{eq:i.orderId}})];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProductsIds=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProducts=function(){return t(a,void 0,void 0,(function(){var t,i,r,o,s,a;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return(t=e.sent()).isSuccess&&(null===(r=t.data)||void 0===r?void 0:r.length)?[4,l.searchProducts({input:{productIdList:t.data.map((function(t){return t.productId})),priceListId:m.getPriceListId(),salesChannelId:m.getSalesChannelId()}})]:[2,[]];case 2:return i=e.sent(),null===(s=null===(o=i.data)||void 0===o?void 0:o.data)||void 0===s||s.forEach((function(t){t.selectedVariantValues=t.variants[0].variantValues})),[2,(null===(a=null==i?void 0:i.data)||void 0===a?void 0:a.data)||[]]}}))}))},this.addProductToFavorites=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:if(!(null===(r=this.customer)||void 0===r?void 0:r.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!0,productId:i})];case 1:return t=e.sent(),h.addToWishlist(i),[2,t.data||!1]}}))}))},this.removeProductFromFavorites=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:if(!(null===(r=this.customer)||void 0===r?void 0:r.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!1,productId:i})];case 1:return t=e.sent(),h.addToWishlist(i),[2,t.data||!1]}}))}))},this.isProductFavorite=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!(null===(t=this.customer)||void 0===t?void 0:t.id))throw Error("Unauthorized");return[4,n.isFavoriteProduct({productId:i})];case 1:return[2,e.sent().data||!1]}}))}))},this.createEmailSubscription=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.subscribeToMarketingNotifications({input:{email:i,captchaToken:this._captchaToken}})];case 2:return(t=e.sent()).isSuccess&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,c.SUBSCRIBED):this._visitorSubscribedEmail=!0,h.createEmailSubscripition(i)),[2,t.isSuccess]}}))}))},this.sendReview=function(r){return t(a,void 0,void 0,(function(){var t,o,s,a;return e(this,(function(e){switch(e.label){case 0:if(t=m.getCustomerReviewSettings(),o=m.getSalesChannelId(),!t)return[2];if(!(s=null===(a=this.customer)||void 0===a?void 0:a.id)&&t.customerLoginRequired)throw Error("Unauthorized");return[4,n.createCustomerReview({input:i(i({},r),{customerId:t.customerLoginRequired?s:void 0,salesChannelId:o||""})})];case 1:return[2,e.sent().data]}}))}))},this.onCustomerConsentGrant=function(){a.saveCustomerConsent()},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a.initialized&&(clearInterval(e),t(null))}),100)}))},this.waitUntilCaptchaTokenInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a._captchaToken&&(clearInterval(e),t(null))}),100)}))},this.getRaffles=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,u.listRaffleParticipants()];case 1:return(t=e.sent())&&t.data?[4,f(t.data)]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2,null===(i=t.data)||void 0===i?void 0:i.map((function(t){return new d(t)}))]}}))}))},this.getCustomerAttributes=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,n.listCustomerAttribute()];case 1:return t=e.sent(),this.customer&&(null===(i=this.customer.attributes)||void 0===i||i.forEach((function(e){var i,r,o;e.customerAttribute=(null===(i=t.data)||void 0===i?void 0:i.find((function(t){return t.id===e.customerAttributeId})))||null,e.customerAttributeOptionId&&(e.customerAttributeOption=(null===(o=null===(r=e.customerAttribute)||void 0===r?void 0:r.options)||void 0===o?void 0:o.find((function(t){return t.id===e.customerAttributeOptionId})))||null)}))),[2,t.data||[]]}}))}))},this.getOrderRefundSettings=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return this._refundSettings?[3,2]:[4,n.listOrderRefundSettings({})];case 1:(t=e.sent()).isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)&&(this._refundSettings=t.data[0]),e.label=2;case 2:return[2]}}))}))},this.setSavedLastViewedProductsResponse=function(t){a._savedLastViewedProducts=s(a._lastViewedProducts),a._savedLastViewedProductsResponse=t},this.setCaptchaToken=function(t){a._captchaToken=t},this.baseStore=o,r(this)}return Object.defineProperty(g.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"canCreateEmailSubscription",{get:function(){var t;return!((null===(t=this.customer)||void 0===t?void 0:t.isSubscribed)||v||this._visitorSubscribedEmail)&&!window.localStorage.getItem("customerEmailSubscription")},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"customerConsentGranted",{get:function(){return this._customerConsentGranted},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"isCaptchaRequired",{get:function(){var t;return(null===(t=m.getCustomerSettings())||void 0===t?void 0:t.requireCaptchaValidation)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"useLastViewedProductResponse",{get:function(){var t;return(null===(t=this._savedLastViewedProducts)||void 0===t?void 0:t.length)&&this._savedLastViewedProductsResponse&&0===o(this._lastViewedProducts,this._savedLastViewedProducts,"productId").length},enumerable:!1,configurable:!0}),g.prototype.socialLogin=function(i){return t(this,void 0,void 0,(function(){var t,r,o;return e(this,(function(e){switch(e.label){case 0:return"undefined"==typeof window?[2]:(t=new URLSearchParams(window.location.search).get("redirect")||"",r="".concat(process.env.NEXT_PUBLIC_BASE_URL,"/ms/").concat(i,"/login/authenticate?redirect=").concat(t),[4,fetch(r,{headers:{"x-api-key":m.getApiKey()||"","x-sfid":m.getStorefrontId()||"","x-sfrid":m.getStorefrontRoutingId()||""}})]);case 1:return[4,e.sent().json()];case 2:return o=e.sent(),window.location.href=o.redirectUrl,[2]}}))}))},g.prototype.socialLoginToken=function(i){var r;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.socialLogin({code:i})];case 1:return(null==(t=e.sent())?void 0:t.isSuccess)&&(null===(r=t.data)||void 0===r?void 0:r.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.customer&&h.customerLogin(),[2,!0]):[2,!1]}}))}))},g.prototype.refundOrder=function(i){return t(this,void 0,void 0,(function(){var t,r,o=this;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=[],i.orderLineItems.map((function(e){null!==e.refundQuantity&&(null==t||t.push({orderLineItemId:e.id,quantity:e.refundQuantity?e.refundQuantity:0}))})),[4,n.createOrderRefundRequest({input:{orderId:i.id,orderLineItems:t}})];case 1:return(r=e.sent()).isSuccess&&r.data?(Object.entries(r.data).forEach((function(t){var e=t[0],i=t[1];o[e]=i})),[2,!0]):[3,3];case 2:return e.sent(),[3,3];case 3:return[2,!1]}}))}))},g.prototype.init=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.loadToken(),this.loadLastViewedProducts(),this.loadCustomerConsent(),[4,this.refreshToken()];case 1:return t.sent(),[4,this.getCustomer()];case 2:return t.sent(),this._initialized=!0,this.customer&&h.customerVisit(),[2]}}))}))},g.prototype.routeChangeInit=function(){this.customer||(this.loadToken(),this.getCustomer())},g.prototype.getCustomer=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return v||!this.token?[2]:[4,n.getCustomer()];case 1:return(t=e.sent()).data&&this.setCustomer(t.data),[2]}}))}))},g.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.token?[4,n.refreshToken({token:this.token})]:[2];case 1:return(t=e.sent()).isSuccess&&t.data?this.setToken(t.data.token,t.data.tokenExpiry):(this.token=null,this.tokenExpiry=null,this.clearLocalData()),[2]}}))}))},g.prototype.setCustomer=function(t){this.customer=new a(t)},g.prototype.getLastViewedProducts=function(){var i;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.getLastViewedProducts({customerId:this.customer.id})]:[3,2];case 1:return t=e.sent(),this._lastViewedProducts=(null===(i=s(t.data))||void 0===i?void 0:i.reverse())||[],[3,3];case 2:this.loadLastViewedProducts(),e.label=3;case 3:return[2,this._lastViewedProducts]}}))}))},g.prototype.saveLastViewedProducts=function(){v||window.localStorage.setItem("lastViewedProducts",JSON.stringify(this._lastViewedProducts))},g.prototype.loadLastViewedProducts=function(){v||(this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=s(this._lastViewedProducts).reverse())},g.prototype.getLocalLastViewedProducts=function(){if(v)return[];try{var t=window.localStorage.getItem("lastViewedProducts");if(t)return JSON.parse(t)}catch(t){}return[]},g.prototype.removeLastViewedProducts=function(){v||window.localStorage.removeItem("lastViewedProducts")},g.prototype.onProductView=function(i,r){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?this._lastViewedProducts.find((function(t){return t.productId===i}))?[2]:[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:[{productId:i,variantId:r}]}})]:[3,2];case 1:return t.sent()&&this._lastViewedProducts.push({productId:i,variantId:r}),[3,3];case 2:this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=this._lastViewedProducts.filter((function(t){return t.productId!==i})),this._lastViewedProducts.push({productId:i,variantId:r}),this._lastViewedProducts=this._lastViewedProducts.slice(-20),this.saveLastViewedProducts(),t.label=3;case 3:return[2]}}))}))},g.prototype.saveLocalLastViewedProducts=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(v)return[2];e.label=1;case 1:return e.trys.push([1,4,,5]),(t=this.getLocalLastViewedProducts()).length?[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:t}})]:[3,3];case 2:e.sent()&&this.removeLastViewedProducts(),e.label=3;case 3:return[3,5];case 4:return e.sent(),[3,5];case 5:return[2]}}))}))},g.prototype.saveCustomerConsent=function(){v||(this._customerConsentGranted=!0,window.localStorage.setItem("customerConsent","true"))},g.prototype.loadCustomerConsent=function(){v||(this._customerConsentGranted=!!window.localStorage.getItem("customerConsent"))},g.prototype.removeCustomerConsent=function(){v||window.localStorage.removeItem("customerConsent")},g.prototype.setToken=function(t,e){v||(this.token=t,this.tokenExpiry=e,localStorage.setItem("customerToken",t),localStorage.setItem("customerTokenExpiry",e+""),m.init({customerToken:t}))},g.prototype.loadToken=function(){if(!v){var t=localStorage.getItem("customerToken"),e=localStorage.getItem("customerTokenExpiry");t&&e&&this.setToken(t,parseInt(e))}},g.prototype.clearLocalTokenData=function(){localStorage.removeItem("customerToken"),localStorage.removeItem("customerTokenExpiry"),this.token=void 0,this.tokenExpiry=void 0},g.prototype.clearLocalData=function(){this.clearLocalTokenData(),this.customer=void 0,m.init({customerToken:""}),this.clearCaptchaToken()},g.prototype.clearCaptchaToken=function(){this._captchaToken=null},g.prototype.getCaptcha=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),this.isCaptchaRequired?(window.grecaptcha.execute(),[4,this.waitUntilCaptchaTokenInitialized()]):[3,2];case 1:e.sent(),window.grecaptcha.reset(),e.label=2;case 2:return[3,4];case 3:return t=e.sent(),console.log("Get captcha error",t),[3,4];case 4:return[2]}}))}))},g}();export{g as IkasCustomerStore};
1
+ import{__awaiter as t,__generator as e,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import o from"lodash/xorBy";import s from"lodash/cloneDeep";import n from"./api.js";import{IkasCustomer as a}from"../../models/data/customer/index.js";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasCustomerEmailSubscriptionStatus as c}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout/country-settings-model.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import{IkasRaffleParticipant as d}from"../../models/data/raffle/index.js";import"../../models/data/state/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import u from"../raffle/index.js";import'./../../ext/@ikas/fe-api-client/build/utils/api.js';import'./../../ext/axios/index.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_defineProperty.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseGetTag.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_stringToPath.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseToString.js';import l from"../product/index.js";import{Analytics as h}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{IkasStorefrontConfig as m}from"@ikas/storefront-config";import{SaveMyCustomerInput as p}from"@ikas/storefront-api";import{populateRaffleParticipantProducts as f}from"@ikas/storefront-providers";var v="undefined"==typeof localStorage,g=function(){function g(o){var a=this;this.customer=null,this.token=null,this.tokenExpiry=null,this.baseStore=null,this._initialized=!1,this._visitorSubscribedEmail=!1,this._lastViewedProducts=[],this._customerConsentGranted=!1,this._refundSettings=null,this._captchaToken=null,this._savedLastViewedProducts=[],this._savedLastViewedProductsResponse=null,this.toAnalyticsCustomer=function(t){return i(i({},t),{consentGranted:a._customerConsentGranted})},this.login=function(i,r){return t(a,void 0,void 0,(function(){var t,o;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:i,password:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(o=t.data,this.setToken(o.token,o.tokenExpiry),o.customer&&this.setCustomer(o.customer),this.customer&&h.customerLogin(),this.saveLocalLastViewedProducts(),[2,!0]):[2,!1]}}))}))},this.logout=function(){var t;a.clearLocalData(),null===(t=a.baseStore)||void 0===t||t.cartStore.removeCart(),h.customerLogout()},this.register=function(i,r,o,s,c,d){return t(a,void 0,void 0,(function(){var t,a;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.register({email:o,password:s,firstName:i,lastName:r,isAcceptMarketing:c,attributes:d,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&(null===(a=t.data)||void 0===a?void 0:a.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.saveLocalLastViewedProducts(),h.completeRegistration(this.toAnalyticsCustomer(this.customer)),[2,!0]):[2,!1]}}))}))},this.saveContactForm=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return h.contactForm(r),[4,this.getCaptcha()];case 1:return e.sent(),[4,n.sendContactFormToMerchant(i(i({},r),{captchaToken:this._captchaToken}))];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.checkEmail=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.checkEmail({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!!t.isSuccess&&!!(null===(r=t.data)||void 0===r?void 0:r.exists)]}}))}))},this.forgotPassword=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.forgotPassword({email:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.recoverPassword=function(i,r,o){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.recoverPassword({password:i,passwordAgain:r,token:o,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.saveCustomer=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.saveCustomer({input:new p(i)})];case 1:return(t=e.sent()).isSuccess&&t.data?(this.setCustomer(t.data),[2,!0]):[2,!1]}}))}))},this.getOrders=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.getOrders({})];case 1:return[2,t.sent().data||[]]}}))}))},this.getOrder=function(i){return t(a,void 0,void 0,(function(){var t,r,o;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrders({orderId:i})];case 1:return(t=e.sent()).isSuccess&&(null===(o=t.data)||void 0===o?void 0:o.length)?(r=t.data[0],[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),r.refundSettings=this._refundSettings,[2,r]}}))}))},this.getOrderByEmail=function(i,r){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.getOrderByEmail({email:i,orderNumber:r})];case 1:return[2,t.sent().data||null]}}))}))},this.getOrderTransactions=function(i){return void 0===i&&(i={}),t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.listOrderTransactions({checkoutId:{eq:i.checkoutId},id:{eq:i.checkoutId},orderId:{eq:i.orderId}})];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProductsIds=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProducts=function(){return t(a,void 0,void 0,(function(){var t,i,r,o,s,a;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return(t=e.sent()).isSuccess&&(null===(r=t.data)||void 0===r?void 0:r.length)?[4,l.searchProducts({input:{productIdList:t.data.map((function(t){return t.productId})),priceListId:m.getPriceListId(),salesChannelId:m.getSalesChannelId()}})]:[2,[]];case 2:return i=e.sent(),null===(s=null===(o=i.data)||void 0===o?void 0:o.data)||void 0===s||s.forEach((function(t){t.selectedVariantValues=t.variants[0].variantValues})),[2,(null===(a=null==i?void 0:i.data)||void 0===a?void 0:a.data)||[]]}}))}))},this.addProductToFavorites=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:if(!(null===(r=this.customer)||void 0===r?void 0:r.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!0,productId:i})];case 1:return t=e.sent(),h.addToWishlist(i),[2,t.data||!1]}}))}))},this.removeProductFromFavorites=function(i){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:if(!(null===(r=this.customer)||void 0===r?void 0:r.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!1,productId:i})];case 1:return t=e.sent(),h.addToWishlist(i),[2,t.data||!1]}}))}))},this.isProductFavorite=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!(null===(t=this.customer)||void 0===t?void 0:t.id))throw Error("Unauthorized");return[4,n.isFavoriteProduct({productId:i})];case 1:return[2,e.sent().data||!1]}}))}))},this.createEmailSubscription=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.subscribeToMarketingNotifications({input:{email:i,captchaToken:this._captchaToken}})];case 2:return(t=e.sent()).isSuccess&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,c.SUBSCRIBED):this._visitorSubscribedEmail=!0,h.createEmailSubscripition(i)),[2,t.isSuccess]}}))}))},this.sendReview=function(r){return t(a,void 0,void 0,(function(){var t,o,s,a;return e(this,(function(e){switch(e.label){case 0:if(t=m.getCustomerReviewSettings(),o=m.getSalesChannelId(),!t)return[2];if(!(s=null===(a=this.customer)||void 0===a?void 0:a.id)&&t.customerLoginRequired)throw Error("Unauthorized");return[4,n.createCustomerReview({input:i(i({},r),{customerId:t.customerLoginRequired?s:void 0,salesChannelId:o||""})})];case 1:return[2,e.sent().data]}}))}))},this.onCustomerConsentGrant=function(){a.saveCustomerConsent()},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a.initialized&&(clearInterval(e),t(null))}),100)}))},this.waitUntilCaptchaTokenInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a._captchaToken&&(clearInterval(e),t(null))}),100)}))},this.getRaffles=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,u.listRaffleParticipants()];case 1:return(t=e.sent())&&t.data?[4,f(t.data)]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2,null===(i=t.data)||void 0===i?void 0:i.map((function(t){return new d(t)}))]}}))}))},this.getCustomerAttributes=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,n.listCustomerAttribute()];case 1:return t=e.sent(),this.customer&&(null===(i=this.customer.attributes)||void 0===i||i.forEach((function(e){var i,r,o;e.customerAttribute=(null===(i=t.data)||void 0===i?void 0:i.find((function(t){return t.id===e.customerAttributeId})))||null,e.customerAttributeOptionId&&(e.customerAttributeOption=(null===(o=null===(r=e.customerAttribute)||void 0===r?void 0:r.options)||void 0===o?void 0:o.find((function(t){return t.id===e.customerAttributeOptionId})))||null)}))),[2,t.data||[]]}}))}))},this.getOrderRefundSettings=function(){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return this._refundSettings?[3,2]:[4,n.listOrderRefundSettings({})];case 1:(t=e.sent()).isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)&&(this._refundSettings=t.data[0]),e.label=2;case 2:return[2]}}))}))},this.setSavedLastViewedProductsResponse=function(t){a._savedLastViewedProducts=s(a._lastViewedProducts),a._savedLastViewedProductsResponse=t},this.setCaptchaToken=function(t){a._captchaToken=t},this.baseStore=o,r(this)}return Object.defineProperty(g.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"canCreateEmailSubscription",{get:function(){var t;return!((null===(t=this.customer)||void 0===t?void 0:t.isSubscribed)||v||this._visitorSubscribedEmail)&&!window.localStorage.getItem("customerEmailSubscription")},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"customerConsentGranted",{get:function(){return this._customerConsentGranted},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"isCaptchaRequired",{get:function(){var t;return(null===(t=m.getCustomerSettings())||void 0===t?void 0:t.requireCaptchaValidation)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"useLastViewedProductResponse",{get:function(){var t;return(null===(t=this._savedLastViewedProducts)||void 0===t?void 0:t.length)&&this._savedLastViewedProductsResponse&&0===o(this._lastViewedProducts,this._savedLastViewedProducts,"productId").length},enumerable:!1,configurable:!0}),g.prototype.socialLogin=function(i){return t(this,void 0,void 0,(function(){var t,r,o;return e(this,(function(e){switch(e.label){case 0:return"undefined"==typeof window?[2]:(t=new URLSearchParams(window.location.search).get("redirect")||"",r="".concat(process.env.NEXT_PUBLIC_BASE_URL,"/ms/").concat(i,"/login/authenticate?redirect=").concat(t),[4,fetch(r,{headers:{"x-api-key":m.getApiKey()||"","x-sfid":m.getStorefrontId()||"","x-sfrid":m.getStorefrontRoutingId()||""}})]);case 1:return[4,e.sent().json()];case 2:return o=e.sent(),window.location.href=o.redirectUrl,[2]}}))}))},g.prototype.socialLoginToken=function(i){var r;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.socialLogin({code:i})];case 1:return(null==(t=e.sent())?void 0:t.isSuccess)&&(null===(r=t.data)||void 0===r?void 0:r.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.customer&&h.customerLogin(),[2,!0]):[2,!1]}}))}))},g.prototype.refundOrder=function(i){return t(this,void 0,void 0,(function(){var t,r,o=this;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=[],i.orderLineItems.map((function(e){null!==e.refundQuantity&&(null==t||t.push({orderLineItemId:e.id,quantity:e.refundQuantity?e.refundQuantity:0}))})),[4,n.createOrderRefundRequest({input:{orderId:i.id,orderLineItems:t}})];case 1:return(r=e.sent()).isSuccess&&r.data?(Object.entries(r.data).forEach((function(t){var e=t[0],i=t[1];o[e]=i})),[2,!0]):[3,3];case 2:return e.sent(),[3,3];case 3:return[2,!1]}}))}))},g.prototype.init=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.loadToken(),this.loadLastViewedProducts(),this.loadCustomerConsent(),[4,this.refreshToken()];case 1:return t.sent(),[4,this.getCustomer()];case 2:return t.sent(),this._initialized=!0,this.customer&&h.customerVisit(),[2]}}))}))},g.prototype.routeChangeInit=function(){this.loadToken(),!this.token&&this.customer&&this.clearLocalData(),this.token&&!this.customer&&this.getCustomer()},g.prototype.getCustomer=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return v||!this.token?[2]:[4,n.getCustomer()];case 1:return(t=e.sent()).data&&this.setCustomer(t.data),[2]}}))}))},g.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.token?[4,n.refreshToken({token:this.token})]:[2];case 1:return(t=e.sent()).isSuccess&&t.data?this.setToken(t.data.token,t.data.tokenExpiry):(this.token=null,this.tokenExpiry=null,this.clearLocalData()),[2]}}))}))},g.prototype.setCustomer=function(t){this.customer=new a(t)},g.prototype.getLastViewedProducts=function(){var i;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.getLastViewedProducts({customerId:this.customer.id})]:[3,2];case 1:return t=e.sent(),this._lastViewedProducts=(null===(i=s(t.data))||void 0===i?void 0:i.reverse())||[],[3,3];case 2:this.loadLastViewedProducts(),e.label=3;case 3:return[2,this._lastViewedProducts]}}))}))},g.prototype.saveLastViewedProducts=function(){v||window.localStorage.setItem("lastViewedProducts",JSON.stringify(this._lastViewedProducts))},g.prototype.loadLastViewedProducts=function(){v||(this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=s(this._lastViewedProducts).reverse())},g.prototype.getLocalLastViewedProducts=function(){if(v)return[];try{var t=window.localStorage.getItem("lastViewedProducts");if(t)return JSON.parse(t)}catch(t){}return[]},g.prototype.removeLastViewedProducts=function(){v||window.localStorage.removeItem("lastViewedProducts")},g.prototype.onProductView=function(i,r){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?this._lastViewedProducts.find((function(t){return t.productId===i}))?[2]:[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:[{productId:i,variantId:r}]}})]:[3,2];case 1:return t.sent()&&this._lastViewedProducts.push({productId:i,variantId:r}),[3,3];case 2:this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=this._lastViewedProducts.filter((function(t){return t.productId!==i})),this._lastViewedProducts.push({productId:i,variantId:r}),this._lastViewedProducts=this._lastViewedProducts.slice(-20),this.saveLastViewedProducts(),t.label=3;case 3:return[2]}}))}))},g.prototype.saveLocalLastViewedProducts=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(v)return[2];e.label=1;case 1:return e.trys.push([1,4,,5]),(t=this.getLocalLastViewedProducts()).length?[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:t}})]:[3,3];case 2:e.sent()&&this.removeLastViewedProducts(),e.label=3;case 3:return[3,5];case 4:return e.sent(),[3,5];case 5:return[2]}}))}))},g.prototype.saveCustomerConsent=function(){v||(this._customerConsentGranted=!0,window.localStorage.setItem("customerConsent","true"))},g.prototype.loadCustomerConsent=function(){v||(this._customerConsentGranted=!!window.localStorage.getItem("customerConsent"))},g.prototype.removeCustomerConsent=function(){v||window.localStorage.removeItem("customerConsent")},g.prototype.setToken=function(t,e){v||(this.token=t,this.tokenExpiry=e,localStorage.setItem("customerToken",t),localStorage.setItem("customerTokenExpiry",e+""),m.init({customerToken:t}))},g.prototype.loadToken=function(){if(!v){var t=localStorage.getItem("customerToken"),e=localStorage.getItem("customerTokenExpiry");t&&e?this.setToken(t,parseInt(e)):this.clearLocalTokenData()}},g.prototype.clearLocalTokenData=function(){localStorage.removeItem("customerToken"),localStorage.removeItem("customerTokenExpiry"),this.token=void 0,this.tokenExpiry=void 0},g.prototype.clearLocalData=function(){this.clearLocalTokenData(),this.customer=void 0,m.init({customerToken:""}),this.clearCaptchaToken()},g.prototype.clearCaptchaToken=function(){this._captchaToken=null},g.prototype.getCaptcha=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),this.isCaptchaRequired?(window.grecaptcha.execute(),[4,this.waitUntilCaptchaTokenInitialized()]):[3,2];case 1:e.sent(),window.grecaptcha.reset(),e.label=2;case 2:return[3,4];case 3:return t=e.sent(),console.log("Get captcha error",t),[3,4];case 4:return[2]}}))}))},g}();export{g as IkasCustomerStore};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "4.4.0-beta.6",
3
+ "version": "4.4.0-beta.8",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -17,11 +17,11 @@
17
17
  "build": "rm -rf build && rollup -c"
18
18
  },
19
19
  "devDependencies": {
20
- "@ikas/storefront-api": "^4.4.0-beta.6",
21
- "@ikas/storefront-config": "^4.4.0-beta.6",
22
- "@ikas/storefront-model-functions": "^4.4.0-beta.6",
23
- "@ikas/storefront-models": "^4.4.0-beta.6",
24
- "@ikas/storefront-providers": "^4.4.0-beta.6",
20
+ "@ikas/storefront-api": "^4.4.0-beta.8",
21
+ "@ikas/storefront-config": "^4.4.0-beta.8",
22
+ "@ikas/storefront-model-functions": "^4.4.0-beta.8",
23
+ "@ikas/storefront-models": "^4.4.0-beta.8",
24
+ "@ikas/storefront-providers": "^4.4.0-beta.8",
25
25
  "@adyen/adyen-web": "^5.28.2",
26
26
  "@rollup/plugin-commonjs": "^22.0.0",
27
27
  "@rollup/plugin-json": "^4.1.0",
@@ -52,11 +52,11 @@
52
52
  "libphonenumber-js": "^1.10.6"
53
53
  },
54
54
  "peerDependencies": {
55
- "@ikas/storefront-api": "^4.4.0-beta.6",
56
- "@ikas/storefront-config": "^4.4.0-beta.6",
57
- "@ikas/storefront-model-functions": "^4.4.0-beta.6",
58
- "@ikas/storefront-models": "^4.4.0-beta.6",
59
- "@ikas/storefront-providers": "^4.4.0-beta.6",
55
+ "@ikas/storefront-api": "^4.4.0-beta.8",
56
+ "@ikas/storefront-config": "^4.4.0-beta.8",
57
+ "@ikas/storefront-model-functions": "^4.4.0-beta.8",
58
+ "@ikas/storefront-models": "^4.4.0-beta.8",
59
+ "@ikas/storefront-providers": "^4.4.0-beta.8",
60
60
  "mobx": "^6.1.3",
61
61
  "mobx-react-lite": "^3.1.5",
62
62
  "next": "12.2.0",