@ikas/storefront-providers 4.0.9 → 4.0.11

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
- var n=function(){return n=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n},n.apply(this,arguments)};function t(n,t,e,r){return new(e||(e=Promise))((function(o,a){function u(n){try{c(r.next(n))}catch(n){a(n)}}function l(n){try{c(r.throw(n))}catch(n){a(n)}}function c(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(u,l)}c((r=r.apply(n,t||[])).next())}))}function e(n,t){var e,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function l(a){return function(l){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(n,u)}catch(n){a=[6,n],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}export{n as __assign,t as __awaiter,e as __generator};
1
+ var n=function(){return n=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n},n.apply(this,arguments)};function t(n,t,e,r){return new(e||(e=Promise))((function(o,a){function l(n){try{i(r.next(n))}catch(n){a(n)}}function c(n){try{i(r.throw(n))}catch(n){a(n)}}function i(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(l,c)}i((r=r.apply(n,t||[])).next())}))}function e(n,t){var e,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;l;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,r=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=l.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue}a=t.call(n,l)}catch(n){a=[6,n],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function r(n,t,e){if(e||2===arguments.length)for(var r,o=0,a=t.length;o<a;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return n.concat(r||Array.prototype.slice.call(t))}export{n as __assign,t as __awaiter,e as __generator,r as __spreadArray};
@@ -1 +1 @@
1
- import{__awaiter as e,__generator as t,__assign as n}from'./../ext/tslib/tslib.es6.js';import a from"lodash/uniq";import r from"lodash/flatten";import{makeAutoObservable as i}from"mobx";import{IkasThemeJsonPageType as s,IkasRaffleMetadataTargetType as o,IkasBlogMetaDataTargetType as u,IkasHTMLMetaDataTargetType as c,IkasThemeJsonComponentPropType as p}from"@ikas/storefront-models";import{IkasStorefrontConfig as l}from"@ikas/storefront-config";import{IkasProductFunctions as d}from"@ikas/storefront-model-functions";import{IkasProductListPropValueProvider as h}from"./prop-value/product-list.js";import{IkasProductPropValueProvider as f}from"./prop-value/product-detail.js";import{IkasBrandListPropValueProvider as g}from"./prop-value/brand-list.js";import{IkasBrandPropValueProvider as v}from"./prop-value/brand.js";import{IkasLinkPropValueProvider as m}from"./prop-value/link.js";import{IkasImageListPropValueProvider as T}from"./prop-value/image-list.js";import{IkasTextPropValueProvider as D}from"./prop-value/text.js";import{IkasColorPropValueProvider as S}from"./prop-value/color.js";import{IkasBooleanPropValueProvider as y}from"./prop-value/boolean.js";import{IkasImagePropValueProvider as L}from"./prop-value/image.js";import{IkasCategoryPropValueProvider as O}from"./prop-value/category.js";import{IkasCategoryListPropValueProvider as P}from"./prop-value/category-list.js";import{IkasCustomPropValueProvider as b}from"./prop-value/custom.js";import{IkasSliderPropValueProvider as I}from"./prop-value/slider.js";import{IkasRichTextPropValueProvider as C}from"./prop-value/rich-text.js";import{IkasBlogPropValueProvider as w}from"./prop-value/blog.js";import{IkasBlogListPropValueProvider as R}from"./prop-value/blog-list.js";import{IkasAttributePropValueProvider as E}from"./prop-value/attribute.js";import{IkasAttributeListPropValueProvider as A}from"./prop-value/attribute-list.js";import{IkasBlogCategoryPropValueProvider as V}from"./prop-value/blog-category.js";import{IkasBlogCategoryListPropValueProvider as j}from"./prop-value/blog-category-list.js";import{IkasRafflePropValueProvider as G}from"./prop-value/raffle.js";import{IkasRaffleListPropValueProvider as F}from"./prop-value/raffle-list.js";import{listMerchantSettings as _,listCustomerReviewSummary as B,listProductOptionSet as M,searchProducts as k,listProductBrand as U,listCategory as N,listBlog as q,listBlogCategory as Y,listStorefrontRaffle as x,listHTMLMetaData as J,listRaffleMetaData as K,listBlogMetaData as X}from"@ikas/storefront-api";import{populateRaffleProducts as H}from"./helpers/raffle.js";var $=function(){function $(e,t,n){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,i(this)}return Object.defineProperty($.prototype,"page",{get:function(){var e=this;if(this.pageType===s.CUSTOM){var t=this.pageParams.slug;return this.theme.pages.find((function(e){return e.type===s.CUSTOM&&e.slug===t}))}return this.theme.pages.find((function(t){return t.type===e.pageType}))},enumerable:!1,configurable:!0}),Object.defineProperty($.prototype,"nextPageData",{get:function(){var e,t,a,i,o,u=this,c=[],p=[],d=[];return this.pageComponentPropValues.forEach((function(e){if(d.push({pageComponent:{id:e.pageComponent.id,componentId:e.pageComponent.componentId},propValues:e.propValues}),!c.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,c.push(t)}})),c.forEach((function(e){var t=e.props.map((function(e){return e.customDataId})).filter((function(e){return!!e}));p.push.apply(p,u.theme.customData.filter((function(e){return t.includes(e.id)})))})),r(p.map((function(e){return u.getFlatCustomData(e)}))).map((function(e){return e.customDataId})).filter((function(e){return!!e})).forEach((function(e){if(!p.find((function(t){return t.id===e}))){var t=u.theme.customData.find((function(t){return t.id===e}));t&&p.push(t)}})),{props:JSON.parse(JSON.stringify({propValues:d,themeJsonComponents:c,customDataList:p,pageSpecificData:this.pageSpecificData||null,pageType:(null===(e=this.page)||void 0===e?void 0:e.type)||s.CUSTOM,pageTitle:(null===(t=this.page)||void 0===t?void 0:t.pageTitle)||null,pageDescription:(null===(a=this.page)||void 0===a?void 0:a.description)||null,canonicals:(null===(i=this.page)||void 0===i?void 0:i.canonicals)||null,disableIndex:(null===(o=this.page)||void 0===o?void 0:o.disableIndex)||null,themeSettings:this.theme.settings||{},productReviewSummary:this.productReviewSummary,configJson:l.toJSON()}))}},enumerable:!1,configurable:!0}),Object.defineProperty($.prototype,"specification",{get:function(){var e,t,n=this,a=this.page;return(null==a?void 0:a.type)===s.PRODUCT?null===(e=a.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==a?void 0:a.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($.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($.prototype,"$pageComponentPropValues",{get:function(){return this.pageComponentPropValues},enumerable:!1,configurable:!0}),$.prototype.getMerchantSettings=function(){return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,_({})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.merchantSettings=e.data),[2]}}))}))},$.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]}}))}))},$.prototype.getProductReviewSummary=function(){var n,a,r;return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.pageType!==s.PRODUCT?[3,2]:[4,B({productId:{eq:null===(n=this.pageSpecificData)||void 0===n?void 0:n.id}})];case 1:(e=t.sent()).isSuccess&&(null===(r=null===(a=e.data)||void 0===a?void 0:a.data)||void 0===r?void 0:r.length)&&(this.productReviewSummary=e.data.data[0]),t.label=2;case 2:return[2]}}))}))},$.prototype.getPageSpecificData=function(){var n,a,r,i;return e(this,void 0,void 0,(function(){var p,h,f,g,v,m,T,D,S,y,L=this;return t(this,(function(O){switch(O.label){case 0:return this.pageType&&![s.BRAND,s.PRODUCT,s.CATEGORY,s.BLOG,s.BLOG_CATEGORY,s.RAFFLE_DETAIL].includes(this.pageType)?[2]:(p=this.pageParams.slug)?(h=[],(null===(n=this.possiblePageTypes)||void 0===n?void 0:n.includes(s.BLOG))||(null===(a=this.possiblePageTypes)||void 0===a?void 0:a.includes(s.BLOG_CATEGORY))?[4,X({slug:{eq:p}})]:[3,2]):[2];case 1:return f=O.sent(),(h=(null===(r=f.data)||void 0===r?void 0:r.data)||[]).length?[3,6]:[2];case 2:return(null===(i=this.possiblePageTypes)||void 0===i?void 0:i.includes(s.RAFFLE_DETAIL))?[4,K({slug:{eq:p}})]:[3,4];case 3:return f=O.sent(),(h=f.data||[]).length?[3,6]:[2];case 4:return[4,J({slug:{eq:p}})];case 5:if(f=O.sent(),!(h=f.data||[])||!h.length)return[2];O.label=6;case 6:if(!(g=h[0]).targetId)return[2];switch(v=function(){return e(L,void 0,void 0,(function(){var e,n,a,r,i,o,u,c,p,h,f;return t(this,(function(t){switch(t.label){case 0:return[4,k({input:{productIdList:[g.targetId],priceListId:l.getPriceListId(),salesChannelId:l.getSalesChannelId(),locale:l.getCurrentLocale()}})];case 1:return e=t.sent(),(null===(h=null===(p=null==e?void 0:e.data)||void 0===p?void 0:p.data)||void 0===h?void 0:h.length)?(n=e.data.data[0]).productOptionSetId?[4,M({id:{eq:n.productOptionSetId}})]:[3,3]:[2];case 2:(a=t.sent()).isSuccess&&(null===(f=null==a?void 0:a.data)||void 0===f?void 0:f.length)&&(n.productOptionSet=a.data[0]),t.label=3;case 3:return(r=n.variants.find((function(e){return e.isActive})))?(n.selectedVariantValues=r.variantValues,i=d.getDisplayedVariantTypes,this.pageSpecificData=n,(o=i(this.pageSpecificData,n.selectedVariantValues)).length&&(u=o[0]).displayedVariantValues.length&&(c=u.displayedVariantValues.find((function(e){return e.hasStock})))&&(this.pageSpecificData.selectedVariantValues=c.variant.variantValues),this.pageType=s.PRODUCT,this.setPageMetaData(g),[2]):[2]}}))}))},m=function(){return e(L,void 0,void 0,(function(){var e,n,a,r;return t(this,(function(t){switch(t.label){case 0:return[4,U({id:{eq:g.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(a=e.data)||void 0===a?void 0:a.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=s.BRAND,this.setPageMetaData(g),[2]):[2]}}))}))},T=function(){return e(L,void 0,void 0,(function(){var e,n,a,r;return t(this,(function(t){switch(t.label){case 0:return[4,N({id:{eq:g.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(a=e.data)||void 0===a?void 0:a.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=s.CATEGORY,this.setPageMetaData(g),[2]):[2]}}))}))},D=function(){return e(L,void 0,void 0,(function(){var e,n,a,r;return t(this,(function(t){switch(t.label){case 0:return[4,q({id:{eq:g.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(a=e.data)||void 0===a?void 0:a.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=s.BLOG,this.setPageMetaData(g),[2]):[2]}}))}))},S=function(){return e(L,void 0,void 0,(function(){var e,n,a,r;return t(this,(function(t){switch(t.label){case 0:return[4,Y({id:{eq:g.targetId},pagination:{page:1,limit:1}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(a=e.data)||void 0===a?void 0:a.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],this.pageSpecificData=n,this.pageType=s.BLOG_CATEGORY,this.setPageMetaData(g),[2]):[2]}}))}))},y=function(){return e(L,void 0,void 0,(function(){var e,n,a,r;return t(this,(function(t){switch(t.label){case 0:return[4,x({id:{eq:g.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(a=e.data)||void 0===a?void 0:a.data)||void 0===r?void 0:r.length)?(n=e.data.data[0],[4,H([n])]):[2];case 2:return t.sent(),this.pageSpecificData=n,this.pageType=s.RAFFLE_DETAIL,this.setPageMetaData(g),[2]}}))}))},g.targetType){case c.BRAND:return[3,7];case c.CATEGORY:return[3,9];case c.PRODUCT:return[3,11];case u.BLOG:return[3,13];case u.BLOG_CATEGORY:return[3,15];case o.RAFFLE:return[3,17]}return[3,19];case 7:return[4,m()];case 8:return[2,O.sent()];case 9:return[4,T()];case 10:return[2,O.sent()];case 11:return[4,v()];case 12:return[2,O.sent()];case 13:return[4,D()];case 14:return[2,O.sent()];case 15:return[4,S()];case 16:return[2,O.sent()];case 17:return[4,y()];case 18:return[2,O.sent()];case 19:return[3,20];case 20:return[2]}}))}))},$.prototype.getPageComponentPropValues=function(n){return e(this,void 0,void 0,(function(){var a,r,i,s=this;return t(this,(function(o){switch(o.label){case 0:return a=this.theme.components.find((function(e){return e.id===n.componentId})),r={pageComponent:n,component:a,propValues:{}},i=function(a){return e(s,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return e=r.propValues,i=a.name,[4,this.getPageComponentPropValue(n,a)];case 1:return e[i]=t.sent(),[2]}}))}))},[4,Promise.all(a.props.map(i))];case 1:return o.sent(),[2,r]}}))}))},$.prototype.getPageComponentPropValue=function(n,a){return e(this,void 0,void 0,(function(){var e,r,i,s,o,u=this;return t(this,(function(t){switch(t.label){case 0:if(r=n.propValues[a.name],i=[p.RAFFLE_LIST],null==r&&!i.includes(a.type))return[2,null];switch(a.type){case p.TEXT:return[3,1];case p.RICH_TEXT:return[3,2];case p.BOOLEAN:return[3,3];case p.IMAGE:return[3,4];case p.IMAGE_LIST:return[3,5];case p.BRAND:return[3,6];case p.BRAND_LIST:return[3,7];case p.PRODUCT_LIST:return[3,8];case p.PRODUCT_DETAIL:return[3,9];case p.PRODUCT_ATTRIBUTE:return[3,10];case p.PRODUCT_ATTRIBUTE_LIST:return[3,11];case p.CATEGORY:return[3,12];case p.CATEGORY_LIST:return[3,13];case p.LINK:case p.LIST_OF_LINK:return[3,14];case p.COLOR:return[3,15];case p.CUSTOM:return[3,16];case p.COMPONENT:case p.COMPONENT_LIST:return[3,17];case p.BLOG:return[3,19];case p.BLOG_LIST:return[3,20];case p.BLOG_CATEGORY:return[3,21];case p.BLOG_CATEGORY_LIST:return[3,22];case p.RAFFLE:return[3,23];case p.RAFFLE_LIST:return[3,24];case p.SLIDER:return[3,25]}return[3,26];case 1:return e=new D(r),[3,27];case 2:return e=new C(r),[3,27];case 3:return e=new y(r),[3,27];case 4:return e=new L(r),[3,27];case 5:return e=new T(r),[3,27];case 6:return e=new v(r),[3,27];case 7:return e=new g(r),[3,27];case 8:return e=new h(this.pageType,r,this.pageSpecificData),[3,27];case 9:return e=new f(r),[3,27];case 10:return e=new E(r),[3,27];case 11:return e=new A(r),[3,27];case 12:return e=new O(r),[3,27];case 13:return e=new P(r),[3,27];case 14:return e=new m(r,this.theme,this.linkMetaDataTargetIds),[3,27];case 15:return e=new S(r),[3,27];case 16:return(s=this.theme.customData.find((function(e){return e.id===a.customDataId})))?(e=new b(r,s,this.theme,this.pageType,this,this.pageSpecificData,this.pageParams),[3,27]):[2];case 17:return o=r,[4,Promise.all(o.map((function(e){return u.getPageComponentPropValues(e)})))];case 18:case 28:return[2,t.sent()];case 19:return e=new w(r),[3,27];case 20:return e=new R(this.pageType,r,this.pageSpecificData),[3,27];case 21:return e=new V(r),[3,27];case 22:return e=new j(r),[3,27];case 23:return e=new G(r),[3,27];case 24:return e=new F,[3,27];case 25:return e=new I(r),[3,27];case 26:return[3,27];case 27:return[4,null==e?void 0:e.getValue()]}}))}))},$.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)},$.prototype.setLinkSlugs=function(){return e(this,void 0,void 0,(function(){var e,n,a;return t(this,(function(t){switch(t.label){case 0:return e=[],n=[],a=[],this.linkMetaDataTargetIds.forEach((function(t){switch(t.type){case"DEFAULT":e.push(t);break;case"BLOG":n.push(t);break;case"RAFFLE":a.push(t)}})),[4,Promise.all([this.getLinkSlugs(e,"DEFAULT"),this.getLinkSlugs(n,"BLOG"),this.getLinkSlugs(a,"RAFFLE")])];case 1:return[2,t.sent()]}}))}))},$.prototype.getLinkSlugs=function(n,r){return e(this,void 0,void 0,(function(){var i,s,o=this;return t(this,(function(u){switch(u.label){case 0:return i=a(n.map((function(e){return e.id}))),s=[],i.length?[4,function(){return e(o,void 0,void 0,(function(){var e,n,a,o,u;return t(this,(function(t){switch(t.label){case 0:switch(e=[],r){case"DEFAULT":return[3,1];case"BLOG":return[3,3];case"RAFFLE":return[3,5]}return[3,7];case 1:return[4,J({targetId:{in:i}})];case 2:return n=t.sent(),e=n.data||[],[3,8];case 3:return[4,X({targetId:{in:i}})];case 4:return a=t.sent(),e=(null===(u=a.data)||void 0===u?void 0:u.data)||[],[3,8];case 5:return[4,K({targetId:{in:i}})];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]}}))}))},$.prototype.getFlatCustomData=function(e){var t=this;if(!e.nestedData||!e.nestedData.length)return[e];var n=r(e.nestedData.map((function(e){return t.getFlatCustomData(e)}))),a=[];return a.push(e),a=a.concat(n)},$}();export{$ as IkasPageDataProvider};
1
+ import{__awaiter as e,__generator as t,__assign as a,__spreadArray as n}from'./../ext/tslib/tslib.es6.js';import r from"lodash/uniq";import i from"lodash/flatten";import{makeAutoObservable as s}from"mobx";import{IkasThemeJsonPageType as o,IkasRaffleMetadataTargetType as u,IkasBlogMetaDataTargetType as c,IkasHTMLMetaDataTargetType as p,IkasThemeJsonComponentPropType as l}from"@ikas/storefront-models";import{IkasStorefrontConfig as d}from"@ikas/storefront-config";import{IkasProductFunctions as f}from"@ikas/storefront-model-functions";import{IkasProductListPropValueProvider as h}from"./prop-value/product-list.js";import{IkasProductPropValueProvider as g}from"./prop-value/product-detail.js";import{IkasBrandListPropValueProvider as v}from"./prop-value/brand-list.js";import{IkasBrandPropValueProvider as m}from"./prop-value/brand.js";import{IkasLinkPropValueProvider as T}from"./prop-value/link.js";import{IkasImageListPropValueProvider as D}from"./prop-value/image-list.js";import{IkasTextPropValueProvider as S}from"./prop-value/text.js";import{IkasColorPropValueProvider as y}from"./prop-value/color.js";import{IkasBooleanPropValueProvider as L}from"./prop-value/boolean.js";import{IkasImagePropValueProvider as I}from"./prop-value/image.js";import{IkasCategoryPropValueProvider as O}from"./prop-value/category.js";import{IkasCategoryListPropValueProvider as P}from"./prop-value/category-list.js";import{IkasCustomPropValueProvider as b}from"./prop-value/custom.js";import{IkasSliderPropValueProvider as C}from"./prop-value/slider.js";import{IkasRichTextPropValueProvider as w}from"./prop-value/rich-text.js";import{IkasBlogPropValueProvider as R}from"./prop-value/blog.js";import{IkasBlogListPropValueProvider as E}from"./prop-value/blog-list.js";import{IkasAttributePropValueProvider as A}from"./prop-value/attribute.js";import{IkasAttributeListPropValueProvider as V}from"./prop-value/attribute-list.js";import{IkasBlogCategoryPropValueProvider as j}from"./prop-value/blog-category.js";import{IkasBlogCategoryListPropValueProvider as F}from"./prop-value/blog-category-list.js";import{IkasRafflePropValueProvider as G}from"./prop-value/raffle.js";import{IkasRaffleListPropValueProvider as _}from"./prop-value/raffle-list.js";import{listMerchantSettings as B,listCustomerReviewSummary as M,listProductOptionSet as k,searchProducts as U,listProductBrand as N,listCategory as q,listBlog as Y,listBlogCategory as x,listStorefrontRaffle as J,listHTMLMetaData as K,listRaffleMetaData as X,listBlogMetaData as H}from"@ikas/storefront-api";import{populateRaffleProducts as $}from"./helpers/raffle.js";var z=function(){function z(e,t,a){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=a,s(this)}return Object.defineProperty(z.prototype,"page",{get:function(){var e=this;if(this.pageType===o.CUSTOM){var t=this.pageParams.slug;return this.theme.pages.find((function(e){return e.type===o.CUSTOM&&e.slug===t}))}return this.theme.pages.find((function(t){return t.type===e.pageType}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"nextPageData",{get:function(){var e,t,r,s,u,c=this,p=[],l=[],f=[];this.pageComponentPropValues.forEach((function(e){if(f.push({pageComponent:{id:e.pageComponent.id,componentId:e.pageComponent.componentId},propValues:e.propValues}),!p.find((function(t){return t.id===e.component.id}))){var t=a({},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,p.push(t)}})),p.forEach((function(e){var t=e.props.map((function(e){return e.customDataId})).filter((function(e){return!!e}));l.push.apply(l,c.theme.customData.filter((function(e){return t.includes(e.id)})))}));var h=i(l.map((function(e){return c.getFlatCustomData(e)}))),g=function(e){var t=function(e){var t=c.getFlatCustomData(e).map((function(e){return e.customDataId})).filter((function(e){return!!e}));g(e.customDataId?n([e.customDataId],t,!0):t)};e.forEach((function(e){var a=l.find((function(t){return t.id===e}));if(a)t(a);else{var n=c.theme.customData.find((function(t){return t.id===e}));n&&(l.push(n),t(n))}}))},v=h.map((function(e){return e.customDataId})).filter((function(e){return!!e}));return g(v),{props:JSON.parse(JSON.stringify({propValues:f,themeJsonComponents:p,customDataList:l,pageSpecificData:this.pageSpecificData||null,pageType:(null===(e=this.page)||void 0===e?void 0:e.type)||o.CUSTOM,pageTitle:(null===(t=this.page)||void 0===t?void 0:t.pageTitle)||null,pageDescription:(null===(r=this.page)||void 0===r?void 0:r.description)||null,canonicals:(null===(s=this.page)||void 0===s?void 0:s.canonicals)||null,disableIndex:(null===(u=this.page)||void 0===u?void 0:u.disableIndex)||null,themeSettings:this.theme.settings||{},productReviewSummary:this.productReviewSummary,configJson:d.toJSON()}))}},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"specification",{get:function(){var e,t,a=this,n=this.page;return(null==n?void 0:n.type)===o.PRODUCT?null===(e=n.specifications)||void 0===e?void 0:e.find((function(e){var t;return e.id===(null===(t=a.pageSpecificData)||void 0===t?void 0:t.id)})):null===(t=null==n?void 0:n.specifications)||void 0===t?void 0:t.find((function(e){var t;return e.id===(null===(t=a.pageSpecificData)||void 0===t?void 0:t.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.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(z.prototype,"$pageComponentPropValues",{get:function(){return this.pageComponentPropValues},enumerable:!1,configurable:!0}),z.prototype.getMerchantSettings=function(){return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,B({})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.merchantSettings=e.data),[2]}}))}))},z.prototype.getPageData=function(){return e(this,void 0,void 0,(function(){var e,a=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 a.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]}}))}))},z.prototype.getProductReviewSummary=function(){var a,n,r;return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.pageType!==o.PRODUCT?[3,2]:[4,M({productId:{eq:null===(a=this.pageSpecificData)||void 0===a?void 0:a.id}})];case 1:(e=t.sent()).isSuccess&&(null===(r=null===(n=e.data)||void 0===n?void 0:n.data)||void 0===r?void 0:r.length)&&(this.productReviewSummary=e.data.data[0]),t.label=2;case 2:return[2]}}))}))},z.prototype.getPageSpecificData=function(){var a,n,r,i;return e(this,void 0,void 0,(function(){var s,l,h,g,v,m,T,D,S,y,L=this;return t(this,(function(I){switch(I.label){case 0:return this.pageType&&![o.BRAND,o.PRODUCT,o.CATEGORY,o.BLOG,o.BLOG_CATEGORY,o.RAFFLE_DETAIL].includes(this.pageType)?[2]:(s=this.pageParams.slug)?(l=[],(null===(a=this.possiblePageTypes)||void 0===a?void 0:a.includes(o.BLOG))||(null===(n=this.possiblePageTypes)||void 0===n?void 0:n.includes(o.BLOG_CATEGORY))?[4,H({slug:{eq:s}})]:[3,2]):[2];case 1:return h=I.sent(),(l=(null===(r=h.data)||void 0===r?void 0:r.data)||[]).length?[3,6]:[2];case 2:return(null===(i=this.possiblePageTypes)||void 0===i?void 0:i.includes(o.RAFFLE_DETAIL))?[4,X({slug:{eq:s}})]:[3,4];case 3:return h=I.sent(),(l=h.data||[]).length?[3,6]:[2];case 4:return[4,K({slug:{eq:s}})];case 5:if(h=I.sent(),!(l=h.data||[])||!l.length)return[2];I.label=6;case 6:if(!(g=l[0]).targetId)return[2];switch(v=function(){return e(L,void 0,void 0,(function(){var e,a,n,r,i,s,u,c,p,l,h;return t(this,(function(t){switch(t.label){case 0:return[4,U({input:{productIdList:[g.targetId],priceListId:d.getPriceListId(),salesChannelId:d.getSalesChannelId(),locale:d.getCurrentLocale()}})];case 1:return e=t.sent(),(null===(l=null===(p=null==e?void 0:e.data)||void 0===p?void 0:p.data)||void 0===l?void 0:l.length)?(a=e.data.data[0]).productOptionSetId?[4,k({id:{eq:a.productOptionSetId}})]:[3,3]:[2];case 2:(n=t.sent()).isSuccess&&(null===(h=null==n?void 0:n.data)||void 0===h?void 0:h.length)&&(a.productOptionSet=n.data[0]),t.label=3;case 3:return(r=a.variants.find((function(e){return e.isActive})))?(a.selectedVariantValues=r.variantValues,i=f.getDisplayedVariantTypes,this.pageSpecificData=a,(s=i(this.pageSpecificData,a.selectedVariantValues)).length&&(u=s[0]).displayedVariantValues.length&&(c=u.displayedVariantValues.find((function(e){return e.hasStock})))&&(this.pageSpecificData.selectedVariantValues=c.variant.variantValues),this.pageType=o.PRODUCT,this.setPageMetaData(g),[2]):[2]}}))}))},m=function(){return e(L,void 0,void 0,(function(){var e,a,n,r;return t(this,(function(t){switch(t.label){case 0:return[4,N({id:{eq:g.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(n=e.data)||void 0===n?void 0:n.data)||void 0===r?void 0:r.length)?(a=e.data.data[0],this.pageSpecificData=a,this.pageType=o.BRAND,this.setPageMetaData(g),[2]):[2]}}))}))},T=function(){return e(L,void 0,void 0,(function(){var e,a,n,r;return t(this,(function(t){switch(t.label){case 0:return[4,q({id:{eq:g.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(n=e.data)||void 0===n?void 0:n.data)||void 0===r?void 0:r.length)?(a=e.data.data[0],this.pageSpecificData=a,this.pageType=o.CATEGORY,this.setPageMetaData(g),[2]):[2]}}))}))},D=function(){return e(L,void 0,void 0,(function(){var e,a,n,r;return t(this,(function(t){switch(t.label){case 0:return[4,Y({id:{eq:g.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(n=e.data)||void 0===n?void 0:n.data)||void 0===r?void 0:r.length)?(a=e.data.data[0],this.pageSpecificData=a,this.pageType=o.BLOG,this.setPageMetaData(g),[2]):[2]}}))}))},S=function(){return e(L,void 0,void 0,(function(){var e,a,n,r;return t(this,(function(t){switch(t.label){case 0:return[4,x({id:{eq:g.targetId},pagination:{page:1,limit:1}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(n=e.data)||void 0===n?void 0:n.data)||void 0===r?void 0:r.length)?(a=e.data.data[0],this.pageSpecificData=a,this.pageType=o.BLOG_CATEGORY,this.setPageMetaData(g),[2]):[2]}}))}))},y=function(){return e(L,void 0,void 0,(function(){var e,a,n,r;return t(this,(function(t){switch(t.label){case 0:return[4,J({id:{eq:g.targetId}})];case 1:return(e=t.sent()).isSuccess&&(null===(r=null===(n=e.data)||void 0===n?void 0:n.data)||void 0===r?void 0:r.length)?(a=e.data.data[0],[4,$([a])]):[2];case 2:return t.sent(),this.pageSpecificData=a,this.pageType=o.RAFFLE_DETAIL,this.setPageMetaData(g),[2]}}))}))},g.targetType){case p.BRAND:return[3,7];case p.CATEGORY:return[3,9];case p.PRODUCT:return[3,11];case c.BLOG:return[3,13];case c.BLOG_CATEGORY:return[3,15];case u.RAFFLE:return[3,17]}return[3,19];case 7:return[4,m()];case 8:return[2,I.sent()];case 9:return[4,T()];case 10:return[2,I.sent()];case 11:return[4,v()];case 12:return[2,I.sent()];case 13:return[4,D()];case 14:return[2,I.sent()];case 15:return[4,S()];case 16:return[2,I.sent()];case 17:return[4,y()];case 18:return[2,I.sent()];case 19:return[3,20];case 20:return[2]}}))}))},z.prototype.getPageComponentPropValues=function(a){return e(this,void 0,void 0,(function(){var n,r,i,s=this;return t(this,(function(o){switch(o.label){case 0:return n=this.theme.components.find((function(e){return e.id===a.componentId})),r={pageComponent:a,component:n,propValues:{}},i=function(n){return e(s,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return e=r.propValues,i=n.name,[4,this.getPageComponentPropValue(a,n)];case 1:return e[i]=t.sent(),[2]}}))}))},[4,Promise.all(n.props.map(i))];case 1:return o.sent(),[2,r]}}))}))},z.prototype.getPageComponentPropValue=function(a,n){return e(this,void 0,void 0,(function(){var e,r,i,s,o,u=this;return t(this,(function(t){switch(t.label){case 0:if(r=a.propValues[n.name],i=[l.RAFFLE_LIST],null==r&&!i.includes(n.type))return[2,null];switch(n.type){case l.TEXT:return[3,1];case l.RICH_TEXT:return[3,2];case l.BOOLEAN:return[3,3];case l.IMAGE:return[3,4];case l.IMAGE_LIST:return[3,5];case l.BRAND:return[3,6];case l.BRAND_LIST:return[3,7];case l.PRODUCT_LIST:return[3,8];case l.PRODUCT_DETAIL:return[3,9];case l.PRODUCT_ATTRIBUTE:return[3,10];case l.PRODUCT_ATTRIBUTE_LIST:return[3,11];case l.CATEGORY:return[3,12];case l.CATEGORY_LIST:return[3,13];case l.LINK:case l.LIST_OF_LINK:return[3,14];case l.COLOR:return[3,15];case l.CUSTOM:return[3,16];case l.COMPONENT:case l.COMPONENT_LIST:return[3,17];case l.BLOG:return[3,19];case l.BLOG_LIST:return[3,20];case l.BLOG_CATEGORY:return[3,21];case l.BLOG_CATEGORY_LIST:return[3,22];case l.RAFFLE:return[3,23];case l.RAFFLE_LIST:return[3,24];case l.SLIDER:return[3,25]}return[3,26];case 1:return e=new S(r),[3,27];case 2:return e=new w(r),[3,27];case 3:return e=new L(r),[3,27];case 4:return e=new I(r),[3,27];case 5:return e=new D(r),[3,27];case 6:return e=new m(r),[3,27];case 7:return e=new v(r),[3,27];case 8:return e=new h(this.pageType,r,this.pageSpecificData),[3,27];case 9:return e=new g(r),[3,27];case 10:return e=new A(r),[3,27];case 11:return e=new V(r),[3,27];case 12:return e=new O(r),[3,27];case 13:return e=new P(r),[3,27];case 14:return e=new T(r,this.theme,this.linkMetaDataTargetIds),[3,27];case 15:return e=new y(r),[3,27];case 16:return(s=this.theme.customData.find((function(e){return e.id===n.customDataId})))?(e=new b(r,s,this.theme,this.pageType,this,this.pageSpecificData,this.pageParams),[3,27]):[2];case 17:return o=r,[4,Promise.all(o.map((function(e){return u.getPageComponentPropValues(e)})))];case 18:case 28:return[2,t.sent()];case 19:return e=new R(r),[3,27];case 20:return e=new E(this.pageType,r,this.pageSpecificData),[3,27];case 21:return e=new j(r),[3,27];case 22:return e=new F(r),[3,27];case 23:return e=new G(r),[3,27];case 24:return e=new _,[3,27];case 25:return e=new C(r),[3,27];case 26:return[3,27];case 27:return[4,null==e?void 0:e.getValue()]}}))}))},z.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)},z.prototype.setLinkSlugs=function(){return e(this,void 0,void 0,(function(){var e,a,n;return t(this,(function(t){switch(t.label){case 0:return e=[],a=[],n=[],this.linkMetaDataTargetIds.forEach((function(t){switch(t.type){case"DEFAULT":e.push(t);break;case"BLOG":a.push(t);break;case"RAFFLE":n.push(t)}})),[4,Promise.all([this.getLinkSlugs(e,"DEFAULT"),this.getLinkSlugs(a,"BLOG"),this.getLinkSlugs(n,"RAFFLE")])];case 1:return[2,t.sent()]}}))}))},z.prototype.getLinkSlugs=function(a,n){return e(this,void 0,void 0,(function(){var i,s,o=this;return t(this,(function(u){switch(u.label){case 0:return i=r(a.map((function(e){return e.id}))),s=[],i.length?[4,function(){return e(o,void 0,void 0,(function(){var e,a,r,o,u;return t(this,(function(t){switch(t.label){case 0:switch(e=[],n){case"DEFAULT":return[3,1];case"BLOG":return[3,3];case"RAFFLE":return[3,5]}return[3,7];case 1:return[4,K({targetId:{in:i}})];case 2:return a=t.sent(),e=a.data||[],[3,8];case 3:return[4,H({targetId:{in:i}})];case 4:return r=t.sent(),e=(null===(u=r.data)||void 0===u?void 0:u.data)||[],[3,8];case 5:return[4,X({targetId:{in:i}})];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(),a.forEach((function(e){var t=s.find((function(t){return t.targetId===e.id}));t&&(e.navigationLink.href+=t.slug)})),[2]}}))}))},z.prototype.getFlatCustomData=function(e){var t=this;if(!e.nestedData||!e.nestedData.length)return[e];var a=i(e.nestedData.map((function(e){return t.getFlatCustomData(e)}))),n=[];return n.push(e),n=n.concat(a)},z}();export{z as IkasPageDataProvider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront-providers",
3
- "version": "4.0.9",
3
+ "version": "4.0.11",
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": "^4.0.9",
21
- "@ikas/storefront-config": "^4.0.9",
22
- "@ikas/storefront-model-functions": "^4.0.9",
23
- "@ikas/storefront-models": "^4.0.9",
20
+ "@ikas/storefront-api": "^4.0.11",
21
+ "@ikas/storefront-config": "^4.0.11",
22
+ "@ikas/storefront-model-functions": "^4.0.11",
23
+ "@ikas/storefront-models": "^4.0.11",
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": "^4.0.9",
42
- "@ikas/storefront-config": "^4.0.9",
43
- "@ikas/storefront-model-functions": "^4.0.9",
44
- "@ikas/storefront-models": "^4.0.9",
41
+ "@ikas/storefront-api": "^4.0.11",
42
+ "@ikas/storefront-config": "^4.0.11",
43
+ "@ikas/storefront-model-functions": "^4.0.11",
44
+ "@ikas/storefront-models": "^4.0.11",
45
45
  "lodash": "^4.17.21"
46
46
  }
47
47
  }