@ikas/storefront-next 4.2.0-alpha.1 → 4.2.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/api/uploadTheme.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e,__generator as t}from'./../ext/tslib/tslib.es6.js';import n from"fs";import r from"path";import s from"archiver";import o from"axios";import i from"@ikas/storefront-assets/checkout/de.js";import
|
|
1
|
+
import{__awaiter as e,__generator as t}from'./../ext/tslib/tslib.es6.js';import n from"fs";import r from"path";import s from"archiver";import o from"axios";import i from"@ikas/storefront-assets/checkout/de.js";import c from"@ikas/storefront-assets/checkout/en.js";import a from"@ikas/storefront-assets/checkout/tr.js";import{corsMiddleware as u}from"./middleware.js";var l=function(s,o){return e(void 0,void 0,void 0,(function(){var e,l,f,y,v,S,w,j,b;return t(this,(function(t){switch(t.label){case 0:return[4,u(s,o)];case 1:t.sent(),e=function(){o.statusCode=200,o.setHeader("Content-Type","application/json"),o.json({status:"ok"})},l=function(){o.statusCode=400,o.setHeader("Content-Type","application/json"),o.json({status:"failed"})},f="",t.label=2;case 2:return t.trys.push([2,10,11,12]),[4,new Promise((function(e,t){var s=r.join(process.cwd(),"src","theme.json");n.readFile(s,(function(n,r){if(n)return t(n);e(JSON.parse(r.toString()))}))}))];case 3:return y=t.sent(),[4,new Promise((function(e,t){var s=r.join(process.cwd(),"public","locales"),o=function(e){return e.length?e.split(".")[0]:e};n.readdir(s,(function(u,l){if(u)return t(u);var f=l.filter((function(e){return n.lstatSync(r.join(s,e)).isDirectory()})),p={},d=!1;f.forEach((function(e){var t=r.join(process.cwd(),"public","locales",e);p[e]={};try{var s=n.readdirSync(t);s.forEach((function(t){var s=n.readFileSync(r.join(process.cwd(),"public","locales",e,t)),u=o(e).toLowerCase(),l=o(t);p[u][l]=JSON.parse(s.toString()),p[u]["checkout-page"]="tr"===u?a:"de"===u?i:c}))}catch(e){console.error(e),d=!0}})),d?t(null):e(p)}))}))];case 4:return v=t.sent(),[4,d(y,v)];case 5:return S=t.sent(),w=!1,"string"!=typeof S?[3,9]:[4,p()];case 6:return f=t.sent(),j=n.statSync(f),[4,h(S,n.readFileSync(f),j.size)];case 7:return(w=t.sent())?[4,m()]:[3,9];case 8:w=t.sent(),t.label=9;case 9:return w?e():l(),[3,12];case 10:return b=t.sent(),console.error(b),l(),[3,12];case 11:return f&&function(e){try{n.unlinkSync(e)}catch(e){console.error(e)}}(f),[7];case 12:return[2]}}))}))},f={};function p(){return e(this,void 0,void 0,(function(){var e,o,i,c,a;return t(this,(function(t){switch(t.label){case 0:return e=r.join(process.cwd()),"theme.zip",o=r.join(process.cwd(),"theme.zip"),i=n.createWriteStream(o),(c=s("zip",{zlib:{level:9}})).on("warning",(function(e){if("ENOENT"!==e.code)throw e})),c.on("error",(function(e){throw e})),c.pipe(i),a=["node_modules",".next","out",".git"],n.readdirSync(e).forEach((function(t){var s=r.join(e,t);if(n.lstatSync(s).isDirectory()){if(a.includes(t))return;c.directory(s,t)}else c.file(s,{name:t})})),[4,c.finalize()];case 1:return t.sent(),[2,new Promise((function(e){setTimeout((function(){e(o)}),2e3)}))]}}))}))}function d(n,r){return e(this,void 0,void 0,(function(){var e,s,i,c,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,4,,5]),e=Object.keys(r),s=e.some((function(e){return"en"===e}))?"en":e[0],[4,y()];case 1:return i=t.sent(),[4,o({method:"post",url:process.env.NEXT_PUBLIC_PARTNER_GQL_URL,headers:{"x-api-key":i.apiKey,"Content-Type":"application/json"},data:JSON.stringify({query:"\n mutation createNewThemeVersion($input: CreateNewThemeVersionInput!) {\n createNewThemeVersion(input: $input) {\n themeVersionId\n uploadUrl\n }\n }\n ",variables:{input:{themeId:i.themeId,themeSecret:i.themeSecret,themeJson:JSON.stringify(n),locales:Object.entries(r).map((function(e){var t=e[0],n=e[1];return{isDefaultLocale:t===s,locale:t,localeJson:JSON.stringify(n)}}))}}})})];case 2:return[4,t.sent().data];case 3:return(c=t.sent()).data&&c.data.createNewThemeVersion?[2,c.data.createNewThemeVersion.uploadUrl]:[3,5];case 4:return a=t.sent(),console.log(a),[3,5];case 5:return[2]}}))}))}function h(n,r,s){return e(this,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:e={headers:{"Content-Type":"application/zip","Content-Length":s+""}},t.label=1;case 1:return t.trys.push([1,3,,4]),[4,o.put(n,r,e)];case 2:return[2,200===t.sent().status];case 3:return i=t.sent(),console.log(i),[2,!1];case 4:return[2]}}))}))}function m(){return e(this,void 0,void 0,(function(){var e,n;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,4,,5]),[4,y()];case 1:return e=t.sent(),[4,fetch(process.env.NEXT_PUBLIC_PARTNER_GQL_URL,{method:"POST",body:JSON.stringify({query:"\n mutation buildThemeLatestVersion(\n $themeSecret: String!\n $themeId: String!\n ) {\n buildThemeLatestVersion(\n themeSecret: $themeSecret\n themeId: $themeId\n )\n }\n ",variables:{themeSecret:e.themeSecret,themeId:e.themeId}}),headers:{"x-api-key":e.apiKey,"Content-Type":"application/json"}})];case 2:return[4,t.sent().json()];case 3:return t.sent(),[2,!0];case 4:return n=t.sent(),console.log(n),[2,!1];case 5:return[2]}}))}))}function y(){return new Promise((function(e,t){var s=r.join(process.cwd(),"config.json");n.readFile(s,(function(n,r){if(n)return t(n);e(JSON.parse(r.toString()))}))}))}export{f as config,l as uploadTheme};
|
|
@@ -14,7 +14,7 @@ export declare class IkasNextPageDataProvider {
|
|
|
14
14
|
static getProdSettings(locale: string): Promise<SettingsData | null>;
|
|
15
15
|
static getSettings(locale: string): Promise<SettingsData | null>;
|
|
16
16
|
static setStorefrontConfig(settings: SettingsData): Promise<void>;
|
|
17
|
-
static setTranslations(settings: SettingsData, componentIds: string[], pageType?: IkasThemeJsonPageType, isEditor?: boolean): Promise<void>;
|
|
17
|
+
static setTranslations(settings: SettingsData, componentIds: string[], pageType?: IkasThemeJsonPageType, isEditor?: boolean, contextLocale?: string): Promise<void>;
|
|
18
18
|
static getExtraProps(settings: SettingsData, provider: IkasPageDataProvider, pageType?: IkasThemeJsonPageType): Promise<Record<string, any>>;
|
|
19
19
|
static getPageData(context: GetStaticPropsContext<ParsedUrlQuery> | GetServerSidePropsContext<ParsedUrlQuery>, isServer: boolean, pageType?: IkasThemeJsonPageType, possiblePageTypes?: IkasThemeJsonPageType[], isEditor?: boolean): Promise<{
|
|
20
20
|
props: {};
|
|
@@ -56,7 +56,7 @@ export declare class IkasNextPageDataProvider {
|
|
|
56
56
|
notFound?: undefined;
|
|
57
57
|
}>;
|
|
58
58
|
static createColorScript(settings: IkasThemeJsonSettings): string | undefined;
|
|
59
|
-
static createFontScript(settings: IkasThemeJsonSettings): string | undefined
|
|
59
|
+
static createFontScript(settings: IkasThemeJsonSettings): Promise<string | undefined>;
|
|
60
60
|
}
|
|
61
61
|
export declare type SettingsData = {
|
|
62
62
|
storefront: IkasStorefront;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__generator as e,__spreadArray as r,__assign as o}from'./../ext/tslib/tslib.es6.js';import n from"fs";import s from"next/config.js";import{IkasThemeJsonPageType as i}from"@ikas/storefront-models";import{IkasPageDataProvider as c}from"@ikas/storefront-providers";import{IkasStorefrontConfig as a}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(t,e){n.readFile("./src/theme.json",{flag:"a+"},(function(r,o){if(r)return e(r);var n=o.length?JSON.parse(o.toString()):{};t(n)}))}))},S.readSettingsFile=function(){return new Promise((function(t){var e=s().serverRuntimeConfig.SETTINGS;n.readFile(e,{flag:"a+"},(function(e,r){if(e)return console.error("SETTINGS FILE READ ERROR!!!"),console.error(e),t(null);var o=r.length?JSON.parse(r.toString()):{};t(o)}))}))},S.cacheLocalSettingsFile=function(r){return t(this,void 0,void 0,(function(){var t,o;return e(this,(function(e){switch(e.label){case 0:return[4,h(t=".ikas")];case 1:return e.sent(),o="settings-".concat(this.startTime,".json"),[4,m(t,o,JSON.stringify(r,null,2))];case 2:return e.sent(),[2]}}))}))},S.readLocalSettingsFile=function(){try{var t=n.readFileSync(".ikas/settings-".concat(this.startTime,".json"));if(t&&t.length)return JSON.parse(t.toString())}catch(t){}},S.getLocalSettings=function(r){return t(this,void 0,void 0,(function(){var t,o,n,s,i,c,a,u,p,d;return e(this,(function(e){switch(e.label){case 0:return[4,S.readLocalSettingsFile()];case 1:return(t=e.sent())?[3,4]:[4,l()];case 2:return(o=e.sent()).isSuccess&&o.data?(t=o.data,[4,this.cacheLocalSettingsFile(t)]):(console.error("Storefront settings fetch failed!"),console.error(o),[2,null]);case 3:e.sent(),e.label=4;case 4:return n=t.storefront,s=t.salesChannel,i=[],c=t.productBackInStockSettings?{customerLoginRequired:t.productBackInStockSettings.customerLoginRequired}:null,a=t.customerReviewSettings?{customerLoginRequired:t.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:t.customerReviewSettings.customerPurchaseRequired||!1}:null,[4,S.readLocalTheme()];case 5:return u=e.sent(),p=S.createColorScript(u.settings),d=S.createFontScript(u.settings),p&&i.push(p),d&&i.push(d),[2,{storefront:n,themeLocalization:{id:"",locale:"en",privacyPolicy:null,returnPolicy:null,storefrontId:n.id,storefrontThemeId:"",termsOfService:null,imprint:null,shippingPolicy:null,themeJson:u},salesChannel:s,routing:n.routings.length?n.routings.find((function(t){return t.locale===r||t.id===r}))||n.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,domain:"localhost:3333",productBackInStockSettings:c,customerReviewSettings:a,merchantSettings:t.merchantSettings,customerSettings:t.customerSettings}]}}))}))},S.getProdSettings=function(r){return t(this,void 0,void 0,(function(){var o=this;return e(this,(function(s){return[2,new Promise((function(s){return t(o,void 0,void 0,(function(){var t,o,i,c,a,l,p,d,g,f,m,h;return e(this,(function(e){switch(e.label){case 0:return[4,S.readSettingsFile()];case 1:return(t=e.sent())&&t.localizationMap?(o=t.storefront,i=t.salesChannel,c=t.localizationMap,a=t.storefrontJSScripts||[],l=t.domain,p=t.productBackInStockSettings?{customerLoginRequired:t.productBackInStockSettings.customerLoginRequired}:null,d=t.customerReviewSettings?{customerLoginRequired:t.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:t.customerReviewSettings.customerPurchaseRequired||!1}:null,(g=t.merchantSettings)?[3,3]:[4,u({})]):[2,s(null)];case 2:if(!(f=e.sent()).isSuccess||!f.data)return console.error("MERCHANT SETTINGS FETCH FAILED!"),[2,s(null)];g=f.data,e.label=3;case 3:return m=c[r],h=o.routings.find((function(t){return t.id===r||t.path===r})),m&&h?(n.readFile(m,{flag:"a+"},(function(e,r){if(e)return console.error("THEME LOCALIZATION FILE READ ERROR!!!"),console.error(e),s(null);var n=r.length?JSON.parse(r.toString()):{},c=n.themeJson.settings.favicon,u=n.themeJson.settings.stockPreference;if(n.themeJson.settings){var f=S.createColorScript(n.themeJson.settings),m=S.createFontScript(n.themeJson.settings);f&&a.push(f),m&&a.push(m)}var v=t.customerSettings;s({storefront:o,themeLocalization:n,salesChannel:i,routing:h,favicon:c,stockPreference:u,storefrontJSScripts:a,domain:l,productBackInStockSettings:p,customerReviewSettings:d,merchantSettings:g,customerSettings:v})})),[2]):(console.error("THEME LOCALIZATION PATH OR ROUTING MISSING!!!"),[2,s(null)])}}))}))}))]}))}))},S.getSettings=function(r){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return"local"===process.env.NEXT_PUBLIC_ENV?[4,this.getLocalSettings(r)]:[3,2];case 1:case 3:return[2,t.sent()];case 2:return[4,this.getProdSettings(r)]}}))}))},S.setStorefrontConfig=function(r){var o;return t(this,void 0,void 0,(function(){var t,n,s,i,c,l,u,d,g,f,m;return e(this,(function(e){return t=r.storefront,n=r.salesChannel,s=r.routing,i=r.favicon,c=r.stockPreference,l=r.storefrontJSScripts,u=r.domain,d=r.productBackInStockSettings,g=r.customerReviewSettings,f=r.merchantSettings,m=r.customerSettings,a.init({apiUrl:process.env.NEXT_PUBLIC_GQL_URL,adminApiUrl:process.env.NEXT_PUBLIC_UPLOAD_GQL_URL,cdnUrl:process.env.NEXT_PUBLIC_IMG_BASE_URL,storefrontId:t.id,storefrontRoutingId:s.id,storefrontThemeId:t.mainStorefrontThemeId,salesChannelId:t.salesChannelId,priceListId:s.priceListId||void 0,stockLocationIds:null===(o=n.stockLocations)||void 0===o?void 0:o.map((function(t){return t.id})),routings:t.routings,paymentGateways:n.paymentGateways||[],gtmId:t.gtmId||void 0,fbpId:t.fbpId||void 0,analytics4Id:t.analytics4Id||void 0,universalAnalyticsId:t.universalAnalyticsId||void 0,tiktokPixelId:t.tiktokPixelId||void 0,favicon:i||null,pickUpStockLocationIds:t.pickUpStockLocationIds&&t.pickUpStockLocationIds.length?t.pickUpStockLocationIds:null,stockPreference:c||null,storefrontJSScripts:l||[],domain:u,productBackInStockSettings:d,customerReviewSettings:g,merchantSettings:f,customerSettings:m,metaTemplates:t.metaTemplates||null}),p(),[2]}))}))},S.setTranslations=function(o,n,c,l){return t(this,void 0,void 0,(function(){var t,u,p,d,g,m,h,S;return e(this,(function(e){switch(e.label){case 0:return t=s().serverRuntimeConfig,u=o.routing,p="local"===process.env.NEXT_PUBLIC_ENV,d=o.themeLocalization.themeJson.components.filter((function(t){return l||n.includes(t.id)})),g=r(["common"],d.map((function(t){return t.dir})),!0),(c===i.CHECKOUT||l)&&g.push("checkout-page"),m=t.nextI18nConf,h=u.locale,[4,new f(h,g,p?void 0:m.localePath).read()];case 1:return S=e.sent(),a.init({translations:S}),[2]}}))}))},S.getExtraProps=function(r,o,n){var s,c,a;return t(this,void 0,void 0,(function(){var t,l,u,p,g;return e(this,(function(e){switch(e.label){case 0:return t={},l=r.themeLocalization,n!==i.CHECKOUT?[3,2]:(u=null===(s=o.page)||void 0===s?void 0:s.components[0])?[4,d({})]:[3,2];case 1:(p=e.sent()).isSuccess||(console.error("CHECKOUT SETTINGS FETCH FAILED!"),console.error(p.graphQLErrors),console.error(p.errorCodes)),g={showTax:null===(c=u.propValues.showTax)||void 0===c||c,buttonBgColor:u.propValues.buttonBgColor,buttonTextColor:u.propValues.buttonTextColor,buttonDisabledBgColor:u.propValues.buttonDisabledBgColor,buttonDisabledTextColor:u.propValues.buttonDisabledTextColor,primaryTextColor:u.propValues.primaryTextColor,secondaryTextColor:u.propValues.secondaryTextColor,primaryBgColor:u.propValues.primaryBgColor,secondaryBgColor:u.propValues.secondaryBgColor,borderColor:u.propValues.borderColor,cardBgColor:u.propValues.cardBgColor,errorColor:u.propValues.errorColor,errorLightColor:u.propValues.errorLightColor,warningColor:u.propValues.warningColor,warningLightColor:u.propValues.warningLightColor,successColor:u.propValues.successColor,successLightColor:u.propValues.successLightColor},t.customizationProps=g,t.returnPolicy=l.returnPolicy,t.privacyPolicy=l.privacyPolicy,t.termsOfService=l.termsOfService,t.imprint=l.imprint,t.shippingPolicy=l.shippingPolicy,t.checkoutSettings=(null===(a=null==p?void 0:p.data)||void 0===a?void 0:a.length)?p.data[0]:null,e.label=2;case 2:return[2,t]}}))}))},S.getPageData=function(r,n,s,i,l){var u;return t(this,void 0,void 0,(function(){var t,d,g,f,m,h,v,C;return e(this,(function(e){switch(e.label){case 0:return t="local"===process.env.NEXT_PUBLIC_ENV,d=!t&&l,a.init({apiUrl:process.env.NEXT_PUBLIC_GQL_URL,adminApiUrl:process.env.NEXT_PUBLIC_UPLOAD_GQL_URL,cdnUrl:process.env.NEXT_PUBLIC_IMG_BASE_URL}),p(),d?[3,7]:(g=r.locale)?[4,S.getSettings(g)]:[2,{props:{},notFound:!0}];case 1:return(f=e.sent())&&f.storefront.mainStorefrontThemeId&&f.storefront.salesChannelId?[4,this.setStorefrontConfig(f)]:[2,{props:{},notFound:!0}];case 2:return e.sent(),m=f.themeLocalization,(h=new c(m.themeJson,r.params,s)).possiblePageTypes=i||(s?[s]:[]),l?[3,4]:[4,h.getPageData()];case 3:if(e.sent(),!h.page)return[2,{props:{},notFound:!0}];e.label=4;case 4:return v=l?h.theme.components.map((function(t){return t.id})):(null===(u=h.page)||void 0===u?void 0:u.components.map((function(t){return t.componentId})))||[],[4,this.setTranslations(f,v,s,l)];case 5:return e.sent(),[4,this.getExtraProps(f,h,s)];case 6:return C=e.sent(),n?[2,{props:o(o({},h.nextPageData.props),C)}]:[2,{props:o(o({},h.nextPageData.props),C),revalidate:60}];case 7:return[2,{props:{}}];case 8:return[2]}}))}))},S.getStaticProps=function(r,o,n,s){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,S.getPageData(r,!1,o,n,s)];case 1:return[2,t.sent()]}}))}))},S.getServerSideProps=function(r,o){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,S.getPageData(r,!0,o)];case 1:return[2,t.sent()]}}))}))},S.createColorScript=function(t){if(t.colors)return"<script>".concat(t.colors.map((function(t){return'document.documentElement.style.setProperty("'.concat(t.key,'","').concat(t.color,'");')})).join("\r\n"),"<\/script> \n ")},S.createFontScript=function(t){var e=g(t.fontFamily);if(e)return'<link id="ikas-font" rel="stylesheet" href="'.concat(e,"\"> \n <style>\n body { \n font-family: '").concat(t.fontFamily.name,'\', -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;\n } \n </style>')},S.startTime=Date.now(),S}();export{S as IkasNextPageDataProvider};
|
|
1
|
+
import{__awaiter as t,__generator as e,__spreadArray as r,__assign as n}from'./../ext/tslib/tslib.es6.js';import o from"fs";import s from"next/config.js";import{IkasThemeJsonPageType as i}from"@ikas/storefront-models";import{IkasPageDataProvider as c}from"@ikas/storefront-providers";import{IkasStorefrontConfig as a}from"@ikas/storefront-config";import{getStorefrontSettings as u,listMerchantSettings as l,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(t,e){o.readFile("./src/theme.json",{flag:"a+"},(function(r,n){if(r)return e(r);var o=n.length?JSON.parse(n.toString()):{};t(o)}))}))},S.readSettingsFile=function(){return new Promise((function(t){var e=s().serverRuntimeConfig.SETTINGS;o.readFile(e,{flag:"a+"},(function(e,r){if(e)return console.error("SETTINGS FILE READ ERROR!!!"),console.error(e),t(null);var n=r.length?JSON.parse(r.toString()):{};t(n)}))}))},S.cacheLocalSettingsFile=function(r){return t(this,void 0,void 0,(function(){var t,n;return e(this,(function(e){switch(e.label){case 0:return[4,h(t=".ikas")];case 1:return e.sent(),n="settings-".concat(this.startTime,".json"),[4,m(t,n,JSON.stringify(r,null,2))];case 2:return e.sent(),[2]}}))}))},S.readLocalSettingsFile=function(){try{var t=o.readFileSync(".ikas/settings-".concat(this.startTime,".json"));if(t&&t.length)return JSON.parse(t.toString())}catch(t){}},S.getLocalSettings=function(r){return t(this,void 0,void 0,(function(){var t,n,o,s,i,c,a,l,p,d;return e(this,(function(e){switch(e.label){case 0:return[4,S.readLocalSettingsFile()];case 1:return(t=e.sent())?[3,4]:[4,u()];case 2:return(n=e.sent()).isSuccess&&n.data?(t=n.data,[4,this.cacheLocalSettingsFile(t)]):(console.error("Storefront settings fetch failed!"),console.error(n),[2,null]);case 3:e.sent(),e.label=4;case 4:return o=t.storefront,s=t.salesChannel,i=[],c=t.productBackInStockSettings?{customerLoginRequired:t.productBackInStockSettings.customerLoginRequired}:null,a=t.customerReviewSettings?{customerLoginRequired:t.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:t.customerReviewSettings.customerPurchaseRequired||!1}:null,[4,S.readLocalTheme()];case 5:return l=e.sent(),p=S.createColorScript(l.settings),[4,S.createFontScript(l.settings)];case 6:return d=e.sent(),p&&i.push(p),d&&i.push(d),[2,{storefront:o,themeLocalization:{id:"",locale:"en",privacyPolicy:null,returnPolicy:null,storefrontId:o.id,storefrontThemeId:"",termsOfService:null,imprint:null,shippingPolicy:null,themeJson:l},salesChannel:s,routing:o.routings.length?o.routings.find((function(t){return t.locale===r||t.id===r}))||o.routings[0]:{countryCodes:[],domain:"",dynamicCurrencySettings:{roundingFormat:null,targetCurrencyCode:""},id:"",locale:"en",path:null,priceListId:null,currencyCode:"USD",currencySymbol:"$"},favicon:l.settings.favicon,stockPreference:l.settings.stockPreference,storefrontJSScripts:i,domain:"localhost:3333",productBackInStockSettings:c,customerReviewSettings:a,merchantSettings:t.merchantSettings,customerSettings:t.customerSettings}]}}))}))},S.getProdSettings=function(r){return t(this,void 0,void 0,(function(){var n=this;return e(this,(function(s){return[2,new Promise((function(s){return t(n,void 0,void 0,(function(){var n,i,c,a,u,p,d,g,f,m,h,v;return e(this,(function(C){switch(C.label){case 0:return[4,S.readSettingsFile()];case 1:return(n=C.sent())&&n.localizationMap?(i=n.storefront,c=n.salesChannel,a=n.localizationMap,u=n.storefrontJSScripts||[],p=n.domain,d=n.productBackInStockSettings?{customerLoginRequired:n.productBackInStockSettings.customerLoginRequired}:null,g=n.customerReviewSettings?{customerLoginRequired:n.customerReviewSettings.customerLoginRequired||!1,customerPurchaseRequired:n.customerReviewSettings.customerPurchaseRequired||!1}:null,(f=n.merchantSettings)?[3,3]:[4,l({})]):[2,s(null)];case 2:if(!(m=C.sent()).isSuccess||!m.data)return console.error("MERCHANT SETTINGS FETCH FAILED!"),[2,s(null)];f=m.data,C.label=3;case 3:return h=a[r],v=i.routings.find((function(t){return t.id===r||t.path===r})),h&&v?(o.readFile(h,{flag:"a+"},(function(r,o){return t(this,void 0,void 0,(function(){var t,a,l,m,h,C,I;return e(this,(function(e){switch(e.label){case 0:return r?(console.error("THEME LOCALIZATION FILE READ ERROR!!!"),console.error(r),[2,s(null)]):(t=o.length?JSON.parse(o.toString()):{},l=(a=t).themeJson.settings.favicon,m=a.themeJson.settings.stockPreference,a.themeJson.settings?(h=S.createColorScript(a.themeJson.settings),[4,S.createFontScript(a.themeJson.settings)]):[3,2]);case 1:C=e.sent(),h&&u.push(h),C&&u.push(C),e.label=2;case 2:return I=n.customerSettings,s({storefront:i,themeLocalization:a,salesChannel:c,routing:v,favicon:l,stockPreference:m,storefrontJSScripts:u,domain:p,productBackInStockSettings:d,customerReviewSettings:g,merchantSettings:f,customerSettings:I}),[2]}}))}))})),[2]):(console.error("THEME LOCALIZATION PATH OR ROUTING MISSING!!!"),[2,s(null)])}}))}))}))]}))}))},S.getSettings=function(r){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return"local"===process.env.NEXT_PUBLIC_ENV?[4,this.getLocalSettings(r)]:[3,2];case 1:case 3:return[2,t.sent()];case 2:return[4,this.getProdSettings(r)]}}))}))},S.setStorefrontConfig=function(r){var n;return t(this,void 0,void 0,(function(){var t,o,s,i,c,u,l,d,g,f,m;return e(this,(function(e){return t=r.storefront,o=r.salesChannel,s=r.routing,i=r.favicon,c=r.stockPreference,u=r.storefrontJSScripts,l=r.domain,d=r.productBackInStockSettings,g=r.customerReviewSettings,f=r.merchantSettings,m=r.customerSettings,a.init({apiUrl:process.env.NEXT_PUBLIC_GQL_URL,cdnUrl:process.env.NEXT_PUBLIC_CDN_URL,storefrontId:t.id,storefrontRoutingId:s.id,storefrontThemeId:t.mainStorefrontThemeId,salesChannelId:t.salesChannelId,priceListId:s.priceListId||void 0,stockLocationIds:null===(n=o.stockLocations)||void 0===n?void 0:n.map((function(t){return t.id})),routings:t.routings,paymentGateways:o.paymentGateways||[],gtmId:t.gtmId||void 0,fbpId:t.fbpId||void 0,analytics4Id:t.analytics4Id||void 0,universalAnalyticsId:t.universalAnalyticsId||void 0,tiktokPixelId:t.tiktokPixelId||void 0,favicon:i||null,pickUpStockLocationIds:t.pickUpStockLocationIds&&t.pickUpStockLocationIds.length?t.pickUpStockLocationIds:null,stockPreference:c||null,storefrontJSScripts:u||[],domain:l,productBackInStockSettings:d,customerReviewSettings:g,merchantSettings:f,customerSettings:m,metaTemplates:t.metaTemplates||null}),p(),[2]}))}))},S.setTranslations=function(n,o,c,u,l){return t(this,void 0,void 0,(function(){var t,p,d,g,m,h,S,v;return e(this,(function(e){switch(e.label){case 0:return t=s().serverRuntimeConfig,p=n.routing,d="local"===process.env.NEXT_PUBLIC_ENV,g=n.themeLocalization.themeJson.components.filter((function(t){return u||o.includes(t.id)})),m=r(["common"],g.map((function(t){return t.dir})),!0),(c===i.CHECKOUT||u)&&m.push("checkout-page"),h=t.nextI18nConf,S=d&&l?l:p.locale,[4,new f(S,m,d?void 0:h.localePath).read()];case 1:return v=e.sent(),a.init({translations:v}),[2]}}))}))},S.getExtraProps=function(r,n,o){var s,c,a;return t(this,void 0,void 0,(function(){var t,u,l,p,g;return e(this,(function(e){switch(e.label){case 0:return t={},u=r.themeLocalization,o!==i.CHECKOUT?[3,2]:(l=null===(s=n.page)||void 0===s?void 0:s.components[0])?[4,d({})]:[3,2];case 1:(p=e.sent()).isSuccess||(console.error("CHECKOUT SETTINGS FETCH FAILED!"),console.error(p.graphQLErrors),console.error(p.errorCodes)),g={showTax:null===(c=l.propValues.showTax)||void 0===c||c,buttonBgColor:l.propValues.buttonBgColor,buttonTextColor:l.propValues.buttonTextColor,buttonDisabledBgColor:l.propValues.buttonDisabledBgColor,buttonDisabledTextColor:l.propValues.buttonDisabledTextColor,primaryTextColor:l.propValues.primaryTextColor,secondaryTextColor:l.propValues.secondaryTextColor,primaryBgColor:l.propValues.primaryBgColor,secondaryBgColor:l.propValues.secondaryBgColor,borderColor:l.propValues.borderColor,cardBgColor:l.propValues.cardBgColor,errorColor:l.propValues.errorColor,errorLightColor:l.propValues.errorLightColor,warningColor:l.propValues.warningColor,warningLightColor:l.propValues.warningLightColor,successColor:l.propValues.successColor,successLightColor:l.propValues.successLightColor},t.customizationProps=g,t.returnPolicy=u.returnPolicy,t.privacyPolicy=u.privacyPolicy,t.termsOfService=u.termsOfService,t.imprint=u.imprint,t.shippingPolicy=u.shippingPolicy,t.checkoutSettings=(null===(a=null==p?void 0:p.data)||void 0===a?void 0:a.length)?p.data[0]:null,e.label=2;case 2:return[2,t]}}))}))},S.getPageData=function(r,o,s,i,u){var l;return t(this,void 0,void 0,(function(){var t,d,g,f,m,h,v,C;return e(this,(function(e){switch(e.label){case 0:return t="local"===process.env.NEXT_PUBLIC_ENV,d=!t&&u,a.init({apiUrl:process.env.NEXT_PUBLIC_GQL_URL,cdnUrl:process.env.NEXT_PUBLIC_CDN_URL}),p(),d?[3,7]:(g=r.locale)?[4,S.getSettings(g)]:[2,{props:{},notFound:!0}];case 1:return(f=e.sent())&&f.storefront.mainStorefrontThemeId&&f.storefront.salesChannelId?[4,this.setStorefrontConfig(f)]:[2,{props:{},notFound:!0}];case 2:return e.sent(),m=f.themeLocalization,(h=new c(m.themeJson,r.params,s)).possiblePageTypes=i||(s?[s]:[]),u?[3,4]:[4,h.getPageData()];case 3:if(e.sent(),!h.page)return[2,{props:{},notFound:!0}];e.label=4;case 4:return v=u?h.theme.components.map((function(t){return t.id})):(null===(l=h.page)||void 0===l?void 0:l.components.map((function(t){return t.componentId})))||[],[4,this.setTranslations(f,v,s,u,g)];case 5:return e.sent(),[4,this.getExtraProps(f,h,s)];case 6:return C=e.sent(),o?[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(r,n,o,s){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,S.getPageData(r,!1,n,o,s)];case 1:return[2,t.sent()]}}))}))},S.getServerSideProps=function(r,n){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,S.getPageData(r,!0,n)];case 1:return[2,t.sent()]}}))}))},S.createColorScript=function(t){if(t.colors)return"<script>".concat(t.colors.map((function(t){return'document.documentElement.style.setProperty("'.concat(t.key,'","').concat(t.color,'");')})).join("\r\n"),"<\/script> \n ")},S.createFontScript=function(r){return t(this,void 0,void 0,(function(){var t,n,o;return e(this,(function(e){switch(e.label){case 0:return(t=g(r.fontFamily))?[4,fetch(t,{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,e.sent().text()];case 2:return n=e.sent(),o=n.replace(new RegExp("fonts.gstatic.com","g"),"fonts.myikas.com"),[2,"<style>\n ".concat(o,"\n\n body { \n font-family: '").concat(r.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.2.0-
|
|
3
|
+
"version": "4.2.0-beta.10",
|
|
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.2.0-
|
|
21
|
-
"@ikas/storefront-providers": "^4.2.0-
|
|
22
|
-
"@ikas/storefront-models": "^4.2.0-
|
|
23
|
-
"@ikas/storefront-api": "^4.2.0-
|
|
24
|
-
"@ikas/storefront-assets": "^4.2.0-
|
|
20
|
+
"@ikas/storefront-config": "^4.2.0-beta.10",
|
|
21
|
+
"@ikas/storefront-providers": "^4.2.0-beta.10",
|
|
22
|
+
"@ikas/storefront-models": "^4.2.0-beta.10",
|
|
23
|
+
"@ikas/storefront-api": "^4.2.0-beta.10",
|
|
24
|
+
"@ikas/storefront-assets": "^4.2.0-beta.10",
|
|
25
25
|
"axios": "^0.21.0",
|
|
26
26
|
"lodash": "^4.17.21",
|
|
27
27
|
"archiver": "^5.3.0",
|
|
28
28
|
"cors": "^2.8.5"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@ikas/storefront-cmd": "^4.2.0-
|
|
32
|
-
"@ikas/storefront-config": "^4.2.0-
|
|
33
|
-
"@ikas/storefront-providers": "^4.2.0-
|
|
34
|
-
"@ikas/storefront-models": "^4.2.0-
|
|
35
|
-
"@ikas/storefront-api": "^4.2.0-
|
|
36
|
-
"@ikas/storefront-assets": "^4.2.0-
|
|
31
|
+
"@ikas/storefront-cmd": "^4.2.0-beta.10",
|
|
32
|
+
"@ikas/storefront-config": "^4.2.0-beta.10",
|
|
33
|
+
"@ikas/storefront-providers": "^4.2.0-beta.10",
|
|
34
|
+
"@ikas/storefront-models": "^4.2.0-beta.10",
|
|
35
|
+
"@ikas/storefront-api": "^4.2.0-beta.10",
|
|
36
|
+
"@ikas/storefront-assets": "^4.2.0-beta.10",
|
|
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",
|