@ikas/storefront 0.0.97 → 0.0.99

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/index.es.js CHANGED
@@ -28275,7 +28275,9 @@ var IkasStorefrontThemeLocalization = /** @class */ (function () {
28275
28275
  this.locale = data.locale || "";
28276
28276
  this.storefrontId = data.storefrontId || "";
28277
28277
  this.storefrontThemeId = data.storefrontThemeId || "";
28278
- this.themeJson = data.themeJson || "";
28278
+ this.themeJson = data.themeJson
28279
+ ? new IkasTheme(data.themeJson)
28280
+ : new IkasTheme();
28279
28281
  this.privacyPolicy = data.privacyPolicy || null;
28280
28282
  this.returnPolicy = data.returnPolicy || null;
28281
28283
  this.termsOfService = data.termsOfService || null;
@@ -28342,38 +28344,68 @@ var IkasSalesChannelStockLocation = /** @class */ (function () {
28342
28344
  var SettingsHelper = /** @class */ (function () {
28343
28345
  function SettingsHelper() {
28344
28346
  }
28345
- SettingsHelper.getSettings = function (locale) {
28347
+ SettingsHelper.readSettingsFile = function () {
28346
28348
  return new Promise(function (resolve) {
28347
28349
  var serverRuntimeConfig = getConfig().serverRuntimeConfig;
28348
- var settings = serverRuntimeConfig.SETTINGS;
28349
- var storefront = new IkasStorefront(settings.storefront);
28350
- var salesChannel = new IkasSalesChannel(settings.salesChannel);
28351
- var localizationMap = settings.localizationMap;
28352
- var themeJSONPath = localizationMap[locale];
28353
- var routing = storefront.routings.find(function (r) { return r.id === locale || r.path === locale; });
28354
- if (!themeJSONPath || !routing) {
28355
- return resolve(null);
28356
- }
28357
- fs.readFile(themeJSONPath, {
28350
+ var settingsPath = serverRuntimeConfig.SETTINGS;
28351
+ fs.readFile(settingsPath, {
28358
28352
  flag: "a+",
28359
28353
  }, function (err, file) {
28360
28354
  if (err) {
28355
+ console.error("SETTINGS FILE READ ERROR!!!");
28356
+ console.error(err);
28361
28357
  return resolve(null);
28362
28358
  }
28363
28359
  var result = file.length ? JSON.parse(file.toString()) : {};
28364
- resolve({
28365
- storefront: storefront,
28366
- theme: new IkasTheme(result),
28367
- salesChannel: salesChannel,
28368
- routing: routing,
28369
- });
28360
+ resolve(result);
28370
28361
  });
28371
28362
  });
28372
28363
  };
28364
+ SettingsHelper.getSettings = function (locale) {
28365
+ var _this = this;
28366
+ return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
28367
+ var settings, storefront, salesChannel, localizationMap, themeJSONPath, routing;
28368
+ return __generator(this, function (_a) {
28369
+ switch (_a.label) {
28370
+ case 0: return [4 /*yield*/, SettingsHelper.readSettingsFile()];
28371
+ case 1:
28372
+ settings = _a.sent();
28373
+ if (!settings)
28374
+ return [2 /*return*/, resolve(null)];
28375
+ storefront = new IkasStorefront(settings.storefront);
28376
+ salesChannel = new IkasSalesChannel(settings.salesChannel);
28377
+ localizationMap = settings.localizationMap;
28378
+ themeJSONPath = localizationMap[locale];
28379
+ routing = storefront.routings.find(function (r) { return r.id === locale || r.path === locale; });
28380
+ if (!themeJSONPath || !routing) {
28381
+ console.error("THEMEJSONPATH OR ROUTING MISSING!!!");
28382
+ return [2 /*return*/, resolve(null)];
28383
+ }
28384
+ fs.readFile(themeJSONPath, {
28385
+ flag: "a+",
28386
+ }, function (err, file) {
28387
+ if (err) {
28388
+ console.error("THEMEJSON FILE RED ERROR!!!");
28389
+ console.error(err);
28390
+ return resolve(null);
28391
+ }
28392
+ var result = file.length ? JSON.parse(file.toString()) : {};
28393
+ resolve({
28394
+ storefront: storefront,
28395
+ themeLocalization: new IkasStorefrontThemeLocalization(result),
28396
+ salesChannel: salesChannel,
28397
+ routing: routing,
28398
+ });
28399
+ });
28400
+ return [2 /*return*/];
28401
+ }
28402
+ });
28403
+ }); });
28404
+ };
28373
28405
  SettingsHelper.getPageData = function (context, isServer, pageType) {
28374
28406
  var _a;
28375
28407
  return __awaiter(this, void 0, void 0, function () {
28376
- var locale, settings, storefront, theme, salesChannel, routing, provider;
28408
+ var locale, settings, storefront, themeLocalization, salesChannel, routing, provider;
28377
28409
  return __generator(this, function (_b) {
28378
28410
  switch (_b.label) {
28379
28411
  case 0:
@@ -28389,14 +28421,14 @@ var SettingsHelper = /** @class */ (function () {
28389
28421
  notFound: true,
28390
28422
  }];
28391
28423
  }
28392
- storefront = settings.storefront, theme = settings.theme, salesChannel = settings.salesChannel, routing = settings.routing;
28424
+ storefront = settings.storefront, themeLocalization = settings.themeLocalization, salesChannel = settings.salesChannel, routing = settings.routing;
28393
28425
  IkasStorefrontConfig.storefrontId = storefront.id;
28394
28426
  IkasStorefrontConfig.storefrontRoutingId = routing.id;
28395
28427
  IkasStorefrontConfig.storefrontThemeId = storefront.mainStorefrontThemeId;
28396
28428
  IkasStorefrontConfig.salesChannelId = storefront.salesChannelId;
28397
28429
  IkasStorefrontConfig.priceListId = routing.priceListId || undefined;
28398
28430
  IkasStorefrontConfig.stockLocationIds = (_a = salesChannel.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return sl.id; });
28399
- provider = new IkasPageDataProvider(theme, context.params, pageType);
28431
+ provider = new IkasPageDataProvider(themeLocalization.themeJson, context.params, pageType);
28400
28432
  return [4 /*yield*/, provider.getPageData()];
28401
28433
  case 2:
28402
28434
  _b.sent();
@@ -28603,10 +28635,10 @@ var getStaticPaths$1 = function (context) { return __awaiter(void 0, void 0, voi
28603
28635
  allSettings = (_a.sent());
28604
28636
  customPagePaths = [];
28605
28637
  allSettings.forEach(function (_a) {
28606
- var theme = _a.theme, routing = _a.routing;
28607
- if (!theme)
28638
+ var themeLocalization = _a.themeLocalization, routing = _a.routing;
28639
+ if (!themeLocalization)
28608
28640
  return;
28609
- var customPages = theme.pages.filter(function (p) { return p.type === IkasThemePageType.CUSTOM; });
28641
+ var customPages = themeLocalization.themeJson.pages.filter(function (p) { return p.type === IkasThemePageType.CUSTOM; });
28610
28642
  customPages.forEach(function (customPage) {
28611
28643
  if (customPage.slug &&
28612
28644
  !customPagePaths.some(function (p) { return p.params.slug === customPage.slug; })) {
@@ -28651,7 +28683,7 @@ var CheckoutPage = function (_a) {
28651
28683
  };
28652
28684
  var _id_ = observer(CheckoutPage);
28653
28685
  var getServerSideProps = function (context) { return __awaiter(void 0, void 0, void 0, function () {
28654
- var id, locale, settings, storefront, routing, redirect, checkout, region;
28686
+ var id, locale, settings, storefront, themeLocalization, routing, redirect, checkout;
28655
28687
  return __generator(this, function (_a) {
28656
28688
  switch (_a.label) {
28657
28689
  case 0:
@@ -28663,19 +28695,17 @@ var getServerSideProps = function (context) { return __awaiter(void 0, void 0, v
28663
28695
  // TODO maybe remove this and convert this page to static
28664
28696
  if (!settings ||
28665
28697
  !settings.storefront.mainStorefrontThemeId ||
28666
- !settings.storefront.salesChannelId ||
28667
- !settings.routing.priceListId) {
28698
+ !settings.storefront.salesChannelId) {
28668
28699
  return [2 /*return*/, {
28669
28700
  props: {},
28670
28701
  notFound: true,
28671
28702
  }];
28672
28703
  }
28673
- storefront = settings.storefront, routing = settings.routing;
28704
+ storefront = settings.storefront, themeLocalization = settings.themeLocalization, routing = settings.routing;
28674
28705
  IkasStorefrontConfig.storefrontId = storefront.id;
28675
28706
  IkasStorefrontConfig.storefrontRoutingId = routing.id;
28676
28707
  IkasStorefrontConfig.storefrontThemeId = storefront.mainStorefrontThemeId;
28677
28708
  IkasStorefrontConfig.salesChannelId = storefront.salesChannelId;
28678
- IkasStorefrontConfig.priceListId = routing.priceListId;
28679
28709
  redirect = function () {
28680
28710
  context.res.writeHead(302, { Location: "/" });
28681
28711
  context.res.end();
@@ -28688,13 +28718,12 @@ var getServerSideProps = function (context) { return __awaiter(void 0, void 0, v
28688
28718
  case 2:
28689
28719
  checkout = _a.sent();
28690
28720
  if (checkout) {
28691
- region = settings.storefront.regions.find(function (r) { return r.id === storefront.mainStorefrontThemeId; });
28692
28721
  return [2 /*return*/, {
28693
28722
  props: {
28694
28723
  checkoutStr: JSON.stringify(checkout),
28695
- returnPolicy: (region === null || region === void 0 ? void 0 : region.returnPolicy) || "",
28696
- privacyPolicy: (region === null || region === void 0 ? void 0 : region.privacyPolicy) || "",
28697
- termsOfService: (region === null || region === void 0 ? void 0 : region.termsOfService) || "",
28724
+ returnPolicy: themeLocalization.returnPolicy || "",
28725
+ privacyPolicy: themeLocalization.privacyPolicy || "",
28726
+ termsOfService: themeLocalization.termsOfService || "",
28698
28727
  queryParams: context.query,
28699
28728
  },
28700
28729
  }];
package/build/index.js CHANGED
@@ -28255,7 +28255,9 @@ var IkasStorefrontThemeLocalization = /** @class */ (function () {
28255
28255
  this.locale = data.locale || "";
28256
28256
  this.storefrontId = data.storefrontId || "";
28257
28257
  this.storefrontThemeId = data.storefrontThemeId || "";
28258
- this.themeJson = data.themeJson || "";
28258
+ this.themeJson = data.themeJson
28259
+ ? new IkasTheme(data.themeJson)
28260
+ : new IkasTheme();
28259
28261
  this.privacyPolicy = data.privacyPolicy || null;
28260
28262
  this.returnPolicy = data.returnPolicy || null;
28261
28263
  this.termsOfService = data.termsOfService || null;
@@ -28322,38 +28324,68 @@ var IkasSalesChannelStockLocation = /** @class */ (function () {
28322
28324
  var SettingsHelper = /** @class */ (function () {
28323
28325
  function SettingsHelper() {
28324
28326
  }
28325
- SettingsHelper.getSettings = function (locale) {
28327
+ SettingsHelper.readSettingsFile = function () {
28326
28328
  return new Promise(function (resolve) {
28327
28329
  var serverRuntimeConfig = getConfig__default['default']().serverRuntimeConfig;
28328
- var settings = serverRuntimeConfig.SETTINGS;
28329
- var storefront = new IkasStorefront(settings.storefront);
28330
- var salesChannel = new IkasSalesChannel(settings.salesChannel);
28331
- var localizationMap = settings.localizationMap;
28332
- var themeJSONPath = localizationMap[locale];
28333
- var routing = storefront.routings.find(function (r) { return r.id === locale || r.path === locale; });
28334
- if (!themeJSONPath || !routing) {
28335
- return resolve(null);
28336
- }
28337
- fs__default['default'].readFile(themeJSONPath, {
28330
+ var settingsPath = serverRuntimeConfig.SETTINGS;
28331
+ fs__default['default'].readFile(settingsPath, {
28338
28332
  flag: "a+",
28339
28333
  }, function (err, file) {
28340
28334
  if (err) {
28335
+ console.error("SETTINGS FILE READ ERROR!!!");
28336
+ console.error(err);
28341
28337
  return resolve(null);
28342
28338
  }
28343
28339
  var result = file.length ? JSON.parse(file.toString()) : {};
28344
- resolve({
28345
- storefront: storefront,
28346
- theme: new IkasTheme(result),
28347
- salesChannel: salesChannel,
28348
- routing: routing,
28349
- });
28340
+ resolve(result);
28350
28341
  });
28351
28342
  });
28352
28343
  };
28344
+ SettingsHelper.getSettings = function (locale) {
28345
+ var _this = this;
28346
+ return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
28347
+ var settings, storefront, salesChannel, localizationMap, themeJSONPath, routing;
28348
+ return __generator(this, function (_a) {
28349
+ switch (_a.label) {
28350
+ case 0: return [4 /*yield*/, SettingsHelper.readSettingsFile()];
28351
+ case 1:
28352
+ settings = _a.sent();
28353
+ if (!settings)
28354
+ return [2 /*return*/, resolve(null)];
28355
+ storefront = new IkasStorefront(settings.storefront);
28356
+ salesChannel = new IkasSalesChannel(settings.salesChannel);
28357
+ localizationMap = settings.localizationMap;
28358
+ themeJSONPath = localizationMap[locale];
28359
+ routing = storefront.routings.find(function (r) { return r.id === locale || r.path === locale; });
28360
+ if (!themeJSONPath || !routing) {
28361
+ console.error("THEMEJSONPATH OR ROUTING MISSING!!!");
28362
+ return [2 /*return*/, resolve(null)];
28363
+ }
28364
+ fs__default['default'].readFile(themeJSONPath, {
28365
+ flag: "a+",
28366
+ }, function (err, file) {
28367
+ if (err) {
28368
+ console.error("THEMEJSON FILE RED ERROR!!!");
28369
+ console.error(err);
28370
+ return resolve(null);
28371
+ }
28372
+ var result = file.length ? JSON.parse(file.toString()) : {};
28373
+ resolve({
28374
+ storefront: storefront,
28375
+ themeLocalization: new IkasStorefrontThemeLocalization(result),
28376
+ salesChannel: salesChannel,
28377
+ routing: routing,
28378
+ });
28379
+ });
28380
+ return [2 /*return*/];
28381
+ }
28382
+ });
28383
+ }); });
28384
+ };
28353
28385
  SettingsHelper.getPageData = function (context, isServer, pageType) {
28354
28386
  var _a;
28355
28387
  return __awaiter(this, void 0, void 0, function () {
28356
- var locale, settings, storefront, theme, salesChannel, routing, provider;
28388
+ var locale, settings, storefront, themeLocalization, salesChannel, routing, provider;
28357
28389
  return __generator(this, function (_b) {
28358
28390
  switch (_b.label) {
28359
28391
  case 0:
@@ -28369,14 +28401,14 @@ var SettingsHelper = /** @class */ (function () {
28369
28401
  notFound: true,
28370
28402
  }];
28371
28403
  }
28372
- storefront = settings.storefront, theme = settings.theme, salesChannel = settings.salesChannel, routing = settings.routing;
28404
+ storefront = settings.storefront, themeLocalization = settings.themeLocalization, salesChannel = settings.salesChannel, routing = settings.routing;
28373
28405
  IkasStorefrontConfig.storefrontId = storefront.id;
28374
28406
  IkasStorefrontConfig.storefrontRoutingId = routing.id;
28375
28407
  IkasStorefrontConfig.storefrontThemeId = storefront.mainStorefrontThemeId;
28376
28408
  IkasStorefrontConfig.salesChannelId = storefront.salesChannelId;
28377
28409
  IkasStorefrontConfig.priceListId = routing.priceListId || undefined;
28378
28410
  IkasStorefrontConfig.stockLocationIds = (_a = salesChannel.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return sl.id; });
28379
- provider = new IkasPageDataProvider(theme, context.params, pageType);
28411
+ provider = new IkasPageDataProvider(themeLocalization.themeJson, context.params, pageType);
28380
28412
  return [4 /*yield*/, provider.getPageData()];
28381
28413
  case 2:
28382
28414
  _b.sent();
@@ -28583,10 +28615,10 @@ var getStaticPaths$1 = function (context) { return __awaiter(void 0, void 0, voi
28583
28615
  allSettings = (_a.sent());
28584
28616
  customPagePaths = [];
28585
28617
  allSettings.forEach(function (_a) {
28586
- var theme = _a.theme, routing = _a.routing;
28587
- if (!theme)
28618
+ var themeLocalization = _a.themeLocalization, routing = _a.routing;
28619
+ if (!themeLocalization)
28588
28620
  return;
28589
- var customPages = theme.pages.filter(function (p) { return p.type === exports.IkasThemePageType.CUSTOM; });
28621
+ var customPages = themeLocalization.themeJson.pages.filter(function (p) { return p.type === exports.IkasThemePageType.CUSTOM; });
28590
28622
  customPages.forEach(function (customPage) {
28591
28623
  if (customPage.slug &&
28592
28624
  !customPagePaths.some(function (p) { return p.params.slug === customPage.slug; })) {
@@ -28631,7 +28663,7 @@ var CheckoutPage = function (_a) {
28631
28663
  };
28632
28664
  var _id_ = mobxReactLite.observer(CheckoutPage);
28633
28665
  var getServerSideProps = function (context) { return __awaiter(void 0, void 0, void 0, function () {
28634
- var id, locale, settings, storefront, routing, redirect, checkout, region;
28666
+ var id, locale, settings, storefront, themeLocalization, routing, redirect, checkout;
28635
28667
  return __generator(this, function (_a) {
28636
28668
  switch (_a.label) {
28637
28669
  case 0:
@@ -28643,19 +28675,17 @@ var getServerSideProps = function (context) { return __awaiter(void 0, void 0, v
28643
28675
  // TODO maybe remove this and convert this page to static
28644
28676
  if (!settings ||
28645
28677
  !settings.storefront.mainStorefrontThemeId ||
28646
- !settings.storefront.salesChannelId ||
28647
- !settings.routing.priceListId) {
28678
+ !settings.storefront.salesChannelId) {
28648
28679
  return [2 /*return*/, {
28649
28680
  props: {},
28650
28681
  notFound: true,
28651
28682
  }];
28652
28683
  }
28653
- storefront = settings.storefront, routing = settings.routing;
28684
+ storefront = settings.storefront, themeLocalization = settings.themeLocalization, routing = settings.routing;
28654
28685
  IkasStorefrontConfig.storefrontId = storefront.id;
28655
28686
  IkasStorefrontConfig.storefrontRoutingId = routing.id;
28656
28687
  IkasStorefrontConfig.storefrontThemeId = storefront.mainStorefrontThemeId;
28657
28688
  IkasStorefrontConfig.salesChannelId = storefront.salesChannelId;
28658
- IkasStorefrontConfig.priceListId = routing.priceListId;
28659
28689
  redirect = function () {
28660
28690
  context.res.writeHead(302, { Location: "/" });
28661
28691
  context.res.end();
@@ -28668,13 +28698,12 @@ var getServerSideProps = function (context) { return __awaiter(void 0, void 0, v
28668
28698
  case 2:
28669
28699
  checkout = _a.sent();
28670
28700
  if (checkout) {
28671
- region = settings.storefront.regions.find(function (r) { return r.id === storefront.mainStorefrontThemeId; });
28672
28701
  return [2 /*return*/, {
28673
28702
  props: {
28674
28703
  checkoutStr: JSON.stringify(checkout),
28675
- returnPolicy: (region === null || region === void 0 ? void 0 : region.returnPolicy) || "",
28676
- privacyPolicy: (region === null || region === void 0 ? void 0 : region.privacyPolicy) || "",
28677
- termsOfService: (region === null || region === void 0 ? void 0 : region.termsOfService) || "",
28704
+ returnPolicy: themeLocalization.returnPolicy || "",
28705
+ privacyPolicy: themeLocalization.privacyPolicy || "",
28706
+ termsOfService: themeLocalization.termsOfService || "",
28678
28707
  queryParams: context.query,
28679
28708
  },
28680
28709
  }];
@@ -1,9 +1,10 @@
1
+ import { IkasTheme } from "../../../theme/index";
1
2
  export declare class IkasStorefrontThemeLocalization {
2
3
  id: string;
3
4
  locale: string;
4
5
  storefrontId: string;
5
6
  storefrontThemeId: string;
6
- themeJson: string;
7
+ themeJson: IkasTheme;
7
8
  privacyPolicy: string | null;
8
9
  returnPolicy: string | null;
9
10
  termsOfService: string | null;
@@ -1,11 +1,13 @@
1
1
  /// <reference types="node" />
2
2
  import { GetServerSidePropsContext, GetStaticPropsContext } from "next";
3
3
  import { ParsedUrlQuery } from "querystring";
4
- import { IkasTheme, IkasThemePageType } from "../models/index";
4
+ import { IkasThemePageType } from "../models/index";
5
5
  import { IkasStorefront } from "../models/data/storefront/index";
6
6
  import { IkasSalesChannel } from "../models/data/sales-channel/index";
7
7
  import { IkasStorefrontRouting } from "../models/data/storefront/routing/index";
8
+ import { IkasStorefrontThemeLocalization } from "../models/data/storefront/theme-localization/index";
8
9
  export declare class SettingsHelper {
10
+ static readSettingsFile(): Promise<any>;
9
11
  static getSettings(locale: string): Promise<SettingsData | null>;
10
12
  static getPageData(context: GetStaticPropsContext<ParsedUrlQuery> | GetServerSidePropsContext<ParsedUrlQuery>, isServer: boolean, pageType?: IkasThemePageType): Promise<{
11
13
  props: {
@@ -76,7 +78,7 @@ export declare class SettingsHelper {
76
78
  }
77
79
  export declare type SettingsData = {
78
80
  storefront: IkasStorefront;
79
- theme: IkasTheme;
81
+ themeLocalization: IkasStorefrontThemeLocalization;
80
82
  salesChannel: IkasSalesChannel;
81
83
  routing: IkasStorefrontRouting;
82
84
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "0.0.97",
3
+ "version": "0.0.99",
4
4
  "main": "./build/index.js",
5
5
  "module": "./build/index.es.js",
6
6
  "author": "Umut Ozan Yıldırım",