@ikas/storefront 0.0.161-alpha.9 → 0.0.162-alpha.1

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.
@@ -9,6 +9,7 @@ export default class PageViewModel {
9
9
  hoveredPageComponentId?: string | null;
10
10
  componentRefs: any;
11
11
  isLoading: boolean;
12
+ locale: string;
12
13
  pageParams: Record<string, any>;
13
14
  queryParams: Record<string, any>;
14
15
  apiKey?: string | null;
package/build/index.es.js CHANGED
@@ -5,6 +5,7 @@ import Head from 'next/head';
5
5
  import { useRouter } from 'next/router';
6
6
  import Link from 'next/link';
7
7
  import NextImage from 'next/image';
8
+ import { useTranslation } from 'next-i18next';
8
9
  import fs from 'fs';
9
10
  import getConfig from 'next/config';
10
11
  import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
@@ -37207,6 +37208,7 @@ var PageViewModel = /** @class */ (function () {
37207
37208
  this.hoveredPageComponentId = null;
37208
37209
  this.componentRefs = {};
37209
37210
  this.isLoading = false;
37211
+ this.locale = "en";
37210
37212
  this.pageParams = {};
37211
37213
  this.queryParams = {};
37212
37214
  this.apiKey = null;
@@ -37359,6 +37361,7 @@ var PageViewModel = /** @class */ (function () {
37359
37361
  this.pageParams = data.pageParams;
37360
37362
  this.queryParams = data.queryParams;
37361
37363
  this.apiKey = data.apiKey;
37364
+ this.locale = data.locale || "en";
37362
37365
  apollo.createApolloClient(this.apiKey || undefined);
37363
37366
  window.editorApiKey = data.apiKey;
37364
37367
  return [4 /*yield*/, this.getPagePropValues()];
@@ -37647,7 +37650,13 @@ var overlayStyle = {
37647
37650
  var IkasPageEditor = observer(function () {
37648
37651
  var _a, _b, _c;
37649
37652
  var router = useRouter();
37653
+ var i18n = useTranslation().i18n;
37650
37654
  var vm = useState(function () { return new PageViewModel(router); })[0];
37655
+ useEffect(function () {
37656
+ if (typeof i18n.changeLanguage === "function") {
37657
+ i18n.changeLanguage(vm.locale);
37658
+ }
37659
+ }, [vm.locale]);
37651
37660
  if (vm.isLoading)
37652
37661
  return null;
37653
37662
  var headerPageComponent = (_a = vm.pageComponents) === null || _a === void 0 ? void 0 : _a.find(function (pc) { var _a, _b; return pc.componentId === ((_b = (_a = vm.theme) === null || _a === void 0 ? void 0 : _a.headerComponent) === null || _b === void 0 ? void 0 : _b.id); });
@@ -37682,6 +37691,30 @@ var index = /*#__PURE__*/Object.freeze({
37682
37691
  Image: Image
37683
37692
  });
37684
37693
 
37694
+ /**
37695
+ * Creates a duplicate-free version of an array, using
37696
+ * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
37697
+ * for equality comparisons, in which only the first occurrence of each element
37698
+ * is kept. The order of result values is determined by the order they occur
37699
+ * in the array.
37700
+ *
37701
+ * @static
37702
+ * @memberOf _
37703
+ * @since 0.1.0
37704
+ * @category Array
37705
+ * @param {Array} array The array to inspect.
37706
+ * @returns {Array} Returns the new duplicate free array.
37707
+ * @example
37708
+ *
37709
+ * _.uniq([2, 1, 2]);
37710
+ * // => [2, 1]
37711
+ */
37712
+ function uniq(array) {
37713
+ return (array && array.length) ? _baseUniq(array) : [];
37714
+ }
37715
+
37716
+ var uniq_1 = uniq;
37717
+
37685
37718
  var IkasStorefrontLocalization = /** @class */ (function () {
37686
37719
  function IkasStorefrontLocalization(data) {
37687
37720
  this.id = data.id || "";
@@ -37968,10 +38001,10 @@ var SettingsHelper = /** @class */ (function () {
37968
38001
  });
37969
38002
  }); });
37970
38003
  };
37971
- SettingsHelper.getPageData = function (context, isServer, pageType, possiblePageTypes) {
38004
+ SettingsHelper.getPageData = function (context, isServer, pageType, possiblePageTypes, isEditor) {
37972
38005
  var _a;
37973
38006
  return __awaiter(this, void 0, void 0, function () {
37974
- var isLocal, locale, serverRuntimeConfig, settings, storefront, themeLocalization, salesChannel, routing, favicon, stockPreference, provider, componentIds, components, componentDirs, _b, _c;
38007
+ var isLocal, locale, serverRuntimeConfig, settings, storefront, themeLocalization, salesChannel, routing, favicon, stockPreference, provider, componentIds, components, componentDirs, nextI18nConf, routingLocales, defaultRoutingLocale, _b, _c;
37975
38008
  var _d, _e;
37976
38009
  return __generator(this, function (_f) {
37977
38010
  switch (_f.label) {
@@ -38011,56 +38044,67 @@ var SettingsHelper = /** @class */ (function () {
38011
38044
  IkasStorefrontConfig.stockPreference = stockPreference || null;
38012
38045
  provider = new IkasPageDataProvider(themeLocalization.themeJson, context.params, pageType);
38013
38046
  provider.possiblePageTypes = possiblePageTypes;
38047
+ if (!!isEditor) return [3 /*break*/, 3];
38014
38048
  return [4 /*yield*/, provider.getPageData()];
38015
38049
  case 2:
38016
38050
  _f.sent();
38051
+ _f.label = 3;
38052
+ case 3:
38017
38053
  if (!provider.page) {
38018
- return [2 /*return*/, {
38019
- props: {},
38020
- notFound: true,
38021
- }];
38054
+ if (!isEditor)
38055
+ return [2 /*return*/, {
38056
+ props: {},
38057
+ notFound: true,
38058
+ }];
38022
38059
  }
38023
- componentIds = provider.page.components.map(function (pc) { return pc.componentId; });
38024
- components = themeLocalization.themeJson.components.filter(function (c) {
38025
- return componentIds.includes(c.id);
38026
- });
38060
+ componentIds = isEditor
38061
+ ? provider.theme.components.map(function (c) { return c.id; })
38062
+ : provider.page.components.map(function (pc) { return pc.componentId; });
38063
+ components = themeLocalization.themeJson.components.filter(function (c) { return isEditor || componentIds.includes(c.id); });
38027
38064
  componentDirs = __spreadArrays(["common"], components.map(function (c) { return c.dir; }));
38028
- if (!isServer) return [3 /*break*/, 4];
38065
+ nextI18nConf = serverRuntimeConfig.nextI18nConf;
38066
+ routingLocales = uniq_1(storefront.routings.map(function (sr) { return sr.locale; }));
38067
+ defaultRoutingLocale = routing.locale;
38068
+ if (!isServer) return [3 /*break*/, 5];
38029
38069
  _d = {};
38030
38070
  _b = [{}];
38031
- return [4 /*yield*/, serverSideTranslations(locale, componentDirs, {
38032
- i18n: {
38033
- locales: serverRuntimeConfig.i18n.locales,
38034
- defaultLocale: serverRuntimeConfig.i18n.defaultLocale,
38035
- },
38036
- serializeConfig: false,
38037
- localePath: serverRuntimeConfig.localePath,
38038
- })];
38039
- case 3: return [2 /*return*/, (_d.props = __assign.apply(void 0, [__assign.apply(void 0, _b.concat([(_f.sent())])), provider.nextPageData.props]),
38071
+ return [4 /*yield*/, serverSideTranslations(routing.locale, componentDirs, isLocal
38072
+ ? undefined
38073
+ : {
38074
+ i18n: {
38075
+ locales: routingLocales,
38076
+ defaultLocale: defaultRoutingLocale,
38077
+ },
38078
+ serializeConfig: false,
38079
+ localePath: nextI18nConf.localePath,
38080
+ })];
38081
+ case 4: return [2 /*return*/, (_d.props = __assign.apply(void 0, [__assign.apply(void 0, _b.concat([(_f.sent())])), provider.nextPageData.props]),
38040
38082
  _d)];
38041
- case 4:
38083
+ case 5:
38042
38084
  _e = {};
38043
38085
  _c = [{}];
38044
- return [4 /*yield*/, serverSideTranslations(locale, componentDirs, {
38045
- i18n: {
38046
- locales: serverRuntimeConfig.i18n.locales,
38047
- defaultLocale: serverRuntimeConfig.i18n.defaultLocale,
38048
- },
38049
- serializeConfig: false,
38050
- localePath: serverRuntimeConfig.localePath,
38051
- })];
38052
- case 5: return [2 /*return*/, (_e.props = __assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_f.sent())])), provider.nextPageData.props]),
38086
+ return [4 /*yield*/, serverSideTranslations(routing.locale, componentDirs, isLocal
38087
+ ? undefined
38088
+ : {
38089
+ i18n: {
38090
+ locales: routingLocales,
38091
+ defaultLocale: defaultRoutingLocale,
38092
+ },
38093
+ serializeConfig: false,
38094
+ localePath: nextI18nConf.localePath,
38095
+ })];
38096
+ case 6: return [2 /*return*/, (_e.props = __assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_f.sent())])), provider.nextPageData.props]),
38053
38097
  _e.revalidate = 60,
38054
38098
  _e)];
38055
38099
  }
38056
38100
  });
38057
38101
  });
38058
38102
  };
38059
- SettingsHelper.getStaticProps = function (context, pageType, possiblePageTypes) {
38103
+ SettingsHelper.getStaticProps = function (context, pageType, possiblePageTypes, isEditor) {
38060
38104
  return __awaiter(this, void 0, void 0, function () {
38061
38105
  return __generator(this, function (_a) {
38062
38106
  switch (_a.label) {
38063
- case 0: return [4 /*yield*/, SettingsHelper.getPageData(context, false, pageType, possiblePageTypes)];
38107
+ case 0: return [4 /*yield*/, SettingsHelper.getPageData(context, false, pageType, possiblePageTypes, isEditor)];
38064
38108
  case 1: return [2 /*return*/, _a.sent()];
38065
38109
  }
38066
38110
  });
@@ -38290,16 +38334,17 @@ var CheckoutPage = function (_a) {
38290
38334
  };
38291
38335
  var _id_ = observer(CheckoutPage);
38292
38336
  var getServerSideProps = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38293
- var id, locale, settings, storefront, themeLocalization, salesChannel, routing, redirect, checkout, checkoutSettings;
38294
- var _a;
38295
- return __generator(this, function (_b) {
38296
- switch (_b.label) {
38337
+ var id, locale, settings, storefront, themeLocalization, salesChannel, routing, redirect, checkout, checkoutSettings, componentDirs, isLocal, serverRuntimeConfig, routingLocales, defaultRoutingLocale, nextI18nConf, _a;
38338
+ var _b;
38339
+ var _c;
38340
+ return __generator(this, function (_d) {
38341
+ switch (_d.label) {
38297
38342
  case 0:
38298
38343
  id = context.query.id;
38299
38344
  locale = context.locale || context.defaultLocale || "en";
38300
38345
  return [4 /*yield*/, SettingsHelper.getSettings(locale)];
38301
38346
  case 1:
38302
- settings = _b.sent();
38347
+ settings = _d.sent();
38303
38348
  // TODO maybe remove this and convert this page to static
38304
38349
  if (!settings ||
38305
38350
  !settings.storefront.mainStorefrontThemeId ||
@@ -38315,7 +38360,7 @@ var getServerSideProps = function (context) { return __awaiter(void 0, void 0, v
38315
38360
  IkasStorefrontConfig.storefrontThemeId = storefront.mainStorefrontThemeId;
38316
38361
  IkasStorefrontConfig.salesChannelId = storefront.salesChannelId;
38317
38362
  IkasStorefrontConfig.priceListId = routing.priceListId || undefined;
38318
- IkasStorefrontConfig.stockLocationIds = (_a = salesChannel.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return sl.id; });
38363
+ IkasStorefrontConfig.stockLocationIds = (_c = salesChannel.stockLocations) === null || _c === void 0 ? void 0 : _c.map(function (sl) { return sl.id; });
38319
38364
  IkasStorefrontConfig.routings = storefront.routings;
38320
38365
  IkasStorefrontConfig.paymentGateways = salesChannel.paymentGateways || [];
38321
38366
  IkasStorefrontConfig.gtmId = storefront.gtmId || undefined;
@@ -38331,24 +38376,33 @@ var getServerSideProps = function (context) { return __awaiter(void 0, void 0, v
38331
38376
  }
38332
38377
  return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(id)];
38333
38378
  case 2:
38334
- checkout = _b.sent();
38335
- if (!checkout) return [3 /*break*/, 4];
38379
+ checkout = _d.sent();
38380
+ if (!checkout) return [3 /*break*/, 5];
38336
38381
  return [4 /*yield*/, IkasCheckoutAPI.listCheckoutSettings()];
38337
38382
  case 3:
38338
- checkoutSettings = _b.sent();
38339
- return [2 /*return*/, {
38340
- props: {
38341
- checkoutStr: JSON.stringify(checkout),
38342
- checkoutSettingsStr: (checkoutSettings === null || checkoutSettings === void 0 ? void 0 : checkoutSettings.length) ? JSON.stringify(checkoutSettings[0])
38343
- : null,
38344
- configJson: IkasStorefrontConfig.getJson(),
38345
- returnPolicy: themeLocalization.returnPolicy || "",
38346
- privacyPolicy: themeLocalization.privacyPolicy || "",
38347
- termsOfService: themeLocalization.termsOfService || "",
38348
- queryParams: context.query,
38349
- },
38350
- }];
38351
- case 4: return [2 /*return*/, redirect()];
38383
+ checkoutSettings = _d.sent();
38384
+ componentDirs = ["common", "checkout-page"];
38385
+ isLocal = process.env.NEXT_PUBLIC_ENV === "local";
38386
+ serverRuntimeConfig = getConfig().serverRuntimeConfig;
38387
+ routingLocales = uniq_1(storefront.routings.map(function (sr) { return sr.locale; }));
38388
+ defaultRoutingLocale = routing.locale;
38389
+ nextI18nConf = serverRuntimeConfig.nextI18nConf;
38390
+ _b = {};
38391
+ _a = [{}];
38392
+ return [4 /*yield*/, serverSideTranslations(routing.locale, componentDirs, isLocal
38393
+ ? undefined
38394
+ : {
38395
+ i18n: {
38396
+ locales: routingLocales,
38397
+ defaultLocale: defaultRoutingLocale,
38398
+ },
38399
+ serializeConfig: false,
38400
+ localePath: nextI18nConf.localePath,
38401
+ })];
38402
+ case 4: return [2 /*return*/, (_b.props = __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_d.sent())])), { checkoutStr: JSON.stringify(checkout), checkoutSettingsStr: (checkoutSettings === null || checkoutSettings === void 0 ? void 0 : checkoutSettings.length) ? JSON.stringify(checkoutSettings[0])
38403
+ : null, configJson: IkasStorefrontConfig.getJson(), returnPolicy: themeLocalization.returnPolicy || "", privacyPolicy: themeLocalization.privacyPolicy || "", termsOfService: themeLocalization.termsOfService || "", queryParams: context.query }]),
38404
+ _b)];
38405
+ case 5: return [2 /*return*/, redirect()];
38352
38406
  }
38353
38407
  });
38354
38408
  }); };
@@ -38583,10 +38637,19 @@ var IkasPageEditor$1 = dynamic(function () { return Promise.resolve().then(funct
38583
38637
  var Page$c = function () {
38584
38638
  return createElement(IkasPageEditor$1, null);
38585
38639
  };
38640
+ var getStaticProps$b = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38641
+ return __generator(this, function (_a) {
38642
+ switch (_a.label) {
38643
+ case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, undefined, undefined, true)];
38644
+ case 1: return [2 /*return*/, _a.sent()];
38645
+ }
38646
+ });
38647
+ }); };
38586
38648
  var editor = observer(Page$c);
38587
38649
 
38588
38650
  var editor$1 = /*#__PURE__*/Object.freeze({
38589
38651
  __proto__: null,
38652
+ getStaticProps: getStaticProps$b,
38590
38653
  'default': editor
38591
38654
  });
38592
38655
 
@@ -38599,7 +38662,7 @@ var Page$d = function (_a) {
38599
38662
  }, [propValuesStr]);
38600
38663
  return (createElement(IkasPage, { settingsStr: settingsStr, page: page, propValues: propValues }));
38601
38664
  };
38602
- var getStaticProps$b = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38665
+ var getStaticProps$c = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38603
38666
  return __generator(this, function (_a) {
38604
38667
  switch (_a.label) {
38605
38668
  case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, IkasThemePageType.FAVORITE_PRODUCTS)];
@@ -38611,7 +38674,7 @@ var getStaticProps$b = function (context) { return __awaiter(void 0, void 0, voi
38611
38674
  var favoriteProducts = /*#__PURE__*/Object.freeze({
38612
38675
  __proto__: null,
38613
38676
  'default': Page$d,
38614
- getStaticProps: getStaticProps$b
38677
+ getStaticProps: getStaticProps$c
38615
38678
  });
38616
38679
 
38617
38680
  var Page$e = function (_a) {
@@ -38631,7 +38694,7 @@ var Page$e = function (_a) {
38631
38694
  }, [isBrowser, propValuesStr]);
38632
38695
  return (createElement(IkasPage, { merchantSettings: merchantSettings, settingsStr: settingsStr, page: page, propValues: propValues, addOgpMetas: true }));
38633
38696
  };
38634
- var getStaticProps$c = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38697
+ var getStaticProps$d = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38635
38698
  return __generator(this, function (_a) {
38636
38699
  switch (_a.label) {
38637
38700
  case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, IkasThemePageType.SEARCH)];
@@ -38643,7 +38706,7 @@ var getStaticProps$c = function (context) { return __awaiter(void 0, void 0, voi
38643
38706
  var search = /*#__PURE__*/Object.freeze({
38644
38707
  __proto__: null,
38645
38708
  'default': Page$e,
38646
- getStaticProps: getStaticProps$c
38709
+ getStaticProps: getStaticProps$d
38647
38710
  });
38648
38711
 
38649
38712
  var Page$f = function (_a) {
@@ -38657,7 +38720,7 @@ var Page$f = function (_a) {
38657
38720
  }, [propValuesStr]);
38658
38721
  return (createElement(IkasPage, { merchantSettings: merchantSettings, settingsStr: settingsStr, page: page, propValues: propValues }));
38659
38722
  };
38660
- var getStaticProps$d = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38723
+ var getStaticProps$e = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38661
38724
  var props;
38662
38725
  return __generator(this, function (_a) {
38663
38726
  switch (_a.label) {
@@ -38679,7 +38742,7 @@ var getStaticProps$d = function (context) { return __awaiter(void 0, void 0, voi
38679
38742
  var _404 = /*#__PURE__*/Object.freeze({
38680
38743
  __proto__: null,
38681
38744
  'default': Page$f,
38682
- getStaticProps: getStaticProps$d
38745
+ getStaticProps: getStaticProps$e
38683
38746
  });
38684
38747
 
38685
38748
  var Page$g = function (_a) {
@@ -38691,7 +38754,7 @@ var Page$g = function (_a) {
38691
38754
  }, [propValuesStr]);
38692
38755
  return (createElement(IkasPage, { merchantSettings: merchantSettings, settingsStr: settingsStr, page: page, propValues: propValues, addOgpMetas: true }));
38693
38756
  };
38694
- var getStaticProps$e = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38757
+ var getStaticProps$f = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38695
38758
  return __generator(this, function (_a) {
38696
38759
  switch (_a.label) {
38697
38760
  case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, IkasThemePageType.BLOG_INDEX)];
@@ -38703,7 +38766,7 @@ var getStaticProps$e = function (context) { return __awaiter(void 0, void 0, voi
38703
38766
  var index$5 = /*#__PURE__*/Object.freeze({
38704
38767
  __proto__: null,
38705
38768
  'default': Page$g,
38706
- getStaticProps: getStaticProps$e
38769
+ getStaticProps: getStaticProps$f
38707
38770
  });
38708
38771
 
38709
38772
  var Page$h = function (_a) {
@@ -38732,7 +38795,7 @@ var getStaticPaths$2 = function (context) { return __awaiter(void 0, void 0, voi
38732
38795
  }];
38733
38796
  });
38734
38797
  }); };
38735
- var getStaticProps$f = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38798
+ var getStaticProps$g = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38736
38799
  return __generator(this, function (_a) {
38737
38800
  switch (_a.label) {
38738
38801
  case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, undefined, [
@@ -38748,7 +38811,7 @@ var _slug_$2 = /*#__PURE__*/Object.freeze({
38748
38811
  __proto__: null,
38749
38812
  'default': _slug_$1,
38750
38813
  getStaticPaths: getStaticPaths$2,
38751
- getStaticProps: getStaticProps$f
38814
+ getStaticProps: getStaticProps$g
38752
38815
  });
38753
38816
 
38754
38817
  /**
package/build/index.js CHANGED
@@ -9,6 +9,7 @@ var Head = require('next/head');
9
9
  var router = require('next/router');
10
10
  var Link = require('next/link');
11
11
  var NextImage = require('next/image');
12
+ var nextI18next = require('next-i18next');
12
13
  var fs = require('fs');
13
14
  var getConfig = require('next/config');
14
15
  var serverSideTranslations = require('next-i18next/serverSideTranslations');
@@ -37184,6 +37185,7 @@ var PageViewModel = /** @class */ (function () {
37184
37185
  this.hoveredPageComponentId = null;
37185
37186
  this.componentRefs = {};
37186
37187
  this.isLoading = false;
37188
+ this.locale = "en";
37187
37189
  this.pageParams = {};
37188
37190
  this.queryParams = {};
37189
37191
  this.apiKey = null;
@@ -37336,6 +37338,7 @@ var PageViewModel = /** @class */ (function () {
37336
37338
  this.pageParams = data.pageParams;
37337
37339
  this.queryParams = data.queryParams;
37338
37340
  this.apiKey = data.apiKey;
37341
+ this.locale = data.locale || "en";
37339
37342
  apollo.createApolloClient(this.apiKey || undefined);
37340
37343
  window.editorApiKey = data.apiKey;
37341
37344
  return [4 /*yield*/, this.getPagePropValues()];
@@ -37624,7 +37627,13 @@ var overlayStyle = {
37624
37627
  var IkasPageEditor = mobxReactLite.observer(function () {
37625
37628
  var _a, _b, _c;
37626
37629
  var router$1 = router.useRouter();
37630
+ var i18n = nextI18next.useTranslation().i18n;
37627
37631
  var vm = React.useState(function () { return new PageViewModel(router$1); })[0];
37632
+ React.useEffect(function () {
37633
+ if (typeof i18n.changeLanguage === "function") {
37634
+ i18n.changeLanguage(vm.locale);
37635
+ }
37636
+ }, [vm.locale]);
37628
37637
  if (vm.isLoading)
37629
37638
  return null;
37630
37639
  var headerPageComponent = (_a = vm.pageComponents) === null || _a === void 0 ? void 0 : _a.find(function (pc) { var _a, _b; return pc.componentId === ((_b = (_a = vm.theme) === null || _a === void 0 ? void 0 : _a.headerComponent) === null || _b === void 0 ? void 0 : _b.id); });
@@ -37659,6 +37668,30 @@ var index = /*#__PURE__*/Object.freeze({
37659
37668
  Image: Image
37660
37669
  });
37661
37670
 
37671
+ /**
37672
+ * Creates a duplicate-free version of an array, using
37673
+ * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
37674
+ * for equality comparisons, in which only the first occurrence of each element
37675
+ * is kept. The order of result values is determined by the order they occur
37676
+ * in the array.
37677
+ *
37678
+ * @static
37679
+ * @memberOf _
37680
+ * @since 0.1.0
37681
+ * @category Array
37682
+ * @param {Array} array The array to inspect.
37683
+ * @returns {Array} Returns the new duplicate free array.
37684
+ * @example
37685
+ *
37686
+ * _.uniq([2, 1, 2]);
37687
+ * // => [2, 1]
37688
+ */
37689
+ function uniq(array) {
37690
+ return (array && array.length) ? _baseUniq(array) : [];
37691
+ }
37692
+
37693
+ var uniq_1 = uniq;
37694
+
37662
37695
  var IkasStorefrontLocalization = /** @class */ (function () {
37663
37696
  function IkasStorefrontLocalization(data) {
37664
37697
  this.id = data.id || "";
@@ -37945,10 +37978,10 @@ var SettingsHelper = /** @class */ (function () {
37945
37978
  });
37946
37979
  }); });
37947
37980
  };
37948
- SettingsHelper.getPageData = function (context, isServer, pageType, possiblePageTypes) {
37981
+ SettingsHelper.getPageData = function (context, isServer, pageType, possiblePageTypes, isEditor) {
37949
37982
  var _a;
37950
37983
  return __awaiter(this, void 0, void 0, function () {
37951
- var isLocal, locale, serverRuntimeConfig, settings, storefront, themeLocalization, salesChannel, routing, favicon, stockPreference, provider, componentIds, components, componentDirs, _b, _c;
37984
+ var isLocal, locale, serverRuntimeConfig, settings, storefront, themeLocalization, salesChannel, routing, favicon, stockPreference, provider, componentIds, components, componentDirs, nextI18nConf, routingLocales, defaultRoutingLocale, _b, _c;
37952
37985
  var _d, _e;
37953
37986
  return __generator(this, function (_f) {
37954
37987
  switch (_f.label) {
@@ -37988,56 +38021,67 @@ var SettingsHelper = /** @class */ (function () {
37988
38021
  IkasStorefrontConfig.stockPreference = stockPreference || null;
37989
38022
  provider = new IkasPageDataProvider(themeLocalization.themeJson, context.params, pageType);
37990
38023
  provider.possiblePageTypes = possiblePageTypes;
38024
+ if (!!isEditor) return [3 /*break*/, 3];
37991
38025
  return [4 /*yield*/, provider.getPageData()];
37992
38026
  case 2:
37993
38027
  _f.sent();
38028
+ _f.label = 3;
38029
+ case 3:
37994
38030
  if (!provider.page) {
37995
- return [2 /*return*/, {
37996
- props: {},
37997
- notFound: true,
37998
- }];
38031
+ if (!isEditor)
38032
+ return [2 /*return*/, {
38033
+ props: {},
38034
+ notFound: true,
38035
+ }];
37999
38036
  }
38000
- componentIds = provider.page.components.map(function (pc) { return pc.componentId; });
38001
- components = themeLocalization.themeJson.components.filter(function (c) {
38002
- return componentIds.includes(c.id);
38003
- });
38037
+ componentIds = isEditor
38038
+ ? provider.theme.components.map(function (c) { return c.id; })
38039
+ : provider.page.components.map(function (pc) { return pc.componentId; });
38040
+ components = themeLocalization.themeJson.components.filter(function (c) { return isEditor || componentIds.includes(c.id); });
38004
38041
  componentDirs = __spreadArrays(["common"], components.map(function (c) { return c.dir; }));
38005
- if (!isServer) return [3 /*break*/, 4];
38042
+ nextI18nConf = serverRuntimeConfig.nextI18nConf;
38043
+ routingLocales = uniq_1(storefront.routings.map(function (sr) { return sr.locale; }));
38044
+ defaultRoutingLocale = routing.locale;
38045
+ if (!isServer) return [3 /*break*/, 5];
38006
38046
  _d = {};
38007
38047
  _b = [{}];
38008
- return [4 /*yield*/, serverSideTranslations.serverSideTranslations(locale, componentDirs, {
38009
- i18n: {
38010
- locales: serverRuntimeConfig.i18n.locales,
38011
- defaultLocale: serverRuntimeConfig.i18n.defaultLocale,
38012
- },
38013
- serializeConfig: false,
38014
- localePath: serverRuntimeConfig.localePath,
38015
- })];
38016
- case 3: return [2 /*return*/, (_d.props = __assign.apply(void 0, [__assign.apply(void 0, _b.concat([(_f.sent())])), provider.nextPageData.props]),
38048
+ return [4 /*yield*/, serverSideTranslations.serverSideTranslations(routing.locale, componentDirs, isLocal
38049
+ ? undefined
38050
+ : {
38051
+ i18n: {
38052
+ locales: routingLocales,
38053
+ defaultLocale: defaultRoutingLocale,
38054
+ },
38055
+ serializeConfig: false,
38056
+ localePath: nextI18nConf.localePath,
38057
+ })];
38058
+ case 4: return [2 /*return*/, (_d.props = __assign.apply(void 0, [__assign.apply(void 0, _b.concat([(_f.sent())])), provider.nextPageData.props]),
38017
38059
  _d)];
38018
- case 4:
38060
+ case 5:
38019
38061
  _e = {};
38020
38062
  _c = [{}];
38021
- return [4 /*yield*/, serverSideTranslations.serverSideTranslations(locale, componentDirs, {
38022
- i18n: {
38023
- locales: serverRuntimeConfig.i18n.locales,
38024
- defaultLocale: serverRuntimeConfig.i18n.defaultLocale,
38025
- },
38026
- serializeConfig: false,
38027
- localePath: serverRuntimeConfig.localePath,
38028
- })];
38029
- case 5: return [2 /*return*/, (_e.props = __assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_f.sent())])), provider.nextPageData.props]),
38063
+ return [4 /*yield*/, serverSideTranslations.serverSideTranslations(routing.locale, componentDirs, isLocal
38064
+ ? undefined
38065
+ : {
38066
+ i18n: {
38067
+ locales: routingLocales,
38068
+ defaultLocale: defaultRoutingLocale,
38069
+ },
38070
+ serializeConfig: false,
38071
+ localePath: nextI18nConf.localePath,
38072
+ })];
38073
+ case 6: return [2 /*return*/, (_e.props = __assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_f.sent())])), provider.nextPageData.props]),
38030
38074
  _e.revalidate = 60,
38031
38075
  _e)];
38032
38076
  }
38033
38077
  });
38034
38078
  });
38035
38079
  };
38036
- SettingsHelper.getStaticProps = function (context, pageType, possiblePageTypes) {
38080
+ SettingsHelper.getStaticProps = function (context, pageType, possiblePageTypes, isEditor) {
38037
38081
  return __awaiter(this, void 0, void 0, function () {
38038
38082
  return __generator(this, function (_a) {
38039
38083
  switch (_a.label) {
38040
- case 0: return [4 /*yield*/, SettingsHelper.getPageData(context, false, pageType, possiblePageTypes)];
38084
+ case 0: return [4 /*yield*/, SettingsHelper.getPageData(context, false, pageType, possiblePageTypes, isEditor)];
38041
38085
  case 1: return [2 /*return*/, _a.sent()];
38042
38086
  }
38043
38087
  });
@@ -38267,16 +38311,17 @@ var CheckoutPage = function (_a) {
38267
38311
  };
38268
38312
  var _id_ = mobxReactLite.observer(CheckoutPage);
38269
38313
  var getServerSideProps = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38270
- var id, locale, settings, storefront, themeLocalization, salesChannel, routing, redirect, checkout, checkoutSettings;
38271
- var _a;
38272
- return __generator(this, function (_b) {
38273
- switch (_b.label) {
38314
+ var id, locale, settings, storefront, themeLocalization, salesChannel, routing, redirect, checkout, checkoutSettings, componentDirs, isLocal, serverRuntimeConfig, routingLocales, defaultRoutingLocale, nextI18nConf, _a;
38315
+ var _b;
38316
+ var _c;
38317
+ return __generator(this, function (_d) {
38318
+ switch (_d.label) {
38274
38319
  case 0:
38275
38320
  id = context.query.id;
38276
38321
  locale = context.locale || context.defaultLocale || "en";
38277
38322
  return [4 /*yield*/, SettingsHelper.getSettings(locale)];
38278
38323
  case 1:
38279
- settings = _b.sent();
38324
+ settings = _d.sent();
38280
38325
  // TODO maybe remove this and convert this page to static
38281
38326
  if (!settings ||
38282
38327
  !settings.storefront.mainStorefrontThemeId ||
@@ -38292,7 +38337,7 @@ var getServerSideProps = function (context) { return __awaiter(void 0, void 0, v
38292
38337
  IkasStorefrontConfig.storefrontThemeId = storefront.mainStorefrontThemeId;
38293
38338
  IkasStorefrontConfig.salesChannelId = storefront.salesChannelId;
38294
38339
  IkasStorefrontConfig.priceListId = routing.priceListId || undefined;
38295
- IkasStorefrontConfig.stockLocationIds = (_a = salesChannel.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return sl.id; });
38340
+ IkasStorefrontConfig.stockLocationIds = (_c = salesChannel.stockLocations) === null || _c === void 0 ? void 0 : _c.map(function (sl) { return sl.id; });
38296
38341
  IkasStorefrontConfig.routings = storefront.routings;
38297
38342
  IkasStorefrontConfig.paymentGateways = salesChannel.paymentGateways || [];
38298
38343
  IkasStorefrontConfig.gtmId = storefront.gtmId || undefined;
@@ -38308,24 +38353,33 @@ var getServerSideProps = function (context) { return __awaiter(void 0, void 0, v
38308
38353
  }
38309
38354
  return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(id)];
38310
38355
  case 2:
38311
- checkout = _b.sent();
38312
- if (!checkout) return [3 /*break*/, 4];
38356
+ checkout = _d.sent();
38357
+ if (!checkout) return [3 /*break*/, 5];
38313
38358
  return [4 /*yield*/, IkasCheckoutAPI.listCheckoutSettings()];
38314
38359
  case 3:
38315
- checkoutSettings = _b.sent();
38316
- return [2 /*return*/, {
38317
- props: {
38318
- checkoutStr: JSON.stringify(checkout),
38319
- checkoutSettingsStr: (checkoutSettings === null || checkoutSettings === void 0 ? void 0 : checkoutSettings.length) ? JSON.stringify(checkoutSettings[0])
38320
- : null,
38321
- configJson: IkasStorefrontConfig.getJson(),
38322
- returnPolicy: themeLocalization.returnPolicy || "",
38323
- privacyPolicy: themeLocalization.privacyPolicy || "",
38324
- termsOfService: themeLocalization.termsOfService || "",
38325
- queryParams: context.query,
38326
- },
38327
- }];
38328
- case 4: return [2 /*return*/, redirect()];
38360
+ checkoutSettings = _d.sent();
38361
+ componentDirs = ["common", "checkout-page"];
38362
+ isLocal = process.env.NEXT_PUBLIC_ENV === "local";
38363
+ serverRuntimeConfig = getConfig__default['default']().serverRuntimeConfig;
38364
+ routingLocales = uniq_1(storefront.routings.map(function (sr) { return sr.locale; }));
38365
+ defaultRoutingLocale = routing.locale;
38366
+ nextI18nConf = serverRuntimeConfig.nextI18nConf;
38367
+ _b = {};
38368
+ _a = [{}];
38369
+ return [4 /*yield*/, serverSideTranslations.serverSideTranslations(routing.locale, componentDirs, isLocal
38370
+ ? undefined
38371
+ : {
38372
+ i18n: {
38373
+ locales: routingLocales,
38374
+ defaultLocale: defaultRoutingLocale,
38375
+ },
38376
+ serializeConfig: false,
38377
+ localePath: nextI18nConf.localePath,
38378
+ })];
38379
+ case 4: return [2 /*return*/, (_b.props = __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_d.sent())])), { checkoutStr: JSON.stringify(checkout), checkoutSettingsStr: (checkoutSettings === null || checkoutSettings === void 0 ? void 0 : checkoutSettings.length) ? JSON.stringify(checkoutSettings[0])
38380
+ : null, configJson: IkasStorefrontConfig.getJson(), returnPolicy: themeLocalization.returnPolicy || "", privacyPolicy: themeLocalization.privacyPolicy || "", termsOfService: themeLocalization.termsOfService || "", queryParams: context.query }]),
38381
+ _b)];
38382
+ case 5: return [2 /*return*/, redirect()];
38329
38383
  }
38330
38384
  });
38331
38385
  }); };
@@ -38560,10 +38614,19 @@ var IkasPageEditor$1 = dynamic__default['default'](function () { return Promise.
38560
38614
  var Page$c = function () {
38561
38615
  return React.createElement(IkasPageEditor$1, null);
38562
38616
  };
38617
+ var getStaticProps$b = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38618
+ return __generator(this, function (_a) {
38619
+ switch (_a.label) {
38620
+ case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, undefined, undefined, true)];
38621
+ case 1: return [2 /*return*/, _a.sent()];
38622
+ }
38623
+ });
38624
+ }); };
38563
38625
  var editor = mobxReactLite.observer(Page$c);
38564
38626
 
38565
38627
  var editor$1 = /*#__PURE__*/Object.freeze({
38566
38628
  __proto__: null,
38629
+ getStaticProps: getStaticProps$b,
38567
38630
  'default': editor
38568
38631
  });
38569
38632
 
@@ -38576,7 +38639,7 @@ var Page$d = function (_a) {
38576
38639
  }, [propValuesStr]);
38577
38640
  return (React.createElement(IkasPage, { settingsStr: settingsStr, page: page, propValues: propValues }));
38578
38641
  };
38579
- var getStaticProps$b = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38642
+ var getStaticProps$c = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38580
38643
  return __generator(this, function (_a) {
38581
38644
  switch (_a.label) {
38582
38645
  case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, exports.IkasThemePageType.FAVORITE_PRODUCTS)];
@@ -38588,7 +38651,7 @@ var getStaticProps$b = function (context) { return __awaiter(void 0, void 0, voi
38588
38651
  var favoriteProducts = /*#__PURE__*/Object.freeze({
38589
38652
  __proto__: null,
38590
38653
  'default': Page$d,
38591
- getStaticProps: getStaticProps$b
38654
+ getStaticProps: getStaticProps$c
38592
38655
  });
38593
38656
 
38594
38657
  var Page$e = function (_a) {
@@ -38608,7 +38671,7 @@ var Page$e = function (_a) {
38608
38671
  }, [isBrowser, propValuesStr]);
38609
38672
  return (React.createElement(IkasPage, { merchantSettings: merchantSettings, settingsStr: settingsStr, page: page, propValues: propValues, addOgpMetas: true }));
38610
38673
  };
38611
- var getStaticProps$c = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38674
+ var getStaticProps$d = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38612
38675
  return __generator(this, function (_a) {
38613
38676
  switch (_a.label) {
38614
38677
  case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, exports.IkasThemePageType.SEARCH)];
@@ -38620,7 +38683,7 @@ var getStaticProps$c = function (context) { return __awaiter(void 0, void 0, voi
38620
38683
  var search = /*#__PURE__*/Object.freeze({
38621
38684
  __proto__: null,
38622
38685
  'default': Page$e,
38623
- getStaticProps: getStaticProps$c
38686
+ getStaticProps: getStaticProps$d
38624
38687
  });
38625
38688
 
38626
38689
  var Page$f = function (_a) {
@@ -38634,7 +38697,7 @@ var Page$f = function (_a) {
38634
38697
  }, [propValuesStr]);
38635
38698
  return (React.createElement(IkasPage, { merchantSettings: merchantSettings, settingsStr: settingsStr, page: page, propValues: propValues }));
38636
38699
  };
38637
- var getStaticProps$d = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38700
+ var getStaticProps$e = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38638
38701
  var props;
38639
38702
  return __generator(this, function (_a) {
38640
38703
  switch (_a.label) {
@@ -38656,7 +38719,7 @@ var getStaticProps$d = function (context) { return __awaiter(void 0, void 0, voi
38656
38719
  var _404 = /*#__PURE__*/Object.freeze({
38657
38720
  __proto__: null,
38658
38721
  'default': Page$f,
38659
- getStaticProps: getStaticProps$d
38722
+ getStaticProps: getStaticProps$e
38660
38723
  });
38661
38724
 
38662
38725
  var Page$g = function (_a) {
@@ -38668,7 +38731,7 @@ var Page$g = function (_a) {
38668
38731
  }, [propValuesStr]);
38669
38732
  return (React.createElement(IkasPage, { merchantSettings: merchantSettings, settingsStr: settingsStr, page: page, propValues: propValues, addOgpMetas: true }));
38670
38733
  };
38671
- var getStaticProps$e = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38734
+ var getStaticProps$f = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38672
38735
  return __generator(this, function (_a) {
38673
38736
  switch (_a.label) {
38674
38737
  case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, exports.IkasThemePageType.BLOG_INDEX)];
@@ -38680,7 +38743,7 @@ var getStaticProps$e = function (context) { return __awaiter(void 0, void 0, voi
38680
38743
  var index$5 = /*#__PURE__*/Object.freeze({
38681
38744
  __proto__: null,
38682
38745
  'default': Page$g,
38683
- getStaticProps: getStaticProps$e
38746
+ getStaticProps: getStaticProps$f
38684
38747
  });
38685
38748
 
38686
38749
  var Page$h = function (_a) {
@@ -38709,7 +38772,7 @@ var getStaticPaths$2 = function (context) { return __awaiter(void 0, void 0, voi
38709
38772
  }];
38710
38773
  });
38711
38774
  }); };
38712
- var getStaticProps$f = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38775
+ var getStaticProps$g = function (context) { return __awaiter(void 0, void 0, void 0, function () {
38713
38776
  return __generator(this, function (_a) {
38714
38777
  switch (_a.label) {
38715
38778
  case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, undefined, [
@@ -38725,7 +38788,7 @@ var _slug_$2 = /*#__PURE__*/Object.freeze({
38725
38788
  __proto__: null,
38726
38789
  'default': _slug_$1,
38727
38790
  getStaticPaths: getStaticPaths$2,
38728
- getStaticProps: getStaticProps$f
38791
+ getStaticProps: getStaticProps$g
38729
38792
  });
38730
38793
 
38731
38794
  /**
@@ -1,4 +1,6 @@
1
1
  /// <reference types="react" />
2
+ import { GetStaticProps } from "next";
3
+ export declare const getStaticProps: GetStaticProps;
2
4
  declare const _default: (() => JSX.Element) & {
3
5
  displayName: string;
4
6
  };
@@ -12,7 +12,7 @@ export declare class SettingsHelper {
12
12
  static readLocalTheme(): Promise<IkasTheme>;
13
13
  static readSettingsFile(): Promise<any>;
14
14
  static getSettings(locale: string): Promise<SettingsData | null>;
15
- static getPageData(context: GetStaticPropsContext<ParsedUrlQuery> | GetServerSidePropsContext<ParsedUrlQuery>, isServer: boolean, pageType?: IkasThemePageType, possiblePageTypes?: IkasThemePageType[]): Promise<{
15
+ static getPageData(context: GetStaticPropsContext<ParsedUrlQuery> | GetServerSidePropsContext<ParsedUrlQuery>, isServer: boolean, pageType?: IkasThemePageType, possiblePageTypes?: IkasThemePageType[], isEditor?: boolean): Promise<{
16
16
  props: {};
17
17
  notFound: boolean;
18
18
  revalidate?: undefined;
@@ -75,7 +75,7 @@ export declare class SettingsHelper {
75
75
  revalidate: number;
76
76
  notFound?: undefined;
77
77
  }>;
78
- static getStaticProps(context: GetStaticPropsContext<ParsedUrlQuery>, pageType?: IkasThemePageType, possiblePageTypes?: IkasThemePageType[]): Promise<{
78
+ static getStaticProps(context: GetStaticPropsContext<ParsedUrlQuery>, pageType?: IkasThemePageType, possiblePageTypes?: IkasThemePageType[], isEditor?: boolean): Promise<{
79
79
  props: {};
80
80
  notFound: boolean;
81
81
  revalidate?: undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "0.0.161-alpha.9",
3
+ "version": "0.0.162-alpha.1",
4
4
  "main": "./build/index.js",
5
5
  "module": "./build/index.es.js",
6
6
  "author": "Umut Ozan Yıldırım",