@ikas/storefront-providers 6.1.0-beta.97 → 6.1.0-beta.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e,__generator as t,__assign as n,__spreadArray as i}from'./../ext/tslib/tslib.es6.js';import r from"lodash/uniq";import a from"lodash/flatten";import{makeAutoObservable as s}from"mobx";import{IkasStorefrontPopupPageFilterTypeEnum as o,IkasThemeJsonPageType as u,IkasStorefrontPopupPageFilterDataTypeEnum as l,IkasProductAttributeType as c,IkasAmountType as d,IkasCampaignOfferProductApplicablePriceEnum as p,IkasCategoryConditionTypeEnum as f,IkasRaffleMetadataTargetType as g,IkasBlogMetaDataTargetType as v,IkasHTMLMetaDataTargetType as h,IkasThemeJsonComponentPropType as m}from"@ikas/storefront-models";import{IkasStorefrontConfig as T}from"@ikas/storefront-config";import{IkasProductFunctions as S,IkasProductVariantFunctions as I}from"@ikas/storefront-model-functions";import{IkasProductListPropValueProvider as P}from"./prop-value/product-list.js";import{IkasProductPropValueProvider as D}from"./prop-value/product-detail.js";import{IkasBrandListPropValueProvider as O}from"./prop-value/brand-list.js";import{IkasBrandPropValueProvider as C}from"./prop-value/brand.js";import{IkasLinkPropValueProvider as R}from"./prop-value/link.js";import{IkasImageListPropValueProvider as b}from"./prop-value/image-list.js";import{IkasTextPropValueProvider as y}from"./prop-value/text.js";import{IkasColorPropValueProvider as L}from"./prop-value/color.js";import{IkasBooleanPropValueProvider as E}from"./prop-value/boolean.js";import{IkasImagePropValueProvider as A}from"./prop-value/image.js";import{IkasCategoryPropValueProvider as w}from"./prop-value/category.js";import{IkasCategoryListPropValueProvider as F}from"./prop-value/category-list.js";import{IkasCustomPropValueProvider as G}from"./prop-value/custom.js";import{IkasSliderPropValueProvider as V}from"./prop-value/slider.js";import{IkasRichTextPropValueProvider as U}from"./prop-value/rich-text.js";import{IkasBlogPropValueProvider as _}from"./prop-value/blog.js";import{IkasBlogListPropValueProvider as j}from"./prop-value/blog-list.js";import{IkasAttributePropValueProvider as N}from"./prop-value/attribute.js";import{IkasAttributeListPropValueProvider as B}from"./prop-value/attribute-list.js";import{IkasBlogCategoryPropValueProvider as M}from"./prop-value/blog-category.js";import{IkasBlogCategoryListPropValueProvider as k}from"./prop-value/blog-category-list.js";import{IkasRafflePropValueProvider as x}from"./prop-value/raffle.js";import{IkasRaffleListPropValueProvider as Y}from"./prop-value/raffle-list.js";import{listMerchantSettings as q,listCustomerReviewSummary as J,searchProducts as H,listCampaignOffer as K,listCustomerReviews as X,listProductOptionSet as z,listProductBrand as Q,listCategory as $,listBlog as W,listBlogCategory as Z,listStorefrontRaffle as ee,listHTMLMetaData as te,listRaffleMetaData as ne,listBlogMetaData as ie}from"@ikas/storefront-api";import{populateRaffleProducts as re}from"./helpers/raffle.js";import{IkasVideoPropValueProvider as ae}from"./prop-value/video.js";var se=function(){function se(e,t,n,i){this.pageType=null,this.pageParams={},this.pageComponentPropValues=[],this.pageSpecificData=null,this.merchantSettings=null,this.possiblePageTypes=[],this.linkMetaDataTargetIds=[],this.productReviewSummary=null,this.theme=e,this.pageParams=t||{},this.pageType=n,this.merchantSettings=i,s(this)}return Object.defineProperty(se.prototype,"page",{get:function(){var e=this;if(this.pageType===u.CUSTOM){var t=this.pageParams.slug;return this.theme.pages.find((function(e){return e.type===u.CUSTOM&&e.slug===t}))}return this.theme.pages.find((function(t){return t.type===e.pageType}))},enumerable:!1,configurable:!0}),Object.defineProperty(se.prototype,"nextPageData",{get:function(){var e,t,i,r,a,s=[],o=[];return this.pageComponentPropValues.forEach((function(e){if(o.push({pageComponent:{id:e.pageComponent.id,componentId:e.pageComponent.componentId},propValues:e.propValues}),!s.find((function(t){return t.id===e.component.id}))){var t=n({},e.component);t.props.forEach((function(e){delete e.description,delete e.displayName,delete e.translations,delete e.groupId})),delete t.translations,delete t.defaultPropValues,delete t.displayName,delete t.description,delete t.dir,delete t.commonPropValues,s.push(t)}})),this.filterPopupList(),{props:JSON.parse(JSON.stringify({propValues:o,themeJsonComponents:s,customDataList:this.theme.customData,pageSpecificData:this.pageSpecificData||null,pageType:(null===(e=this.page)||void 0===e?void 0:e.type)||u.CUSTOM,pageTitle:(null===(t=this.page)||void 0===t?void 0:t.pageTitle)||null,pageDescription:(null===(i=this.page)||void 0===i?void 0:i.description)||null,canonicals:(null===(r=this.page)||void 0===r?void 0:r.canonicals)||null,disableIndex:(null===(a=this.page)||void 0===a?void 0:a.disableIndex)||null,settings:this.theme.settings||{},productReviewSummary:this.productReviewSummary,configJson:T.toJSON(),merchantSettings:this.getMerchantSettings()}))}},enumerable:!1,configurable:!0}),se.prototype.filterPopupList=function(){var e=this;this.pageParams.slug;var t=T.getCurrentRouting();T.getCurrentLocale(),T.getDomain();var n=T.getStorefrontId(),i=T.getStorefrontRoutingId(),r=this.pageType;(null==t?void 0:t.path)&&"/".concat(null==t?void 0:t.path);var a=T.getStorefrontPopups(),s=[];a.length&&a.forEach((function(t){var a,c,d,p,f=!1,g=!1,v=!1,h=!1;if(null===(a=t.pageFilters)||void 0===a?void 0:a.length){var m=t.pageFilters.sort((function(e,t){return e.pageType===o.CUSTOM?1:-1})).find((function(e){switch(e.pageType){case o.ACCOUNT:if(r)return[u.ACCOUNT,u.ORDERS,u.ORDER_DETAIL,u.FAVORITE_PRODUCTS,u.ADDRESSES,u.RAFFLE_ACCOUNT].includes(r);case o.LOGIN:return r===u.LOGIN;case o.REGISTER:return r===u.REGISTER;case o.CART:return r===u.CART;case o.CATEGORY:return r===u.CATEGORY;case o.HOME:return r===u.INDEX;case o.PRODUCT:return r===u.PRODUCT;case o.PRODUCT_BRAND:return r===u.BRAND;case o.CUSTOM:return!0}}));if(null===(c=null==m?void 0:m.filters)||void 0===c?void 0:c.length)switch(m.pageType){case o.CATEGORY:case o.PRODUCT:case o.PRODUCT_BRAND:var T=null===(d=e.pageSpecificData)||void 0===d?void 0:d.id,S=m.filters[0];S.type===l.ID_LIST&&T&&(f=S.value.includes(T),h=!0);break;case o.CUSTOM:f=!0;break;default:h=!0,f=!0}else t.pageFilters.find((function(e){return e.pageType===(null==m?void 0:m.pageType)}))&&(f=!0,h=!0)}else f=!0,h=!0;if(f)if(g=!!(null===(p=t.storefrontRoutings)||void 0===p?void 0:p.find((function(e){return e.storefrontId===n&&e.storefrontRoutingId===i}))),t.dateFilter){if(t.dateFilter){var I=t.dateFilter.startDate?new Date(t.dateFilter.startDate):null,P=t.dateFilter.endDate?new Date(t.dateFilter.endDate):null,D=new Date;(I&&P&&I.getTime()<=D.getTime()&&P.getTime()>=D.getTime()||I&&!P&&I.getTime()<=D.getTime()||P&&!I&&P.getTime()>=D.getTime())&&(v=!0)}}else v=!0;f&&g&&v&&(t.isFilteredOnServerSide=h,s.push(t))})),T.init({storefrontPopups:s})},Object.defineProperty(se.prototype,"specification",{get:function(){var e,t,n=this,i=this.page;return(null==i?void 0:i.type)===u.PRODUCT?null===(e=i.specifications)||void 0===e?void 0:e.find((function(e){var t;return e.id===(null===(t=n.pageSpecificData)||void 0===t?void 0:t.id)})):null===(t=null==i?void 0:i.specifications)||void 0===t?void 0:t.find((function(e){var t;return e.id===(null===(t=n.pageSpecificData)||void 0===t?void 0:t.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(se.prototype,"pageComponents",{get:function(){var e;return this.specification?this.specification.components:(null===(e=this.page)||void 0===e?void 0:e.components)||[]},enumerable:!1,configurable:!0}),Object.defineProperty(se.prototype,"$pageComponentPropValues",{get:function(){return this.pageComponentPropValues},enumerable:!1,configurable:!0}),se.prototype.getMerchantSettings=function(){return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.merchantSettings?[2,this.merchantSettings]:[4,q({})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.merchantSettings=e.data),[2]}}))}))},se.prototype.getPageData=function(){return e(this,void 0,void 0,(function(){var e,n=this;return t(this,(function(t){switch(t.label){case 0:return this.pageSpecificData?[3,2]:[4,this.getPageSpecificData()];case 1:t.sent(),t.label=2;case 2:return this.page?[4,this.getMerchantSettings()]:[2];case 3:return t.sent(),e=this,[4,Promise.all(this.pageComponents.map((function(e){return n.getPageComponentPropValues(e)})))];case 4:return e.pageComponentPropValues=t.sent(),[4,this.setLinkSlugs()];case 5:return t.sent(),[4,this.getProductReviewSummary()];case 6:return t.sent(),[2]}}))}))},se.prototype.getProductReviewSummary=function(){var n,i,r;return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.pageType!==u.PRODUCT?[3,2]:[4,J({productId:{eq:null===(n=this.pageSpecificData)||void 0===n?void 0:n.id}})];case 1:(e=t.sent()).isSuccess&&(null===(r=null===(i=e.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.length)&&(this.productReviewSummary=e.data.data[0]),t.label=2;case 2:return[2]}}))}))},se.prototype.getPageSpecificData=function(){var i,r,a,s;return e(this,void 0,void 0,(function(){var o,l,m,P,D,O,C,R,b,y,L=this;return t(this,(function(E){switch(E.label){case 0:return this.pageType&&![u.BRAND,u.PRODUCT,u.CATEGORY,u.BLOG,u.BLOG_CATEGORY,u.RAFFLE_DETAIL].includes(this.pageType)?[2]:(o=this.pageParams.slug)?(l=[],(null===(i=this.possiblePageTypes)||void 0===i?void 0:i.includes(u.BLOG))||(null===(r=this.possiblePageTypes)||void 0===r?void 0:r.includes(u.BLOG_CATEGORY))?[4,ie({slug:{eq:o}})]:[3,2]):[2];case 1:return m=E.sent(),(l=(null===(a=m.data)||void 0===a?void 0:a.data)||[]).length?[3,6]:[2];case 2:return(null===(s=this.possiblePageTypes)||void 0===s?void 0:s.includes(u.RAFFLE_DETAIL))?[4,ne({slug:{eq:o}})]:[3,4];case 3:return m=E.sent(),(l=m.data||[]).length?[3,6]:[2];case 4:return[4,te({slug:{eq:o}})];case 5:if(m=E.sent(),!(l=m.data||[])||!l.length)return[2];E.label=6;case 6:if(!(P=l[0]).targetId)return[2];switch(D=function(){return e(L,void 0,void 0,(function(){var i,r,a,s,o,l,f,g,v,h,m,D,O,C,R,b,y,L,E,A,w,F,G,V,U,_,j,N,B,M,k,x,Y,q,J,Q,$,W,Z,ee,te,ne,ie,re=this;return t(this,(function(ae){switch(ae.label){case 0:return[4,H({input:{productIdList:[P.targetId],priceListId:T.getPriceListId(),salesChannelId:T.getSalesChannelId()}})];case 1:return i=ae.sent(),(null===(x=null===(k=null==i?void 0:i.data)||void 0===k?void 0:k.data)||void 0===x?void 0:x.length)?(r=T.getCurrentRouting(),a=T.getRoutings(),s=a.find((function(e){return null===e.path})),o=null==r?void 0:r.locale,(l=i.data.data[0]).productOptionSetId?[4,z({id:{eq:l.productOptionSetId}})]:[3,3]):[2];case 2:(f=ae.sent()).isSuccess&&(null===(Y=null==f?void 0:f.data)||void 0===Y?void 0:Y.length)&&(l.productOptionSet=f.data[0]),ae.label=3;case 3:return((null===(q=T.getDomain())||void 0===q?void 0:q.includes("thepurestsolutions"))||(null===(J=process.env.NEXT_PUBLIC_GQL_URL)||void 0===J?void 0:J.includes(".dev"))&&!T.getIsEditor())&&(g=l.variants.find((function(e){return e.isActive})))?(v=!!(null===(Q=g.bundleSettings)||void 0===Q?void 0:Q.products.length),h=[l.id],v&&(null===($=g.bundleSettings)||void 0===$||$.products.forEach((function(e){h.push(e.productId)}))),[4,X({productId:v?null:l.id,productIds:v?h:null,input:{salesChannelId:T.getSalesChannelId()||""},pagination:{page:1,limit:10}})]):[3,5];case 4:m=ae.sent(),(null===(W=m.data)||void 0===W?void 0:W.data)&&m.isSuccess&&(D=m.data.data,O=!!(null===(Z=g.bundleSettings)||void 0===Z?void 0:Z.products.length),C=[l.id],O&&(null===(ee=g.bundleSettings)||void 0===ee||ee.products.forEach((function(e){C.push(e.productId)}))),l.customerReviews=n(n({data:D,count:D.length,limit:10,page:1,initialized:!0},O?{}:{productId:l.id}),O?{productIds:C}:{})),ae.label=5;case 5:return(null===(te=l.campaignOffers)||void 0===te?void 0:te.length)?[4,K({id:{in:l.campaignOffers.map((function(e){return e.id}))}})]:[3,8];case 6:return(R=ae.sent()).isSuccess&&(null===(ne=R.data)||void 0===ne?void 0:ne.length)?(b=R.data[0],y=[],L=[],b.offers.forEach((function(e){return y.push(e.productId)})),[4,H({input:{productIdList:y,priceListId:T.getPriceListId(),salesChannelId:T.getSalesChannelId()}})]):[3,8];case 7:(A=ae.sent()).isSuccess&&A.data&&b.offers.forEach((function(e){var t,i,r=null===(i=null===(t=A.data)||void 0===t?void 0:t.data)||void 0===i?void 0:i.find((function(t){return t.id===e.productId}));if(r){var a=r.variants.filter((function(t){return I.hasStock(t)&&!(e.excludedVariantIdList||[]).some((function(e){return e===t.id}))})).map((function(t){if(!e.discountAmount)return t;var i=!1;return e.discountType===d.AMOUNT&&(i=!0),n(n({},t),{prices:t.prices.map((function(t){var r=null!==t.discountPrice?t.discountPrice:t.sellPrice,a=r,s=r-(i?e.discountAmount:r*e.discountAmount/100);return e.applicablePrice===p.SELL_PRICE&&(a=t.sellPrice,s=t.sellPrice-(i?e.discountAmount:t.sellPrice*e.discountAmount/100)),n(n({},t),{sellPrice:a,discountPrice:s})}))})}));a.length&&L.push({campaignOfferId:b.id,campaignOfferProductId:e.id,product:n(n({},r),{variants:a})})}E||(E={campaignOfferId:b.id,title:e.title,description:e.description})})),l.appliedCampaignOffer=E,l.offers=L,ae.label=8;case 8:return l.productGroup?[4,H({input:{productGroupId:l.productGroup.id,productGroupKey:l.productGroup.groupKey,priceListId:T.getPriceListId(),salesChannelId:T.getSalesChannelId(),perPage:200}})]:[3,10];case 9:(w=ae.sent()).isSuccess&&(null===(ie=w.data)||void 0===ie?void 0:ie.data)&&(l.productGroupItems=w.data.data.map((function(e){var t,n;return{productId:e.id,image:e.variants[0].images&&e.variants[0].images.length?e.variants[0].images[0].image:null,href:S.getProductHref(e),groupValues:null===(t=e.productGroup)||void 0===t?void 0:t.values,order:null===(n=e.productGroup)||void 0===n?void 0:n.order}}))),ae.label=10;case 10:return l.attributes.length||l.variants.some((function(e){return e.attributes.some((function(e){var t;return(null===(t=e.productAttribute)||void 0===t?void 0:t.type)===c.PRODUCT}))}))?(F=l,[4,this.setProductAttributes(l)]):[3,13];case 11:return F.attributes=ae.sent(),[4,Promise.all(l.variants.map((function(n){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return e=n,[4,this.setProductAttributes(n)];case 1:return e.attributes=t.sent(),[2]}}))}))})))];case 12:ae.sent(),ae.label=13;case 13:return(G=l.variants.find((function(e){return e.isActive})))?(l.selectedVariantValues=G.variantValues,V=S.getDisplayedVariantTypes,this.pageSpecificData=l,(U=V(this.pageSpecificData,l.selectedVariantValues)).length&&(_=U[0]).displayedVariantValues.length&&(j=_.displayedVariantValues.find((function(e){return e.hasStock})))&&(this.pageSpecificData.selectedVariantValues=j.variant.variantValues),this.pageType=u.PRODUCT,N=P,B=s&&s.locale===(null==r?void 0:r.locale),N&&(null==N?void 0:N.translations)&&!B&&(M=null==N?void 0:N.translations.find((function(e){return e.locale===o})),N.pageTitle=(null==M?void 0:M.pageTitle)||null,N.description=(null==M?void 0:M.description)||null),this.setPageMetaData(N),[2]):[2]}}))}))},O=function(){return e(L,void 0,void 0,(function(){var e,n,i,r,a,s,o,l,c,d,p;return t(this,(function(t){switch(t.label){case 0:return[4,Q({id:{eq:P.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(p=null===(d=e.data)||void 0===d?void 0:d.data)||void 0===p?void 0:p.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=u.BRAND,i=P,r=T.getRoutings(),a=r.find((function(e){return null===e.path})),s=T.getCurrentRouting(),o=null==s?void 0:s.locale,l=a&&a.locale===(null==s?void 0:s.locale),i&&(null==i?void 0:i.translations)&&!l&&(c=null==i?void 0:i.translations.find((function(e){return e.locale===o})),i.pageTitle=(null==c?void 0:c.pageTitle)||null,i.description=(null==c?void 0:c.description)||null),this.setPageMetaData(i),[2]):[2]}}))}))},C=function(){return e(L,void 0,void 0,(function(){var e,n,i,r,a,s,o,l,c,d,p,g,v,h,m;return t(this,(function(t){switch(t.label){case 0:return[4,$({id:{eq:P.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(v=null===(g=e.data)||void 0===g?void 0:g.data)||void 0===v?void 0:v.length)?(n=e.data.data[0]).conditions&&(i=n.conditions.find((function(e){return e.conditionType===f.PRODUCT_BRAND})))?[4,Q({id:{eq:i.valueList[0]}})]:[3,3]:[2];case 2:(r=t.sent()).isSuccess&&(null===(m=null===(h=r.data)||void 0===h?void 0:h.data)||void 0===m?void 0:m.length)&&(n.conditionValues={brand:r.data.data[0]}),t.label=3;case 3:return this.pageSpecificData=n,this.pageType=u.CATEGORY,a=P,s=T.getRoutings(),o=s.find((function(e){return null===e.path})),l=T.getCurrentRouting(),c=null==l?void 0:l.locale,d=o&&o.locale===(null==l?void 0:l.locale),a&&(null==a?void 0:a.translations)&&!d&&(p=null==a?void 0:a.translations.find((function(e){return e.locale===c})),a.pageTitle=(null==p?void 0:p.pageTitle)||null,a.description=(null==p?void 0:p.description)||null),this.setPageMetaData(a),[2]}}))}))},R=function(){return e(L,void 0,void 0,(function(){var e,n,i,r;return t(this,(function(t){switch(t.label){case 0:return[4,W({id:{eq:P.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(i=e.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=u.BLOG,this.setPageMetaData(P),[2]):[2]}}))}))},b=function(){return e(L,void 0,void 0,(function(){var e,n,i,r;return t(this,(function(t){switch(t.label){case 0:return[4,Z({id:{eq:P.targetId},pagination:{page:1,limit:1}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(i=e.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=u.BLOG_CATEGORY,this.setPageMetaData(P),[2]):[2]}}))}))},y=function(){return e(L,void 0,void 0,(function(){var e,n,i,r;return t(this,(function(t){switch(t.label){case 0:return[4,ee({id:{eq:P.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(i=e.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],[4,re([n])]):[2];case 2:return t.sent(),this.pageSpecificData=n,this.pageType=u.RAFFLE_DETAIL,this.setPageMetaData(P),[2]}}))}))},P.targetType){case h.BRAND:return[3,7];case h.CATEGORY:return[3,9];case h.PRODUCT:return[3,11];case v.BLOG:return[3,13];case v.BLOG_CATEGORY:return[3,15];case g.RAFFLE:return[3,17]}return[3,19];case 7:return[4,O()];case 8:return[2,E.sent()];case 9:return[4,C()];case 10:return[2,E.sent()];case 11:return[4,D()];case 12:return[2,E.sent()];case 13:return[4,R()];case 14:return[2,E.sent()];case 15:return[4,b()];case 16:return[2,E.sent()];case 17:return[4,y()];case 18:return[2,E.sent()];case 19:return[3,20];case 20:return[2]}}))}))},se.prototype.getPageComponentPropValues=function(n){return e(this,void 0,void 0,(function(){var i,r,a,s=this;return t(this,(function(o){switch(o.label){case 0:return((i=this.theme.components.find((function(e){return e.id===n.componentId}))).isHeader||i.isFooter)&&(n.propValues=i.commonPropValues||n.propValues),r={pageComponent:n,component:i,propValues:{}},a=function(i){return e(s,void 0,void 0,(function(){var e,a;return t(this,(function(t){switch(t.label){case 0:return e=r.propValues,a=i.name,[4,this.getPageComponentPropValue(n,i)];case 1:return e[a]=t.sent(),[2]}}))}))},[4,Promise.all(i.props.map(a))];case 1:return o.sent(),[2,r]}}))}))},se.prototype.getPageComponentPropValue=function(i,r){return e(this,void 0,void 0,(function(){var e,a,s,o,u,l,c,d,p,f,g=this;return t(this,(function(t){switch(t.label){case 0:if(a=i.propValues[r.name],s=[m.RAFFLE_LIST],null==a&&!s.includes(r.type))return[2,null];switch(r.type){case m.TEXT:return[3,1];case m.RICH_TEXT:return[3,2];case m.BOOLEAN:return[3,3];case m.IMAGE:return[3,4];case m.IMAGE_LIST:return[3,5];case m.BRAND:return[3,6];case m.BRAND_LIST:return[3,7];case m.PRODUCT_LIST:return[3,8];case m.PRODUCT_DETAIL:return[3,9];case m.PRODUCT_ATTRIBUTE:return[3,10];case m.PRODUCT_ATTRIBUTE_LIST:return[3,11];case m.CATEGORY:return[3,12];case m.CATEGORY_LIST:return[3,13];case m.LINK:case m.LIST_OF_LINK:return[3,14];case m.COLOR:return[3,15];case m.CUSTOM:return[3,16];case m.COMPONENT:case m.COMPONENT_LIST:return[3,17];case m.BLOG:return[3,19];case m.BLOG_LIST:return[3,20];case m.BLOG_CATEGORY:return[3,21];case m.BLOG_CATEGORY_LIST:return[3,22];case m.RAFFLE:return[3,23];case m.RAFFLE_LIST:return[3,24];case m.SLIDER:return[3,25];case m.VIDEO:return[3,26]}return[3,27];case 1:return e=new y(a),[3,28];case 2:return e=new U(a),[3,28];case 3:return e=new E(a),[3,28];case 4:return e=new A(a),[3,28];case 5:return e=new b(a),[3,28];case 6:return e=new C(a),[3,28];case 7:return e=new O(a),[3,28];case 8:return o=this.theme.components.find((function(e){return e.id===i.componentId})),u=[],o&&(d=o.props.find((function(e){return e.name===r.name})))&&(u=d.excludedFields||[]),e=new P(this.pageType,n(n({},a),{excludedFields:u}),this.pageSpecificData),[3,28];case 9:return e=new D(a),[3,28];case 10:return e=new N(a),[3,28];case 11:return e=new B(a),[3,28];case 12:return l=this.theme.components.find((function(e){return e.id===i.componentId})),c=[],l&&(d=l.props.find((function(e){return e.name===r.name})))&&(c=d.excludedFieldsCategory||[]),e=new w(n(n({},a),{excludedFieldsCategory:c})),[3,28];case 13:return e=new F(a),[3,28];case 14:return e=new R(a,this.theme,this.linkMetaDataTargetIds),[3,28];case 15:return e=new L(a),[3,28];case 16:return(p=this.theme.customData.find((function(e){return e.id===r.customDataId})))?(e=new G(a,p,this.theme,this.pageType,this,this.pageSpecificData,this.pageParams),[3,28]):[2];case 17:return f=a,[4,Promise.all(f.map((function(e){return g.getPageComponentPropValues(e)})))];case 18:case 29:return[2,t.sent()];case 19:return e=new _(a),[3,28];case 20:return e=new j(this.pageType,a,this.pageSpecificData),[3,28];case 21:return e=new M(a),[3,28];case 22:return e=new k(a),[3,28];case 23:return e=new x(a),[3,28];case 24:return e=new Y,[3,28];case 25:return e=new V(a),[3,28];case 26:return e=new ae(a),[3,28];case 27:return[3,28];case 28:return[4,null==e?void 0:e.getValue()]}}))}))},se.prototype.setPageMetaData=function(e){this.page&&(this.page.pageTitle=e.pageTitle||null,this.page.description=e.description||null,this.page.canonicals=e.canonicals||null,this.page.disableIndex=e.disableIndex||null)},se.prototype.setLinkSlugs=function(){return e(this,void 0,void 0,(function(){var e,n,i;return t(this,(function(t){switch(t.label){case 0:return e=[],n=[],i=[],this.linkMetaDataTargetIds.forEach((function(t){switch(t.type){case"DEFAULT":e.push(t);break;case"BLOG":n.push(t);break;case"RAFFLE":i.push(t)}})),[4,Promise.all([this.getLinkSlugs(e,"DEFAULT"),this.getLinkSlugs(n,"BLOG"),this.getLinkSlugs(i,"RAFFLE")])];case 1:return[2,t.sent()]}}))}))},se.prototype.getLinkSlugs=function(n,i){return e(this,void 0,void 0,(function(){var a,s,o=this;return t(this,(function(u){switch(u.label){case 0:return a=r(n.map((function(e){return e.id}))),s=[],a.length?[4,function(){return e(o,void 0,void 0,(function(){var e,n,r,o,u;return t(this,(function(t){switch(t.label){case 0:switch(e=[],i){case"DEFAULT":return[3,1];case"BLOG":return[3,3];case"RAFFLE":return[3,5]}return[3,7];case 1:return[4,te({targetId:{in:a}})];case 2:return n=t.sent(),e=n.data||[],[3,8];case 3:return[4,ie({targetId:{in:a}})];case 4:return r=t.sent(),e=(null===(u=r.data)||void 0===u?void 0:u.data)||[],[3,8];case 5:return[4,ne({targetId:{in:a}})];case 6:return o=t.sent(),e=o.data||[],[3,8];case 7:return[3,8];case 8:return e.length&&(s=e),[2]}}))}))}()]:[2];case 1:return u.sent(),n.forEach((function(e){var t=s.find((function(t){return t.targetId===e.id}));t&&(e.navigationLink.href+=t.slug)})),[2]}}))}))},se.prototype.getFlatCustomData=function(e){var t=this;if(!e.nestedData||!e.nestedData.length)return[e];var n=a(e.nestedData.map((function(e){return t.getFlatCustomData(e)}))),i=[];return i.push(e),i=i.concat(n)},se.prototype.setProductAttributes=function(r){return e(this,void 0,void 0,(function(){var a,s,o=this;return t(this,(function(u){switch(u.label){case 0:return a=r.attributes.filter((function(e){var t;return(null===(t=e.productAttribute)||void 0===t?void 0:t.type)===c.PRODUCT})).map((function(i){return e(o,void 0,void 0,(function(){var e,r,a,s;return t(this,(function(t){switch(t.label){case 0:return i.value?[4,H({input:{productIdList:JSON.parse(i.value),priceListId:T.getPriceListId(),salesChannelId:T.getSalesChannelId()}})]:[2,n(n({},i),{products:[]})];case 1:return e=t.sent(),null===(a=null===(r=e.data)||void 0===r?void 0:r.data)||void 0===a||a.forEach((function(e){e.selectedVariantValues=e.variants[0].variantValues})),[2,n(n({},i),{products:(null===(s=e.data)||void 0===s?void 0:s.data)||[]})]}}))}))})),[4,Promise.allSettled(a)];case 1:return s=u.sent().filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value})),[2,i(i([],r.attributes.filter((function(e){var t;return(null===(t=e.productAttribute)||void 0===t?void 0:t.type)!==c.PRODUCT})),!0),s,!0)]}}))}))},se}();export{se as IkasPageDataProvider};
|
|
1
|
+
import{__awaiter as e,__generator as t,__assign as n,__spreadArray as i}from'./../ext/tslib/tslib.es6.js';import r from"lodash/uniq";import a from"lodash/flatten";import{makeAutoObservable as s}from"mobx";import{IkasStorefrontPopupPageFilterTypeEnum as o,IkasThemeJsonPageType as u,IkasStorefrontPopupPageFilterDataTypeEnum as l,IkasProductAttributeType as c,IkasAmountType as d,IkasCampaignOfferProductApplicablePriceEnum as p,IkasCategoryConditionTypeEnum as f,IkasRaffleMetadataTargetType as g,IkasBlogMetaDataTargetType as v,IkasHTMLMetaDataTargetType as h,IkasThemeJsonComponentPropType as m}from"@ikas/storefront-models";import{IkasStorefrontConfig as T}from"@ikas/storefront-config";import{IkasProductFunctions as S,IkasProductVariantFunctions as I}from"@ikas/storefront-model-functions";import{IkasProductListPropValueProvider as P}from"./prop-value/product-list.js";import{IkasProductPropValueProvider as D}from"./prop-value/product-detail.js";import{IkasBrandListPropValueProvider as O}from"./prop-value/brand-list.js";import{IkasBrandPropValueProvider as C}from"./prop-value/brand.js";import{IkasLinkPropValueProvider as R}from"./prop-value/link.js";import{IkasImageListPropValueProvider as b}from"./prop-value/image-list.js";import{IkasTextPropValueProvider as y}from"./prop-value/text.js";import{IkasColorPropValueProvider as L}from"./prop-value/color.js";import{IkasBooleanPropValueProvider as E}from"./prop-value/boolean.js";import{IkasImagePropValueProvider as A}from"./prop-value/image.js";import{IkasCategoryPropValueProvider as w}from"./prop-value/category.js";import{IkasCategoryListPropValueProvider as F}from"./prop-value/category-list.js";import{IkasCustomPropValueProvider as G}from"./prop-value/custom.js";import{IkasSliderPropValueProvider as V}from"./prop-value/slider.js";import{IkasRichTextPropValueProvider as U}from"./prop-value/rich-text.js";import{IkasBlogPropValueProvider as _}from"./prop-value/blog.js";import{IkasBlogListPropValueProvider as j}from"./prop-value/blog-list.js";import{IkasAttributePropValueProvider as N}from"./prop-value/attribute.js";import{IkasAttributeListPropValueProvider as B}from"./prop-value/attribute-list.js";import{IkasBlogCategoryPropValueProvider as M}from"./prop-value/blog-category.js";import{IkasBlogCategoryListPropValueProvider as k}from"./prop-value/blog-category-list.js";import{IkasRafflePropValueProvider as x}from"./prop-value/raffle.js";import{IkasRaffleListPropValueProvider as Y}from"./prop-value/raffle-list.js";import{listMerchantSettings as q,listCustomerReviewSummary as J,searchProducts as H,listCampaignOffer as K,listCustomerReviews as X,listProductOptionSet as z,listProductBrand as Q,listCategory as $,listBlog as W,listBlogCategory as Z,listStorefrontRaffle as ee,listHTMLMetaData as te,listRaffleMetaData as ne,listBlogMetaData as ie}from"@ikas/storefront-api";import{populateRaffleProducts as re}from"./helpers/raffle.js";import{IkasVideoPropValueProvider as ae}from"./prop-value/video.js";var se=function(){function se(e,t,n,i){this.pageType=null,this.pageParams={},this.pageComponentPropValues=[],this.pageSpecificData=null,this.merchantSettings=null,this.possiblePageTypes=[],this.linkMetaDataTargetIds=[],this.productReviewSummary=null,this.theme=e,this.pageParams=t||{},this.pageType=n,this.merchantSettings=i,s(this)}return Object.defineProperty(se.prototype,"page",{get:function(){var e=this;if(this.pageType===u.CUSTOM){var t=this.pageParams.slug;return this.theme.pages.find((function(e){return e.type===u.CUSTOM&&e.slug===t}))}return this.theme.pages.find((function(t){return t.type===e.pageType}))},enumerable:!1,configurable:!0}),Object.defineProperty(se.prototype,"nextPageData",{get:function(){var e,t,i,r,a,s=[],o=[];return this.pageComponentPropValues.forEach((function(e){if(o.push({pageComponent:{id:e.pageComponent.id,componentId:e.pageComponent.componentId},propValues:e.propValues}),!s.find((function(t){return t.id===e.component.id}))){var t=n({},e.component);t.props.forEach((function(e){delete e.description,delete e.displayName,delete e.translations,delete e.groupId})),delete t.translations,delete t.defaultPropValues,delete t.displayName,delete t.description,delete t.dir,delete t.commonPropValues,s.push(t)}})),this.filterPopupList(),{props:JSON.parse(JSON.stringify({propValues:o,themeJsonComponents:s,customDataList:this.theme.customData,pageSpecificData:this.pageSpecificData||null,pageType:(null===(e=this.page)||void 0===e?void 0:e.type)||u.CUSTOM,pageTitle:(null===(t=this.page)||void 0===t?void 0:t.pageTitle)||null,pageDescription:(null===(i=this.page)||void 0===i?void 0:i.description)||null,canonicals:(null===(r=this.page)||void 0===r?void 0:r.canonicals)||null,disableIndex:(null===(a=this.page)||void 0===a?void 0:a.disableIndex)||null,settings:this.theme.settings||{},productReviewSummary:this.productReviewSummary,configJson:T.toJSON(),merchantSettings:this.getMerchantSettings()}))}},enumerable:!1,configurable:!0}),se.prototype.filterPopupList=function(){var e=this;this.pageParams.slug;var t=T.getCurrentRouting();T.getCurrentLocale(),T.getDomain();var n=T.getStorefrontId(),i=T.getStorefrontRoutingId(),r=this.pageType;(null==t?void 0:t.path)&&"/".concat(null==t?void 0:t.path);var a=T.getStorefrontPopups(),s=[];a.length&&a.forEach((function(t){var a,c,d,p,f=!1,g=!1,v=!1,h=!1;if(null===(a=t.pageFilters)||void 0===a?void 0:a.length){var m=t.pageFilters.sort((function(e,t){return e.pageType===o.CUSTOM?1:-1})).find((function(e){switch(e.pageType){case o.ACCOUNT:if(r)return[u.ACCOUNT,u.ORDERS,u.ORDER_DETAIL,u.FAVORITE_PRODUCTS,u.ADDRESSES,u.RAFFLE_ACCOUNT].includes(r);case o.LOGIN:return r===u.LOGIN;case o.REGISTER:return r===u.REGISTER;case o.CART:return r===u.CART;case o.CATEGORY:return r===u.CATEGORY;case o.HOME:return r===u.INDEX;case o.PRODUCT:return r===u.PRODUCT;case o.PRODUCT_BRAND:return r===u.BRAND;case o.CUSTOM:return!0}}));if(null===(c=null==m?void 0:m.filters)||void 0===c?void 0:c.length)switch(m.pageType){case o.CATEGORY:case o.PRODUCT:case o.PRODUCT_BRAND:var T=null===(d=e.pageSpecificData)||void 0===d?void 0:d.id,S=m.filters[0];S.type===l.ID_LIST&&T&&(f=S.value.includes(T),h=!0);break;case o.CUSTOM:f=!0;break;default:h=!0,f=!0}else t.pageFilters.find((function(e){return e.pageType===(null==m?void 0:m.pageType)}))&&(f=!0,h=!0)}else f=!0,h=!0;if(f)if(g=!!(null===(p=t.storefrontRoutings)||void 0===p?void 0:p.find((function(e){return e.storefrontId===n&&e.storefrontRoutingId===i}))),t.dateFilter){if(t.dateFilter){var I=t.dateFilter.startDate?new Date(t.dateFilter.startDate):null,P=t.dateFilter.endDate?new Date(t.dateFilter.endDate):null,D=new Date;(I&&P&&I.getTime()<=D.getTime()&&P.getTime()>=D.getTime()||I&&!P&&I.getTime()<=D.getTime()||P&&!I&&P.getTime()>=D.getTime())&&(v=!0)}}else v=!0;f&&g&&v&&(t.isFilteredOnServerSide=h,s.push(t))})),T.init({storefrontPopups:s})},Object.defineProperty(se.prototype,"specification",{get:function(){var e,t,n=this,i=this.page;return(null==i?void 0:i.type)===u.PRODUCT?null===(e=i.specifications)||void 0===e?void 0:e.find((function(e){var t;return e.id===(null===(t=n.pageSpecificData)||void 0===t?void 0:t.id)})):null===(t=null==i?void 0:i.specifications)||void 0===t?void 0:t.find((function(e){var t;return e.id===(null===(t=n.pageSpecificData)||void 0===t?void 0:t.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(se.prototype,"pageComponents",{get:function(){var e;return this.specification?this.specification.components:(null===(e=this.page)||void 0===e?void 0:e.components)||[]},enumerable:!1,configurable:!0}),Object.defineProperty(se.prototype,"$pageComponentPropValues",{get:function(){return this.pageComponentPropValues},enumerable:!1,configurable:!0}),se.prototype.getMerchantSettings=function(){return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.merchantSettings?[2,this.merchantSettings]:[4,q({})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.merchantSettings=e.data),[2]}}))}))},se.prototype.getPageData=function(){return e(this,void 0,void 0,(function(){var e,n=this;return t(this,(function(t){switch(t.label){case 0:return this.pageSpecificData?[3,2]:[4,this.getPageSpecificData()];case 1:t.sent(),t.label=2;case 2:return this.page?[4,this.getMerchantSettings()]:[2];case 3:return t.sent(),e=this,[4,Promise.all(this.pageComponents.map((function(e){return n.getPageComponentPropValues(e)})))];case 4:return e.pageComponentPropValues=t.sent(),[4,this.setLinkSlugs()];case 5:return t.sent(),[4,this.getProductReviewSummary()];case 6:return t.sent(),[2]}}))}))},se.prototype.getProductReviewSummary=function(){var n,i,r;return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.pageType!==u.PRODUCT?[3,2]:[4,J({productId:{eq:null===(n=this.pageSpecificData)||void 0===n?void 0:n.id}})];case 1:(e=t.sent()).isSuccess&&(null===(r=null===(i=e.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.length)&&(this.productReviewSummary=e.data.data[0]),t.label=2;case 2:return[2]}}))}))},se.prototype.getPageSpecificData=function(){var i,r,a,s;return e(this,void 0,void 0,(function(){var o,l,m,P,D,O,C,R,b,y,L=this;return t(this,(function(E){switch(E.label){case 0:return this.pageType&&![u.BRAND,u.PRODUCT,u.CATEGORY,u.BLOG,u.BLOG_CATEGORY,u.RAFFLE_DETAIL].includes(this.pageType)?[2]:(o=this.pageParams.slug)?(l=[],(null===(i=this.possiblePageTypes)||void 0===i?void 0:i.includes(u.BLOG))||(null===(r=this.possiblePageTypes)||void 0===r?void 0:r.includes(u.BLOG_CATEGORY))?[4,ie({slug:{eq:o}})]:[3,2]):[2];case 1:return m=E.sent(),(l=(null===(a=m.data)||void 0===a?void 0:a.data)||[]).length?[3,6]:[2];case 2:return(null===(s=this.possiblePageTypes)||void 0===s?void 0:s.includes(u.RAFFLE_DETAIL))?[4,ne({slug:{eq:o}})]:[3,4];case 3:return m=E.sent(),(l=m.data||[]).length?[3,6]:[2];case 4:return[4,te({slug:{eq:o}})];case 5:if(m=E.sent(),!(l=m.data||[])||!l.length)return[2];E.label=6;case 6:if(!(P=l[0]).targetId)return[2];switch(D=function(){return e(L,void 0,void 0,(function(){var i,r,a,s,o,l,f,g,v,h,m,D,O,C,R,b,y,L,E,A,w,F,G,V,U,_,j,N,B,M,k,x,Y,q,J,Q,$,W,Z,ee,te,ne,ie=this;return t(this,(function(re){switch(re.label){case 0:return[4,H({input:{productIdList:[P.targetId],priceListId:T.getPriceListId(),salesChannelId:T.getSalesChannelId()}})];case 1:return i=re.sent(),(null===(k=null===(M=null==i?void 0:i.data)||void 0===M?void 0:M.data)||void 0===k?void 0:k.length)?(r=T.getCurrentRouting(),a=T.getRoutings(),s=a.find((function(e){return null===e.path})),o=null==r?void 0:r.locale,(l=i.data.data[0]).productOptionSetId?[4,z({id:{eq:l.productOptionSetId}})]:[3,3]):[2];case 2:(f=re.sent()).isSuccess&&(null===(x=null==f?void 0:f.data)||void 0===x?void 0:x.length)&&(l.productOptionSet=f.data[0]),re.label=3;case 3:return((null===(Y=T.getDomain())||void 0===Y?void 0:Y.includes("thepurestsolutions"))||(null===(q=process.env.NEXT_PUBLIC_GQL_URL)||void 0===q?void 0:q.includes(".dev"))&&!T.getIsEditor())&&(g=l.variants.find((function(e){return e.isActive})))?(v=!!(null===(J=g.bundleSettings)||void 0===J?void 0:J.products.length),h=[l.id],v&&(null===(Q=g.bundleSettings)||void 0===Q||Q.products.forEach((function(e){h.push(e.productId)}))),[4,X({productId:v?null:l.id,productIds:v?h:null,input:{salesChannelId:T.getSalesChannelId()||""},pagination:{page:1,limit:10}})]):[3,5];case 4:m=re.sent(),(null===($=m.data)||void 0===$?void 0:$.data)&&m.isSuccess&&(D=m.data.data,O=!!(null===(W=g.bundleSettings)||void 0===W?void 0:W.products.length),C=[l.id],O&&(null===(Z=g.bundleSettings)||void 0===Z||Z.products.forEach((function(e){C.push(e.productId)}))),l.customerReviews=n(n({data:D,count:D.length,limit:10,page:1,initialized:!0},O?{}:{productId:l.id}),O?{productIds:C}:{})),re.label=5;case 5:return(null===(ee=l.campaignOffers)||void 0===ee?void 0:ee.length)?[4,K({id:{in:l.campaignOffers.map((function(e){return e.id}))}})]:[3,8];case 6:return(R=re.sent()).isSuccess&&(null===(te=R.data)||void 0===te?void 0:te.length)?(b=R.data[0],y=[],L=[],b.offers.forEach((function(e){return y.push(e.productId)})),[4,H({input:{productIdList:y,priceListId:T.getPriceListId(),salesChannelId:T.getSalesChannelId()}})]):[3,8];case 7:(A=re.sent()).isSuccess&&A.data&&b.offers.forEach((function(e){var t,i,r=null===(i=null===(t=A.data)||void 0===t?void 0:t.data)||void 0===i?void 0:i.find((function(t){return t.id===e.productId}));if(r){var a=r.variants.filter((function(t){return I.hasStock(t)&&!(e.excludedVariantIdList||[]).some((function(e){return e===t.id}))})).map((function(t){if(!e.discountAmount)return t;var i=!1;return e.discountType===d.AMOUNT&&(i=!0),n(n({},t),{prices:t.prices.map((function(t){var r=null!==t.discountPrice?t.discountPrice:t.sellPrice,a=r,s=r-(i?e.discountAmount:r*e.discountAmount/100);return e.applicablePrice===p.SELL_PRICE&&(a=t.sellPrice,s=t.sellPrice-(i?e.discountAmount:t.sellPrice*e.discountAmount/100)),n(n({},t),{sellPrice:a,discountPrice:s})}))})}));a.length&&L.push({campaignOfferId:b.id,campaignOfferProductId:e.id,product:n(n({},r),{variants:a})})}E||(E={campaignOfferId:b.id,title:e.title,description:e.description})})),l.appliedCampaignOffer=E,l.offers=L,re.label=8;case 8:return l.productGroup?[4,H({input:{productGroupId:l.productGroup.id,productGroupKey:l.productGroup.groupKey,priceListId:T.getPriceListId(),salesChannelId:T.getSalesChannelId(),perPage:200}})]:[3,10];case 9:(w=re.sent()).isSuccess&&(null===(ne=w.data)||void 0===ne?void 0:ne.data)&&(l.productGroupItems=w.data.data.map((function(e){var t,n;return{productId:e.id,image:e.variants[0].images&&e.variants[0].images.length?e.variants[0].images[0].image:null,href:S.getProductHref(e),groupValues:null===(t=e.productGroup)||void 0===t?void 0:t.values,order:null===(n=e.productGroup)||void 0===n?void 0:n.order}}))),re.label=10;case 10:return l.attributes.length||l.variants.some((function(e){return e.attributes.some((function(e){var t;return(null===(t=e.productAttribute)||void 0===t?void 0:t.type)===c.PRODUCT}))}))?(F=l,[4,this.setProductAttributes(l)]):[3,13];case 11:return F.attributes=re.sent(),[4,Promise.all(l.variants.map((function(n){return e(ie,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return e=n,[4,this.setProductAttributes(n)];case 1:return e.attributes=t.sent(),[2]}}))}))})))];case 12:re.sent(),re.label=13;case 13:return(G=l.variants.find((function(e){return e.isActive})))?(l.selectedVariantValues=G.variantValues,V=S.getDisplayedVariantTypes,this.pageSpecificData=l,(U=V(this.pageSpecificData,l.selectedVariantValues)).length&&(_=U[0]).displayedVariantValues.length&&(j=_.displayedVariantValues.find((function(e){return e.hasStock})))&&(this.pageSpecificData.selectedVariantValues=j.variant.variantValues),this.pageType=u.PRODUCT,N=P,s&&(s.locale,null==r||r.locale),N&&(null==N?void 0:N.translations)&&(B=null==N?void 0:N.translations.find((function(e){return e.locale===o})),N.pageTitle=(null==B?void 0:B.pageTitle)||null,N.description=(null==B?void 0:B.description)||null),this.setPageMetaData(N),[2]):[2]}}))}))},O=function(){return e(L,void 0,void 0,(function(){var e,n,i,r,a,s,o,l,c,d,p;return t(this,(function(t){switch(t.label){case 0:return[4,Q({id:{eq:P.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(p=null===(d=e.data)||void 0===d?void 0:d.data)||void 0===p?void 0:p.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=u.BRAND,i=P,r=T.getRoutings(),a=r.find((function(e){return null===e.path})),s=T.getCurrentRouting(),o=null==s?void 0:s.locale,l=a&&a.locale===(null==s?void 0:s.locale),i&&(null==i?void 0:i.translations)&&!l&&(c=null==i?void 0:i.translations.find((function(e){return e.locale===o})),i.pageTitle=(null==c?void 0:c.pageTitle)||null,i.description=(null==c?void 0:c.description)||null),this.setPageMetaData(i),[2]):[2]}}))}))},C=function(){return e(L,void 0,void 0,(function(){var e,n,i,r,a,s,o,l,c,d,p,g,v,h,m;return t(this,(function(t){switch(t.label){case 0:return[4,$({id:{eq:P.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(v=null===(g=e.data)||void 0===g?void 0:g.data)||void 0===v?void 0:v.length)?(n=e.data.data[0]).conditions&&(i=n.conditions.find((function(e){return e.conditionType===f.PRODUCT_BRAND})))?[4,Q({id:{eq:i.valueList[0]}})]:[3,3]:[2];case 2:(r=t.sent()).isSuccess&&(null===(m=null===(h=r.data)||void 0===h?void 0:h.data)||void 0===m?void 0:m.length)&&(n.conditionValues={brand:r.data.data[0]}),t.label=3;case 3:return this.pageSpecificData=n,this.pageType=u.CATEGORY,a=P,s=T.getRoutings(),o=s.find((function(e){return null===e.path})),l=T.getCurrentRouting(),c=null==l?void 0:l.locale,d=o&&o.locale===(null==l?void 0:l.locale),a&&(null==a?void 0:a.translations)&&!d&&(p=null==a?void 0:a.translations.find((function(e){return e.locale===c})),a.pageTitle=(null==p?void 0:p.pageTitle)||null,a.description=(null==p?void 0:p.description)||null),this.setPageMetaData(a),[2]}}))}))},R=function(){return e(L,void 0,void 0,(function(){var e,n,i,r;return t(this,(function(t){switch(t.label){case 0:return[4,W({id:{eq:P.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(i=e.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=u.BLOG,this.setPageMetaData(P),[2]):[2]}}))}))},b=function(){return e(L,void 0,void 0,(function(){var e,n,i,r;return t(this,(function(t){switch(t.label){case 0:return[4,Z({id:{eq:P.targetId},pagination:{page:1,limit:1}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(i=e.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=u.BLOG_CATEGORY,this.setPageMetaData(P),[2]):[2]}}))}))},y=function(){return e(L,void 0,void 0,(function(){var e,n,i,r;return t(this,(function(t){switch(t.label){case 0:return[4,ee({id:{eq:P.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(i=e.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],[4,re([n])]):[2];case 2:return t.sent(),this.pageSpecificData=n,this.pageType=u.RAFFLE_DETAIL,this.setPageMetaData(P),[2]}}))}))},P.targetType){case h.BRAND:return[3,7];case h.CATEGORY:return[3,9];case h.PRODUCT:return[3,11];case v.BLOG:return[3,13];case v.BLOG_CATEGORY:return[3,15];case g.RAFFLE:return[3,17]}return[3,19];case 7:return[4,O()];case 8:return[2,E.sent()];case 9:return[4,C()];case 10:return[2,E.sent()];case 11:return[4,D()];case 12:return[2,E.sent()];case 13:return[4,R()];case 14:return[2,E.sent()];case 15:return[4,b()];case 16:return[2,E.sent()];case 17:return[4,y()];case 18:return[2,E.sent()];case 19:return[3,20];case 20:return[2]}}))}))},se.prototype.getPageComponentPropValues=function(n){return e(this,void 0,void 0,(function(){var i,r,a,s=this;return t(this,(function(o){switch(o.label){case 0:return((i=this.theme.components.find((function(e){return e.id===n.componentId}))).isHeader||i.isFooter)&&(n.propValues=i.commonPropValues||n.propValues),r={pageComponent:n,component:i,propValues:{}},a=function(i){return e(s,void 0,void 0,(function(){var e,a;return t(this,(function(t){switch(t.label){case 0:return e=r.propValues,a=i.name,[4,this.getPageComponentPropValue(n,i)];case 1:return e[a]=t.sent(),[2]}}))}))},[4,Promise.all(i.props.map(a))];case 1:return o.sent(),[2,r]}}))}))},se.prototype.getPageComponentPropValue=function(i,r){return e(this,void 0,void 0,(function(){var e,a,s,o,u,l,c,d,p,f,g=this;return t(this,(function(t){switch(t.label){case 0:if(a=i.propValues[r.name],s=[m.RAFFLE_LIST],null==a&&!s.includes(r.type))return[2,null];switch(r.type){case m.TEXT:return[3,1];case m.RICH_TEXT:return[3,2];case m.BOOLEAN:return[3,3];case m.IMAGE:return[3,4];case m.IMAGE_LIST:return[3,5];case m.BRAND:return[3,6];case m.BRAND_LIST:return[3,7];case m.PRODUCT_LIST:return[3,8];case m.PRODUCT_DETAIL:return[3,9];case m.PRODUCT_ATTRIBUTE:return[3,10];case m.PRODUCT_ATTRIBUTE_LIST:return[3,11];case m.CATEGORY:return[3,12];case m.CATEGORY_LIST:return[3,13];case m.LINK:case m.LIST_OF_LINK:return[3,14];case m.COLOR:return[3,15];case m.CUSTOM:return[3,16];case m.COMPONENT:case m.COMPONENT_LIST:return[3,17];case m.BLOG:return[3,19];case m.BLOG_LIST:return[3,20];case m.BLOG_CATEGORY:return[3,21];case m.BLOG_CATEGORY_LIST:return[3,22];case m.RAFFLE:return[3,23];case m.RAFFLE_LIST:return[3,24];case m.SLIDER:return[3,25];case m.VIDEO:return[3,26]}return[3,27];case 1:return e=new y(a),[3,28];case 2:return e=new U(a),[3,28];case 3:return e=new E(a),[3,28];case 4:return e=new A(a),[3,28];case 5:return e=new b(a),[3,28];case 6:return e=new C(a),[3,28];case 7:return e=new O(a),[3,28];case 8:return o=this.theme.components.find((function(e){return e.id===i.componentId})),u=[],o&&(d=o.props.find((function(e){return e.name===r.name})))&&(u=d.excludedFields||[]),e=new P(this.pageType,n(n({},a),{excludedFields:u}),this.pageSpecificData),[3,28];case 9:return e=new D(a),[3,28];case 10:return e=new N(a),[3,28];case 11:return e=new B(a),[3,28];case 12:return l=this.theme.components.find((function(e){return e.id===i.componentId})),c=[],l&&(d=l.props.find((function(e){return e.name===r.name})))&&(c=d.excludedFieldsCategory||[]),e=new w(n(n({},a),{excludedFieldsCategory:c})),[3,28];case 13:return e=new F(a),[3,28];case 14:return e=new R(a,this.theme,this.linkMetaDataTargetIds),[3,28];case 15:return e=new L(a),[3,28];case 16:return(p=this.theme.customData.find((function(e){return e.id===r.customDataId})))?(e=new G(a,p,this.theme,this.pageType,this,this.pageSpecificData,this.pageParams),[3,28]):[2];case 17:return f=a,[4,Promise.all(f.map((function(e){return g.getPageComponentPropValues(e)})))];case 18:case 29:return[2,t.sent()];case 19:return e=new _(a),[3,28];case 20:return e=new j(this.pageType,a,this.pageSpecificData),[3,28];case 21:return e=new M(a),[3,28];case 22:return e=new k(a),[3,28];case 23:return e=new x(a),[3,28];case 24:return e=new Y,[3,28];case 25:return e=new V(a),[3,28];case 26:return e=new ae(a),[3,28];case 27:return[3,28];case 28:return[4,null==e?void 0:e.getValue()]}}))}))},se.prototype.setPageMetaData=function(e){this.page&&(this.page.pageTitle=e.pageTitle||null,this.page.description=e.description||null,this.page.canonicals=e.canonicals||null,this.page.disableIndex=e.disableIndex||null)},se.prototype.setLinkSlugs=function(){return e(this,void 0,void 0,(function(){var e,n,i;return t(this,(function(t){switch(t.label){case 0:return e=[],n=[],i=[],this.linkMetaDataTargetIds.forEach((function(t){switch(t.type){case"DEFAULT":e.push(t);break;case"BLOG":n.push(t);break;case"RAFFLE":i.push(t)}})),[4,Promise.all([this.getLinkSlugs(e,"DEFAULT"),this.getLinkSlugs(n,"BLOG"),this.getLinkSlugs(i,"RAFFLE")])];case 1:return[2,t.sent()]}}))}))},se.prototype.getLinkSlugs=function(n,i){return e(this,void 0,void 0,(function(){var a,s,o=this;return t(this,(function(u){switch(u.label){case 0:return a=r(n.map((function(e){return e.id}))),s=[],a.length?[4,function(){return e(o,void 0,void 0,(function(){var e,n,r,o,u;return t(this,(function(t){switch(t.label){case 0:switch(e=[],i){case"DEFAULT":return[3,1];case"BLOG":return[3,3];case"RAFFLE":return[3,5]}return[3,7];case 1:return[4,te({targetId:{in:a}})];case 2:return n=t.sent(),e=n.data||[],[3,8];case 3:return[4,ie({targetId:{in:a}})];case 4:return r=t.sent(),e=(null===(u=r.data)||void 0===u?void 0:u.data)||[],[3,8];case 5:return[4,ne({targetId:{in:a}})];case 6:return o=t.sent(),e=o.data||[],[3,8];case 7:return[3,8];case 8:return e.length&&(s=e),[2]}}))}))}()]:[2];case 1:return u.sent(),n.forEach((function(e){var t=s.find((function(t){return t.targetId===e.id}));t&&(e.navigationLink.href+=t.slug)})),[2]}}))}))},se.prototype.getFlatCustomData=function(e){var t=this;if(!e.nestedData||!e.nestedData.length)return[e];var n=a(e.nestedData.map((function(e){return t.getFlatCustomData(e)}))),i=[];return i.push(e),i=i.concat(n)},se.prototype.setProductAttributes=function(r){return e(this,void 0,void 0,(function(){var a,s,o=this;return t(this,(function(u){switch(u.label){case 0:return a=r.attributes.filter((function(e){var t;return(null===(t=e.productAttribute)||void 0===t?void 0:t.type)===c.PRODUCT})).map((function(i){return e(o,void 0,void 0,(function(){var e,r,a,s;return t(this,(function(t){switch(t.label){case 0:return i.value?[4,H({input:{productIdList:JSON.parse(i.value),priceListId:T.getPriceListId(),salesChannelId:T.getSalesChannelId()}})]:[2,n(n({},i),{products:[]})];case 1:return e=t.sent(),null===(a=null===(r=e.data)||void 0===r?void 0:r.data)||void 0===a||a.forEach((function(e){e.selectedVariantValues=e.variants[0].variantValues})),[2,n(n({},i),{products:(null===(s=e.data)||void 0===s?void 0:s.data)||[]})]}}))}))})),[4,Promise.allSettled(a)];case 1:return s=u.sent().filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value})),[2,i(i([],r.attributes.filter((function(e){var t;return(null===(t=e.productAttribute)||void 0===t?void 0:t.type)!==c.PRODUCT})),!0),s,!0)]}}))}))},se}();export{se as IkasPageDataProvider};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikas/storefront-providers",
|
|
3
|
-
"version": "6.1.0-beta.
|
|
3
|
+
"version": "6.1.0-beta.98",
|
|
4
4
|
"description": "Data providers for ikas storefront theme components.",
|
|
5
5
|
"author": "ikas",
|
|
6
6
|
"license": "ISC",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
20
|
-
"@ikas/storefront-api": "^6.1.0-beta.
|
|
21
|
-
"@ikas/storefront-config": "^6.1.0-beta.
|
|
22
|
-
"@ikas/storefront-model-functions": "^6.1.0-beta.
|
|
23
|
-
"@ikas/storefront-models": "^6.1.0-beta.
|
|
20
|
+
"@ikas/storefront-api": "^6.1.0-beta.98",
|
|
21
|
+
"@ikas/storefront-config": "^6.1.0-beta.98",
|
|
22
|
+
"@ikas/storefront-model-functions": "^6.1.0-beta.98",
|
|
23
|
+
"@ikas/storefront-models": "^6.1.0-beta.98",
|
|
24
24
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
25
25
|
"rollup-plugin-rename-node-modules": "^1.2.0",
|
|
26
26
|
"@types/lodash": "^4.14.168",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"mobx": "^6.1.3",
|
|
41
|
-
"@ikas/storefront-api": "^6.1.0-beta.
|
|
42
|
-
"@ikas/storefront-config": "^6.1.0-beta.
|
|
43
|
-
"@ikas/storefront-model-functions": "^6.1.0-beta.
|
|
44
|
-
"@ikas/storefront-models": "^6.1.0-beta.
|
|
41
|
+
"@ikas/storefront-api": "^6.1.0-beta.98",
|
|
42
|
+
"@ikas/storefront-config": "^6.1.0-beta.98",
|
|
43
|
+
"@ikas/storefront-model-functions": "^6.1.0-beta.98",
|
|
44
|
+
"@ikas/storefront-models": "^6.1.0-beta.98",
|
|
45
45
|
"lodash": "^4.17.21"
|
|
46
46
|
}
|
|
47
47
|
}
|