@ikas/storefront-next 4.15.0-beta.8 → 4.15.0

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 n,__generator as e}from"../../../ext/tslib/tslib.es6.js";import t from"path";import{createFile as o,deleteDirContent as r}from"../../../utils/fs.js";import{IkasThemeJsonPageType as c}from"@ikas/storefront-models";import{PAGE_INFO as i,CHECKOUT_COMPONENT_ID as s}from"../pages/info.js";import{findAllByKey as a}from"../../../utils/helper.js";var u=function(){function u(){}return u.generate=function(o,c){return n(this,void 0,void 0,(function(){var n;return e(this,(function(e){switch(e.label){case 0:return[4,r(t.join(c||process.cwd(),"src","components","__generated__"))];case 1:return e.sent(),[4,u.generateAllPageComponentImportsFiles(o,c)];case 2:return(n=e.sent())?[4,u.generateAllComponentImportsFileForEditor(o,c)]:[3,4];case 3:n=e.sent(),e.label=4;case 4:return[2,n]}}))}))},u.generateAllPageComponentImportsFiles=function(t,o){return n(this,void 0,void 0,(function(){var n,r,c,s,a;return e(this,(function(e){switch(e.label){case 0:n=!0,r=0,c=i,e.label=1;case 1:return r<c.length?(s=c[r],(a=n)?[4,u.generatePageComponentImportsFileWithInfo(s,t,o)]:[3,3]):[3,5];case 2:a=e.sent(),e.label=3;case 3:n=a,e.label=4;case 4:return r++,[3,1];case 5:return[2,n]}}))}))},u.generatePageComponentImportsFileWithInfo=function(t,o,r){return n(this,void 0,void 0,(function(){var n,c,i,p;return e(this,(function(e){switch(e.label){case 0:if(t.isCheckout||t.isEditor)return[2,!0];e.label=1;case 1:return e.trys.push([1,3,,4]),n=o.components,c=[],t.pageTypes.forEach((function(e){var t=o.pages.filter((function(n){return n.type===e}));t.length&&t.forEach((function(e){var t,o=e.components;(null===(t=e.specifications)||void 0===t?void 0:t.length)&&e.specifications.forEach((function(n){o.push.apply(o,n.components)})),c.push.apply(c,o.map((function(n){return n.componentId}))),o.forEach((function(e){var t=n.find((function(n){return n.id===e.componentId}));if(t){var o=a(t.commonPropValues||e.propValues,"componentId");c.push.apply(c,o)}}))}))})),i=n.filter((function(n){return c.includes(n.id)&&n.id!==s})),[4,u.generateComponentImportsFile(i,t,r)];case 2:return[2,e.sent()];case 3:return p=e.sent(),console.error(p),[2,!1];case 4:return[2]}}))}))},u.generatePageComponentImportsFileWithType=function(n,e,t){if(n!==c.CHECKOUT){try{var o=i.find((function(e){return e.pageTypes.includes(n)}));if(o)return u.generatePageComponentImportsFileWithInfo(o,e,t)}catch(n){console.error(n)}return!1}},u.generateComponentImportsFile=function(n,e,r){try{var c="";return n.filter((function(n){return"checkout"!==n.id})).forEach((function(n,e){c+="import Component".concat(e,' from "src/components/').concat(n.dir,'";\r\n')})),c+="\n const Components = {\n ".concat(n.map((function(n,e){return'"'.concat(n.id,'": Component').concat(e)})),"\n };\n "),c+="\r\n",c+="export default Components;",o(t.join(r||process.cwd(),"src","components","__generated__","pages"),e.path.replace("tsx","ts"),c)}catch(n){return console.error(n),!1}},u.generateAllComponentImportsFileForEditor=function(r,c){return n(this,void 0,void 0,(function(){var n,i,s,a;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),n='import dynamic from "next/dynamic";\r\n',n+='import { IkasEditorComponentLoader } from "@ikas/storefront";\r\n',n+="\r\n",n+="\r\n",(i=r.components.filter((function(n){return"checkout"!==n.id}))).filter((function(n){return"checkout"!==n.id})).forEach((function(e,t){n+="const Component".concat(t,' = dynamic(() => import("../').concat(e.dir,'"), { loading: () => <IkasEditorComponentLoader /> });\r\n')})),n+="\r\n",n+="\nconst Components = {\n ".concat(i.map((function(n,e){return'"'.concat(n.id,'": Component').concat(e)})),"\n};\n"),n+="\r\n",n+="export default Components;",s=t.join(c||process.cwd(),"src","components","__generated__"),[4,o(s,"editor.tsx",n)];case 1:return[2,e.sent()];case 2:return a=e.sent(),console.error(a),[2,!1];case 3:return[2]}}))}))},u.generateAllComponentImportsFile=function(r,c){return n(this,void 0,void 0,(function(){var n,i,s,a;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),n="",(i=r.components.filter((function(n){return"checkout"!==n.id}))).filter((function(n){return"checkout"!==n.id})).forEach((function(e,t){n+="import Component".concat(t,' from "../').concat(e.dir,'";\r\n')})),n+="\r\n",n+="\nconst Components = {\n ".concat(i.map((function(n,e){return'"'.concat(n.id,'": Component').concat(e)})),"\n};\n"),n+="\r\n",n+="export default Components;",s=t.join(c||process.cwd(),"src","components","__generated__"),[4,o(s,"index.tsx",n)];case 1:return[2,e.sent()];case 2:return a=e.sent(),console.error(a),[2,!1];case 3:return[2]}}))}))},u}();export{u as ComponentImportsGenerator};
1
+ import{__awaiter as n,__generator as t}from"../../../ext/tslib/tslib.es6.js";import e from"path";import{createFile as o,deleteDirContent as r}from"../../../utils/fs.js";import{IkasThemeJsonPageType as c}from"@ikas/storefront-models";import{PAGE_INFO as i,CHECKOUT_COMPONENT_ID as s}from"../pages/info.js";import{findAllByKey as a}from"../../../utils/helper.js";import u from"lodash/uniq";var p=function(){function p(){}return p.generate=function(o,c,i){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:return[4,r(e.join(c||process.cwd(),"src","components","__generated__"))];case 1:return t.sent(),[4,p.generateAllPageComponentImportsFiles(o,c,i)];case 2:return(n=t.sent())?[4,p.generateAllComponentImportsFileForEditor(o,c)]:[3,4];case 3:n=t.sent(),t.label=4;case 4:return[2,n]}}))}))},p.generateAllPageComponentImportsFiles=function(e,o,r){return n(this,void 0,void 0,(function(){var n,c,s,a,u;return t(this,(function(t){switch(t.label){case 0:n=!0,c=0,s=i,t.label=1;case 1:return c<s.length?(a=s[c],(u=n)?[4,p.generatePageComponentImportsFileWithInfo(a,e,o,r)]:[3,3]):[3,5];case 2:u=t.sent(),t.label=3;case 3:n=u,t.label=4;case 4:return c++,[3,1];case 5:return[2,n]}}))}))},p.generatePageComponentImportsFileWithInfo=function(e,o,r,c){return n(this,void 0,void 0,(function(){var n,i,f,m;return t(this,(function(t){switch(t.label){case 0:if(e.isCheckout||e.isEditor)return[2,!0];t.label=1;case 1:return t.trys.push([1,3,,4]),n=o.components,i=[],e.pageTypes.forEach((function(t){var e=o.pages.filter((function(n){return n.type===t}));e.length&&e.forEach((function(t){var e,o=t.components;(null===(e=t.specifications)||void 0===e?void 0:e.length)&&t.specifications.forEach((function(n){o.push.apply(o,n.components)})),i.push.apply(i,o.map((function(n){return n.componentId}))),o.forEach((function(t){var e=n.find((function(n){return n.id===t.componentId}));if(e){var o=a(e.commonPropValues||t.propValues,"componentId");i.push.apply(i,o)}})),null==c||c.forEach((function(n){var t=a(n,"componentId");i.push.apply(i,t)}))}))})),i=u(i),f=n.filter((function(n){return i.includes(n.id)&&n.id!==s})),[4,p.generateComponentImportsFile(f,e,r)];case 2:return[2,t.sent()];case 3:return m=t.sent(),console.error(m),[2,!1];case 4:return[2]}}))}))},p.generatePageComponentImportsFileWithType=function(n,t,e){if(n!==c.CHECKOUT){try{var o=i.find((function(t){return t.pageTypes.includes(n)}));if(o)return p.generatePageComponentImportsFileWithInfo(o,t,e)}catch(n){console.error(n)}return!1}},p.generateComponentImportsFile=function(n,t,r){try{var c="";return n.filter((function(n){return"checkout"!==n.id})).forEach((function(n,t){c+="import Component".concat(t,' from "src/components/').concat(n.dir,'";\r\n')})),c+="\n const Components = {\n ".concat(n.map((function(n,t){return'"'.concat(n.id,'": Component').concat(t)})),"\n };\n "),c+="\r\n",c+="export default Components;",o(e.join(r||process.cwd(),"src","components","__generated__","pages"),t.path.replace("tsx","ts"),c)}catch(n){return console.error(n),!1}},p.generateAllComponentImportsFileForEditor=function(r,c){return n(this,void 0,void 0,(function(){var n,i,s,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),n='import dynamic from "next/dynamic";\r\n',n+='import { IkasEditorComponentLoader } from "@ikas/storefront";\r\n',n+="\r\n",n+="\r\n",(i=r.components.filter((function(n){return"checkout"!==n.id}))).filter((function(n){return"checkout"!==n.id})).forEach((function(t,e){n+="const Component".concat(e,' = dynamic(() => import("../').concat(t.dir,'"), { loading: () => <IkasEditorComponentLoader /> });\r\n')})),n+="\r\n",n+="\nconst Components = {\n ".concat(i.map((function(n,t){return'"'.concat(n.id,'": Component').concat(t)})),"\n};\n"),n+="\r\n",n+="export default Components;",s=e.join(c||process.cwd(),"src","components","__generated__"),[4,o(s,"editor.tsx",n)];case 1:return[2,t.sent()];case 2:return a=t.sent(),console.error(a),[2,!1];case 3:return[2]}}))}))},p.generateAllComponentImportsFile=function(r,c){return n(this,void 0,void 0,(function(){var n,i,s,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),n="",(i=r.components.filter((function(n){return"checkout"!==n.id}))).filter((function(n){return"checkout"!==n.id})).forEach((function(t,e){n+="import Component".concat(e,' from "../').concat(t.dir,'";\r\n')})),n+="\r\n",n+="\nconst Components = {\n ".concat(i.map((function(n,t){return'"'.concat(n.id,'": Component').concat(t)})),"\n};\n"),n+="\r\n",n+="export default Components;",s=e.join(c||process.cwd(),"src","components","__generated__"),[4,o(s,"index.tsx",n)];case 1:return[2,t.sent()];case 2:return a=t.sent(),console.error(a),[2,!1];case 3:return[2]}}))}))},p}();export{p as ComponentImportsGenerator};
@@ -109,4 +109,7 @@ export declare type IkasCheckoutCustomizationProps = {
109
109
  warningLightColor?: string;
110
110
  successColor?: string;
111
111
  successLightColor?: string;
112
+ secondaryButtonBgColor?: string;
113
+ secondaryButtonTextColor?: string;
114
+ secondaryButtonBorderColor?: string;
112
115
  };
@@ -1 +1 @@
1
- import{__awaiter as e,__generator as t,__spreadArray as o,__assign as n}from'./../ext/tslib/tslib.es6.js';import r from"fs";import i from"next/config.js";import{IkasThemeJsonPageType as s}from"@ikas/storefront-models";import{IkasPageDataProvider as a}from"@ikas/storefront-providers";import{IkasStorefrontConfig as c}from"@ikas/storefront-config";import{getStorefrontSettings as l,listMerchantSettings as u,setAPIClientConfig as p,listCheckoutSettings as g}from"@ikas/storefront-api";import{getGoogleFontHref as d}from"../utils/google-fonts.js";import{I18NFileReader as f}from"../utils/i18n.js";import{createFile as m,deleteDirContent as h}from"../utils/fs.js";var S=function(){function S(){}return S.readLocalTheme=function(){return new Promise((function(e,t){r.readFile("./src/theme.json",{flag:"a+"},(function(o,n){if(o)return t(o);var r=n.length?JSON.parse(n.toString()):{};e(r)}))}))},S.readSettingsFile=function(){return new Promise((function(e){var t=i().serverRuntimeConfig.SETTINGS;r.readFile(t,{flag:"a+"},(function(t,o){if(t)return console.error("SETTINGS FILE READ ERROR!!!"),console.error(t),e(null);var n=o.length?JSON.parse(o.toString()):{};e(n)}))}))},S.cacheLocalSettingsFile=function(o){return e(this,void 0,void 0,(function(){var e,n;return t(this,(function(t){switch(t.label){case 0:return[4,h(e=".ikas")];case 1:return t.sent(),n="settings-".concat(this.startTime,".json"),[4,m(e,n,JSON.stringify(o,null,2))];case 2:return t.sent(),[2]}}))}))},S.readLocalSettingsFile=function(){try{var e=r.readFileSync(".ikas/settings-".concat(this.startTime,".json"));if(e&&e.length)return JSON.parse(e.toString())}catch(e){}},S.getLocalSettings=function(o){return e(this,void 0,void 0,(function(){var e,n,r,i,s,a,c,u,p,g;return t(this,(function(t){switch(t.label){case 0:return[4,S.readLocalSettingsFile()];case 1:return(e=t.sent())?[3,4]:[4,l()];case 2:return(n=t.sent()).isSuccess&&n.data?(e=n.data,[4,this.cacheLocalSettingsFile(e)]):(console.error("Storefront settings fetch failed!"),console.error(n),[2,null]);case 3:t.sent(),t.label=4;case 4:return r=e.storefront,i=e.salesChannel,s=[],a=e.productBackInStockSettings?{customerLoginRequired:e.productBackInStockSettings.customerLoginRequired}:null,c=e.customerReviewSettings?{customerLoginRequired:e.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:e.customerReviewSettings.customerPurchaseRequired||!1}:null,[4,S.readLocalTheme()];case 5:return u=t.sent(),p=S.createColorScript(u.settings),[4,S.createFontScript(u.settings)];case 6:return g=t.sent(),p&&s.push(p),g&&s.push(g),[2,{storefront:r,themeLocalization:{id:"",locale:"en",privacyPolicy:null,returnPolicy:null,storefrontId:r.id,storefrontThemeId:"",termsOfService:null,imprint:null,shippingPolicy:null,themeJson:u},salesChannel:i,routing:r.routings.length?r.routings.find((function(e){return e.locale===o||e.id===o}))||r.routings[0]:{countryCodes:[],domain:"",dynamicCurrencySettings:{roundingFormat:null,targetCurrencyCode:""},id:"",locale:"en",path:null,priceListId:null,currencyCode:"USD",currencySymbol:"$"},favicon:u.settings.favicon,stockPreference:u.settings.stockPreference,storefrontJSScripts:s,highPriorityStoreFrontJSScripts:[],domain:"localhost:3333",productBackInStockSettings:a,customerReviewSettings:c,merchantSettings:e.merchantSettings,customerSettings:e.customerSettings}]}}))}))},S.getProdSettings=function(o){return e(this,void 0,void 0,(function(){var n=this;return t(this,(function(i){return[2,new Promise((function(i){return e(n,void 0,void 0,(function(){var n,s,a,c,l,p,g,d,f,m,h,v,C;return t(this,(function(I){switch(I.label){case 0:return[4,S.readSettingsFile()];case 1:return(n=I.sent())&&n.localizationMap?(s=n.storefront,a=n.salesChannel,c=n.localizationMap,l=n.storefrontJSScripts||[],p=n.highPriorityStoreFrontJSScripts||[],g=n.domain,d=n.productBackInStockSettings?{customerLoginRequired:n.productBackInStockSettings.customerLoginRequired}:null,f=n.customerReviewSettings?{customerLoginRequired:n.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:n.customerReviewSettings.customerPurchaseRequired||!1}:null,(m=n.merchantSettings)?[3,3]:[4,u({})]):[2,i(null)];case 2:if(!(h=I.sent()).isSuccess||!h.data)return console.error("MERCHANT SETTINGS FETCH FAILED!"),[2,i(null)];m=h.data,I.label=3;case 3:return m&&(m.address=null,delete m.merchantAddress),v=c[o],C=s.routings.find((function(e){return e.id===o||e.path===o})),v&&C?(r.readFile(v,{flag:"a+"},(function(o,r){return e(this,void 0,void 0,(function(){var e,c,u,h,v,I,y;return t(this,(function(t){switch(t.label){case 0:return o?(console.error("THEME LOCALIZATION FILE READ ERROR!!!"),console.error(o),[2,i(null)]):(e=r.length?JSON.parse(r.toString()):{},u=(c=e).themeJson.settings.favicon,h=c.themeJson.settings.stockPreference,c.themeJson.settings?(v=S.createColorScript(c.themeJson.settings),[4,S.createFontScript(c.themeJson.settings)]):[3,2]);case 1:I=t.sent(),v&&l.push(v),I&&l.push(I),t.label=2;case 2:return y=n.customerSettings,i({storefront:s,themeLocalization:c,salesChannel:a,routing:C,favicon:u,stockPreference:h,storefrontJSScripts:l,highPriorityStoreFrontJSScripts:p,domain:g,productBackInStockSettings:d,customerReviewSettings:f,merchantSettings:m,customerSettings:y,custom:n.custom}),[2]}}))}))})),[2]):(console.error("THEME LOCALIZATION PATH OR ROUTING MISSING!!!"),[2,i(null)])}}))}))}))]}))}))},S.getSettings=function(o){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return"local"===process.env.NEXT_PUBLIC_ENV?[4,this.getLocalSettings(o)]:[3,2];case 1:case 3:return[2,e.sent()];case 2:return[4,this.getProdSettings(o)]}}))}))},S.setStorefrontConfig=function(o){var n;return e(this,void 0,void 0,(function(){var e,r,i,s,a,l,u,g,d,f,m,h;return t(this,(function(t){return e=o.storefront,r=o.salesChannel,i=o.routing,s=o.favicon,a=o.stockPreference,l=o.storefrontJSScripts,u=o.domain,g=o.productBackInStockSettings,d=o.customerReviewSettings,f=o.merchantSettings,m=o.customerSettings,h=o.custom,c.init({apiUrl:process.env.NEXT_PUBLIC_GQL_URL,cdnUrl:process.env.NEXT_PUBLIC_CDN_URL,storefrontId:e.id,storefrontRoutingId:i.id,storefrontThemeId:e.mainStorefrontThemeId,storefrontB2BSettings:e.b2bSettings||void 0,storefrontType:e.type,salesChannelId:e.salesChannelId,priceListId:i.priceListId||void 0,stockLocationIds:null===(n=r.stockLocations)||void 0===n?void 0:n.map((function(e){return e.id})),routings:e.routings,paymentGateways:r.paymentGateways||[],gtmId:e.gtmId||void 0,fbpId:e.fbpId||void 0,analytics4Id:e.analytics4Id||void 0,universalAnalyticsId:e.universalAnalyticsId||void 0,tiktokPixelId:e.tiktokPixelId||void 0,favicon:s||null,pickUpStockLocationIds:e.pickUpStockLocationIds&&e.pickUpStockLocationIds.length?e.pickUpStockLocationIds:null,stockPreference:a||null,storefrontJSScripts:l||[],domain:u,productBackInStockSettings:g,customerReviewSettings:d,merchantSettings:f,customerSettings:m,metaTemplates:e.metaTemplates||null,custom:h||null,indexPageSeoSettings:e.indexPageSeoSettings}),p(),[2]}))}))},S.setTranslations=function(n,r,a,l,u){return e(this,void 0,void 0,(function(){var e,p,g,d,m,h,S,v;return t(this,(function(t){switch(t.label){case 0:return e=i().serverRuntimeConfig,p=n.routing,g="local"===process.env.NEXT_PUBLIC_ENV,d=n.themeLocalization.themeJson.components.filter((function(e){return l||r.includes(e.id)})),m=o(["common"],d.map((function(e){return e.dir})),!0),(a===s.CHECKOUT||l)&&m.push("checkout-page"),h=e.nextI18nConf,S=g&&u?u:p.locale,[4,new f(S,m,g?void 0:h.localePath).read()];case 1:return v=t.sent(),c.init({translations:v}),[2]}}))}))},S.getExtraProps=function(o,n,r){var i,a,c,l,u,p,d,f,m,h,S,v,C,I,y,L,P,T,w;return e(this,void 0,void 0,(function(){var e,k,O,b,R;return t(this,(function(t){switch(t.label){case 0:return e={},k=o.themeLocalization,r!==s.CHECKOUT?[3,2]:(O=null===(i=n.page)||void 0===i?void 0:i.components[0])?[4,g({})]:[3,2];case 1:(b=t.sent()).isSuccess||(console.error("CHECKOUT SETTINGS FETCH FAILED!"),console.error(b.graphQLErrors),console.error(b.errorCodes)),R={logo:null!==(a=O.propValues.logo)&&void 0!==a?a:null,showTax:null===(c=O.propValues.showTax)||void 0===c||c,showCampaignOffersDesign:null!==(l=O.propValues.showCampaignOffersDesign)&&void 0!==l&&l,showCampaignIsBiggerImage:null!==(u=O.propValues.showCampaignIsBiggerImage)&&void 0!==u&&u,campaignOfferIsSmallDesign:null!==(p=O.propValues.campaignOfferIsSmallDesign)&&void 0!==p&&p,showCampaignHideDiscountBadge:null!==(d=O.propValues.showCampaignHideDiscountBadge)&&void 0!==d&&d,campaignOfferCountdownStyleIsLine:null!==(f=O.propValues.campaignOfferCountdownStyleIsLine)&&void 0!==f&&f,campaignOfferCountdownStyleIsLineSuccessPage:null!==(m=O.propValues.campaignOfferCountdownStyleIsLineSuccessPage)&&void 0!==m&&m,campaignOffersEnableMiddlePhase:null!==(h=O.propValues.campaignOffersEnableMiddlePhase)&&void 0!==h&&h,campaignOffersTitleColor:null!==(S=O.propValues.campaignOffersTitleColor)&&void 0!==S?S:null,campaignOffersDescriptionColor:null!==(v=O.propValues.campaignOffersDescriptionColor)&&void 0!==v?v:null,campaignOffersDiscountPercentageColor:null!==(C=O.propValues.campaignOffersDiscountPercentageColor)&&void 0!==C?C:null,campaignOffersDiscountPercentageBgColor:null!==(I=O.propValues.campaignOffersDiscountPercentageBgColor)&&void 0!==I?I:null,campaignOffersCountdownTextColor:null!==(y=O.propValues.campaignOffersCountdownTextColor)&&void 0!==y?y:null,campaignOffersCountdownTimeColor:null!==(L=O.propValues.campaignOffersCountdownTimeColor)&&void 0!==L?L:null,campaignOffersCountdownBgColor:null!==(P=O.propValues.campaignOffersCountdownBgColor)&&void 0!==P?P:null,campaignOffersMiddlePhaseOverlayColor:null!==(T=O.propValues.campaignOffersMiddlePhaseOverlayColor)&&void 0!==T?T:null,buttonBgColor:O.propValues.buttonBgColor,buttonTextColor:O.propValues.buttonTextColor,buttonDisabledBgColor:O.propValues.buttonDisabledBgColor,buttonDisabledTextColor:O.propValues.buttonDisabledTextColor,primaryTextColor:O.propValues.primaryTextColor,secondaryTextColor:O.propValues.secondaryTextColor,primaryBgColor:O.propValues.primaryBgColor,secondaryBgColor:O.propValues.secondaryBgColor,borderColor:O.propValues.borderColor,cardBgColor:O.propValues.cardBgColor,errorColor:O.propValues.errorColor,errorLightColor:O.propValues.errorLightColor,warningColor:O.propValues.warningColor,warningLightColor:O.propValues.warningLightColor,successColor:O.propValues.successColor,successLightColor:O.propValues.successLightColor},e.customizationProps=R,e.returnPolicy=k.returnPolicy,e.privacyPolicy=k.privacyPolicy,e.termsOfService=k.termsOfService,e.imprint=k.imprint,e.shippingPolicy=k.shippingPolicy,e.checkoutSettings=(null===(w=null==b?void 0:b.data)||void 0===w?void 0:w.length)?b.data[0]:null,t.label=2;case 2:return[2,e]}}))}))},S.getPageData=function(o,r,i,s,l){var u;return e(this,void 0,void 0,(function(){var e,g,d,f,m,h,v,C;return t(this,(function(t){switch(t.label){case 0:return e="local"===process.env.NEXT_PUBLIC_ENV,g=!e&&l,c.init({apiUrl:process.env.NEXT_PUBLIC_GQL_URL,cdnUrl:process.env.NEXT_PUBLIC_CDN_URL}),p(),g?[3,7]:(d=o.locale)?[4,S.getSettings(d)]:[2,{props:{},notFound:!0}];case 1:return(f=t.sent())&&f.storefront.mainStorefrontThemeId&&f.storefront.salesChannelId?[4,this.setStorefrontConfig(f)]:[2,{props:{},notFound:!0}];case 2:return t.sent(),m=f.themeLocalization,(h=new a(m.themeJson,o.params,i,f.merchantSettings)).possiblePageTypes=s||(i?[i]:[]),l?[3,4]:[4,h.getPageData()];case 3:if(t.sent(),!h.page)return[2,{props:{},notFound:!0}];t.label=4;case 4:return v=l?h.theme.components.map((function(e){return e.id})):(null===(u=h.page)||void 0===u?void 0:u.components.map((function(e){return e.componentId})))||[],[4,this.setTranslations(f,v,i,l,d)];case 5:return t.sent(),[4,this.getExtraProps(f,h,i)];case 6:return C=t.sent(),r?[2,{props:n(n({},h.nextPageData.props),C)}]:[2,{props:n(n({},h.nextPageData.props),C),revalidate:60}];case 7:return[2,{props:{}}];case 8:return[2]}}))}))},S.getStaticProps=function(o,n,r,i){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,S.getPageData(o,!1,n,r,i)];case 1:return[2,e.sent()]}}))}))},S.getServerSideProps=function(o,n){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,S.getPageData(o,!0,n)];case 1:return[2,e.sent()]}}))}))},S.createColorScript=function(e){if(e.colors)return"<script>".concat(e.colors.map((function(e){return'document.documentElement.style.setProperty("'.concat(e.key,'","').concat(e.color,'");')})).join("\r\n"),"<\/script> \n ")},S.createFontScript=function(o){return e(this,void 0,void 0,(function(){var e,n,r;return t(this,(function(t){switch(t.label){case 0:return(e=d(o.fontFamily))?[4,fetch(e,{headers:{"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"}})]:[3,3];case 1:return[4,t.sent().text()];case 2:return n=t.sent(),r=n.replace(new RegExp("fonts.gstatic.com","g"),"fonts.myikas.com"),[2,"<style>\n ".concat(r,"\n\n body { \n font-family: '").concat(o.fontFamily.name,'\', -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;\n } \n\n </style>')];case 3:return[2]}}))}))},S.startTime=Date.now(),S}();export{S as IkasNextPageDataProvider};
1
+ import{__awaiter as e,__generator as t,__spreadArray as o,__assign as n}from'./../ext/tslib/tslib.es6.js';import r from"fs";import s from"next/config.js";import{IkasThemeJsonPageType as i}from"@ikas/storefront-models";import{IkasPageDataProvider as a}from"@ikas/storefront-providers";import{IkasStorefrontConfig as c}from"@ikas/storefront-config";import{getStorefrontSettings as l,listMerchantSettings as u,setAPIClientConfig as p,listCheckoutSettings as d}from"@ikas/storefront-api";import{getGoogleFontHref as g}from"../utils/google-fonts.js";import{I18NFileReader as f}from"../utils/i18n.js";import{createFile as m,deleteDirContent as h}from"../utils/fs.js";var S=function(){function S(){}return S.readLocalTheme=function(){return new Promise((function(e,t){r.readFile("./src/theme.json",{flag:"a+"},(function(o,n){if(o)return t(o);var r=n.length?JSON.parse(n.toString()):{};e(r)}))}))},S.readSettingsFile=function(){return new Promise((function(e){var t=s().serverRuntimeConfig.SETTINGS;r.readFile(t,{flag:"a+"},(function(t,o){if(t)return console.error("SETTINGS FILE READ ERROR!!!"),console.error(t),e(null);var n=o.length?JSON.parse(o.toString()):{};e(n)}))}))},S.cacheLocalSettingsFile=function(o){return e(this,void 0,void 0,(function(){var e,n;return t(this,(function(t){switch(t.label){case 0:return[4,h(e=".ikas")];case 1:return t.sent(),n="settings-".concat(this.startTime,".json"),[4,m(e,n,JSON.stringify(o,null,2))];case 2:return t.sent(),[2]}}))}))},S.readLocalSettingsFile=function(){try{var e=r.readFileSync(".ikas/settings-".concat(this.startTime,".json"));if(e&&e.length)return JSON.parse(e.toString())}catch(e){}},S.getLocalSettings=function(o){return e(this,void 0,void 0,(function(){var e,n,r,s,i,a,c,u,p,d;return t(this,(function(t){switch(t.label){case 0:return[4,S.readLocalSettingsFile()];case 1:return(e=t.sent())?[3,4]:[4,l()];case 2:return(n=t.sent()).isSuccess&&n.data?(e=n.data,[4,this.cacheLocalSettingsFile(e)]):(console.error("Storefront settings fetch failed!"),console.error(n),[2,null]);case 3:t.sent(),t.label=4;case 4:return r=e.storefront,s=e.salesChannel,i=[],a=e.productBackInStockSettings?{customerLoginRequired:e.productBackInStockSettings.customerLoginRequired}:null,c=e.customerReviewSettings?{customerLoginRequired:e.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:e.customerReviewSettings.customerPurchaseRequired||!1}:null,[4,S.readLocalTheme()];case 5:return u=t.sent(),p=S.createColorScript(u.settings),[4,S.createFontScript(u.settings)];case 6:return d=t.sent(),p&&i.push(p),d&&i.push(d),[2,{storefront:r,themeLocalization:{id:"",locale:"en",privacyPolicy:null,returnPolicy:null,storefrontId:r.id,storefrontThemeId:"",termsOfService:null,imprint:null,shippingPolicy:null,themeJson:u},salesChannel:s,routing:r.routings.length?r.routings.find((function(e){return e.locale===o||e.id===o}))||r.routings[0]:{countryCodes:[],domain:"",dynamicCurrencySettings:{roundingFormat:null,targetCurrencyCode:""},id:"",locale:"en",path:null,priceListId:null,currencyCode:"USD",currencySymbol:"$"},favicon:u.settings.favicon,stockPreference:u.settings.stockPreference,storefrontJSScripts:i,highPriorityStoreFrontJSScripts:[],domain:"localhost:3333",productBackInStockSettings:a,customerReviewSettings:c,merchantSettings:e.merchantSettings,customerSettings:e.customerSettings}]}}))}))},S.getProdSettings=function(o){return e(this,void 0,void 0,(function(){var n=this;return t(this,(function(s){return[2,new Promise((function(s){return e(n,void 0,void 0,(function(){var n,i,a,c,l,p,d,g,f,m,h,v,C;return t(this,(function(I){switch(I.label){case 0:return[4,S.readSettingsFile()];case 1:return(n=I.sent())&&n.localizationMap?(i=n.storefront,a=n.salesChannel,c=n.localizationMap,l=n.storefrontJSScripts||[],p=n.highPriorityStoreFrontJSScripts||[],d=n.domain,g=n.productBackInStockSettings?{customerLoginRequired:n.productBackInStockSettings.customerLoginRequired}:null,f=n.customerReviewSettings?{customerLoginRequired:n.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:n.customerReviewSettings.customerPurchaseRequired||!1}:null,(m=n.merchantSettings)?[3,3]:[4,u({})]):[2,s(null)];case 2:if(!(h=I.sent()).isSuccess||!h.data)return console.error("MERCHANT SETTINGS FETCH FAILED!"),[2,s(null)];m=h.data,I.label=3;case 3:return m&&(m.address=null,delete m.merchantAddress),v=c[o],C=i.routings.find((function(e){return e.id===o||e.path===o})),v&&C?(r.readFile(v,{flag:"a+"},(function(o,r){return e(this,void 0,void 0,(function(){var e,c,u,h,v,I,y;return t(this,(function(t){switch(t.label){case 0:return o?(console.error("THEME LOCALIZATION FILE READ ERROR!!!"),console.error(o),[2,s(null)]):(e=r.length?JSON.parse(r.toString()):{},u=(c=e).themeJson.settings.favicon,h=c.themeJson.settings.stockPreference,c.themeJson.settings?(v=S.createColorScript(c.themeJson.settings),[4,S.createFontScript(c.themeJson.settings)]):[3,2]);case 1:I=t.sent(),v&&l.push(v),I&&l.push(I),t.label=2;case 2:return y=n.customerSettings,s({storefront:i,themeLocalization:c,salesChannel:a,routing:C,favicon:u,stockPreference:h,storefrontJSScripts:l,highPriorityStoreFrontJSScripts:p,domain:d,productBackInStockSettings:g,customerReviewSettings:f,merchantSettings:m,customerSettings:y,custom:n.custom}),[2]}}))}))})),[2]):(console.error("THEME LOCALIZATION PATH OR ROUTING MISSING!!!"),[2,s(null)])}}))}))}))]}))}))},S.getSettings=function(o){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return"local"===process.env.NEXT_PUBLIC_ENV?[4,this.getLocalSettings(o)]:[3,2];case 1:case 3:return[2,e.sent()];case 2:return[4,this.getProdSettings(o)]}}))}))},S.setStorefrontConfig=function(o){var n;return e(this,void 0,void 0,(function(){var e,r,s,i,a,l,u,d,g,f,m,h;return t(this,(function(t){return e=o.storefront,r=o.salesChannel,s=o.routing,i=o.favicon,a=o.stockPreference,l=o.storefrontJSScripts,u=o.domain,d=o.productBackInStockSettings,g=o.customerReviewSettings,f=o.merchantSettings,m=o.customerSettings,h=o.custom,c.init({apiUrl:process.env.NEXT_PUBLIC_GQL_URL,cdnUrl:process.env.NEXT_PUBLIC_CDN_URL,storefrontId:e.id,storefrontRoutingId:s.id,storefrontThemeId:e.mainStorefrontThemeId,storefrontB2BSettings:e.b2bSettings||void 0,storefrontType:e.type,salesChannelId:e.salesChannelId,priceListId:s.priceListId||void 0,stockLocationIds:null===(n=r.stockLocations)||void 0===n?void 0:n.map((function(e){return e.id})),routings:e.routings,paymentGateways:r.paymentGateways||[],gtmId:e.gtmId||void 0,fbpId:e.fbpId||void 0,analytics4Id:e.analytics4Id||void 0,universalAnalyticsId:e.universalAnalyticsId||void 0,tiktokPixelId:e.tiktokPixelId||void 0,favicon:i||null,pickUpStockLocationIds:e.pickUpStockLocationIds&&e.pickUpStockLocationIds.length?e.pickUpStockLocationIds:null,stockPreference:a||null,storefrontJSScripts:l||[],domain:u,productBackInStockSettings:d,customerReviewSettings:g,merchantSettings:f,customerSettings:m,metaTemplates:e.metaTemplates||null,custom:h||null,indexPageSeoSettings:e.indexPageSeoSettings}),p(),[2]}))}))},S.setTranslations=function(n,r,a,l,u){return e(this,void 0,void 0,(function(){var e,p,d,g,m,h,S,v;return t(this,(function(t){switch(t.label){case 0:return e=s().serverRuntimeConfig,p=n.routing,d="local"===process.env.NEXT_PUBLIC_ENV,g=n.themeLocalization.themeJson.components.filter((function(e){return l||r.includes(e.id)})),m=o(["common"],g.map((function(e){return e.dir})),!0),(a===i.CHECKOUT||l)&&m.push("checkout-page"),h=e.nextI18nConf,S=d&&u?u:p.locale,[4,new f(S,m,d?void 0:h.localePath).read()];case 1:return v=t.sent(),c.init({translations:v}),[2]}}))}))},S.getExtraProps=function(o,n,r){var s,a,c,l,u,p,g,f,m,h,S,v,C,I,y,L,P,T,w,k,O,B;return e(this,void 0,void 0,(function(){var e,b,R,E,V;return t(this,(function(t){switch(t.label){case 0:return e={},b=o.themeLocalization,r!==i.CHECKOUT?[3,2]:(R=null===(s=n.page)||void 0===s?void 0:s.components[0])?[4,d({})]:[3,2];case 1:(E=t.sent()).isSuccess||(console.error("CHECKOUT SETTINGS FETCH FAILED!"),console.error(E.graphQLErrors),console.error(E.errorCodes)),V={logo:null!==(a=R.propValues.logo)&&void 0!==a?a:null,showTax:null===(c=R.propValues.showTax)||void 0===c||c,showCampaignOffersDesign:null!==(l=R.propValues.showCampaignOffersDesign)&&void 0!==l&&l,showCampaignIsBiggerImage:null!==(u=R.propValues.showCampaignIsBiggerImage)&&void 0!==u&&u,campaignOfferIsSmallDesign:null!==(p=R.propValues.campaignOfferIsSmallDesign)&&void 0!==p&&p,showCampaignHideDiscountBadge:null!==(g=R.propValues.showCampaignHideDiscountBadge)&&void 0!==g&&g,campaignOfferCountdownStyleIsLine:null!==(f=R.propValues.campaignOfferCountdownStyleIsLine)&&void 0!==f&&f,campaignOfferCountdownStyleIsLineSuccessPage:null!==(m=R.propValues.campaignOfferCountdownStyleIsLineSuccessPage)&&void 0!==m&&m,campaignOffersEnableMiddlePhase:null!==(h=R.propValues.campaignOffersEnableMiddlePhase)&&void 0!==h&&h,campaignOffersTitleColor:null!==(S=R.propValues.campaignOffersTitleColor)&&void 0!==S?S:null,campaignOffersDescriptionColor:null!==(v=R.propValues.campaignOffersDescriptionColor)&&void 0!==v?v:null,campaignOffersDiscountPercentageColor:null!==(C=R.propValues.campaignOffersDiscountPercentageColor)&&void 0!==C?C:null,campaignOffersDiscountPercentageBgColor:null!==(I=R.propValues.campaignOffersDiscountPercentageBgColor)&&void 0!==I?I:null,campaignOffersCountdownTextColor:null!==(y=R.propValues.campaignOffersCountdownTextColor)&&void 0!==y?y:null,campaignOffersCountdownTimeColor:null!==(L=R.propValues.campaignOffersCountdownTimeColor)&&void 0!==L?L:null,campaignOffersCountdownBgColor:null!==(P=R.propValues.campaignOffersCountdownBgColor)&&void 0!==P?P:null,campaignOffersMiddlePhaseOverlayColor:null!==(T=R.propValues.campaignOffersMiddlePhaseOverlayColor)&&void 0!==T?T:null,buttonBgColor:R.propValues.buttonBgColor,buttonTextColor:R.propValues.buttonTextColor,buttonDisabledBgColor:R.propValues.buttonDisabledBgColor,buttonDisabledTextColor:R.propValues.buttonDisabledTextColor,primaryTextColor:R.propValues.primaryTextColor,secondaryTextColor:R.propValues.secondaryTextColor,primaryBgColor:R.propValues.primaryBgColor,secondaryBgColor:R.propValues.secondaryBgColor,borderColor:R.propValues.borderColor,cardBgColor:R.propValues.cardBgColor,errorColor:R.propValues.errorColor,errorLightColor:R.propValues.errorLightColor,warningColor:R.propValues.warningColor,warningLightColor:R.propValues.warningLightColor,successColor:R.propValues.successColor,successLightColor:R.propValues.successLightColor,secondaryButtonBgColor:null!==(w=R.propValues.secondaryButtonBgColor)&&void 0!==w?w:null,secondaryButtonTextColor:null!==(k=R.propValues.secondaryButtonTextColor)&&void 0!==k?k:null,secondaryButtonBorderColor:null!==(O=R.propValues.secondaryButtonBorderColor)&&void 0!==O?O:null},e.customizationProps=V,e.returnPolicy=b.returnPolicy,e.privacyPolicy=b.privacyPolicy,e.termsOfService=b.termsOfService,e.imprint=b.imprint,e.shippingPolicy=b.shippingPolicy,e.checkoutSettings=(null===(B=null==E?void 0:E.data)||void 0===B?void 0:B.length)?E.data[0]:null,t.label=2;case 2:return[2,e]}}))}))},S.getPageData=function(o,r,s,i,l){var u;return e(this,void 0,void 0,(function(){var e,d,g,f,m,h,v,C;return t(this,(function(t){switch(t.label){case 0:return e="local"===process.env.NEXT_PUBLIC_ENV,d=!e&&l,c.init({apiUrl:process.env.NEXT_PUBLIC_GQL_URL,cdnUrl:process.env.NEXT_PUBLIC_CDN_URL}),p(),d?[3,7]:(g=o.locale)?[4,S.getSettings(g)]:[2,{props:{},notFound:!0}];case 1:return(f=t.sent())&&f.storefront.mainStorefrontThemeId&&f.storefront.salesChannelId?[4,this.setStorefrontConfig(f)]:[2,{props:{},notFound:!0}];case 2:return t.sent(),m=f.themeLocalization,(h=new a(m.themeJson,o.params,s,f.merchantSettings)).possiblePageTypes=i||(s?[s]:[]),l?[3,4]:[4,h.getPageData()];case 3:if(t.sent(),!h.page)return[2,{props:{},notFound:!0}];t.label=4;case 4:return v=l?h.theme.components.map((function(e){return e.id})):(null===(u=h.page)||void 0===u?void 0:u.components.map((function(e){return e.componentId})))||[],[4,this.setTranslations(f,v,s,l,g)];case 5:return t.sent(),[4,this.getExtraProps(f,h,s)];case 6:return C=t.sent(),r?[2,{props:n(n({},h.nextPageData.props),C)}]:[2,{props:n(n({},h.nextPageData.props),C),revalidate:60}];case 7:return[2,{props:{}}];case 8:return[2]}}))}))},S.getStaticProps=function(o,n,r,s){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,S.getPageData(o,!1,n,r,s)];case 1:return[2,e.sent()]}}))}))},S.getServerSideProps=function(o,n){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,S.getPageData(o,!0,n)];case 1:return[2,e.sent()]}}))}))},S.createColorScript=function(e){if(e.colors)return"<script>".concat(e.colors.map((function(e){return'document.documentElement.style.setProperty("'.concat(e.key,'","').concat(e.color,'");')})).join("\r\n"),"<\/script> \n ")},S.createFontScript=function(o){return e(this,void 0,void 0,(function(){var e,n,r;return t(this,(function(t){switch(t.label){case 0:return(e=g(o.fontFamily))?[4,fetch(e,{headers:{"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"}})]:[3,3];case 1:return[4,t.sent().text()];case 2:return n=t.sent(),r=n.replace(new RegExp("fonts.gstatic.com","g"),"fonts.myikas.com"),[2,"<style>\n ".concat(r,"\n\n body { \n font-family: '").concat(o.fontFamily.name,'\', -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;\n } \n\n </style>')];case 3:return[2]}}))}))},S.startTime=Date.now(),S}();export{S as IkasNextPageDataProvider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront-next",
3
- "version": "4.15.0-beta.8",
3
+ "version": "4.15.0",
4
4
  "description": "Next.js specific functions for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -17,23 +17,23 @@
17
17
  },
18
18
  "peerDependencies": {
19
19
  "next": "12.2.0",
20
- "@ikas/storefront-config": "^4.15.0-beta.8",
21
- "@ikas/storefront-providers": "^4.15.0-beta.8",
22
- "@ikas/storefront-models": "^4.15.0-beta.8",
23
- "@ikas/storefront-api": "^4.15.0-beta.8",
24
- "@ikas/storefront-assets": "^4.15.0-beta.8",
20
+ "@ikas/storefront-config": "^4.15.0",
21
+ "@ikas/storefront-providers": "^4.15.0",
22
+ "@ikas/storefront-models": "^4.15.0",
23
+ "@ikas/storefront-api": "^4.15.0",
24
+ "@ikas/storefront-assets": "^4.15.0",
25
25
  "axios": "^0.26.0",
26
26
  "lodash": "^4.17.21",
27
27
  "cors": "^2.8.5",
28
28
  "adm-zip": "^0.5.9"
29
29
  },
30
30
  "devDependencies": {
31
- "@ikas/storefront-cmd": "^4.15.0-beta.8",
32
- "@ikas/storefront-config": "^4.15.0-beta.8",
33
- "@ikas/storefront-providers": "^4.15.0-beta.8",
34
- "@ikas/storefront-models": "^4.15.0-beta.8",
35
- "@ikas/storefront-api": "^4.15.0-beta.8",
36
- "@ikas/storefront-assets": "^4.15.0-beta.8",
31
+ "@ikas/storefront-cmd": "^4.15.0",
32
+ "@ikas/storefront-config": "^4.15.0",
33
+ "@ikas/storefront-providers": "^4.15.0",
34
+ "@ikas/storefront-models": "^4.15.0",
35
+ "@ikas/storefront-api": "^4.15.0",
36
+ "@ikas/storefront-assets": "^4.15.0",
37
37
  "@rollup/plugin-node-resolve": "^13.3.0",
38
38
  "@rollup/plugin-commonjs": "^22.0.0",
39
39
  "@rollup/plugin-json": "^4.1.0",