@ikas/storefront 0.0.96 → 0.0.98
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 +67 -23
- package/build/index.js +68 -23
- package/build/utils/settings.d.ts +1 -0
- package/package.json +1 -1
package/build/index.es.js
CHANGED
|
@@ -8,6 +8,7 @@ import Link from 'next/link';
|
|
|
8
8
|
import Head from 'next/head';
|
|
9
9
|
import fs from 'fs';
|
|
10
10
|
import dynamic from 'next/dynamic';
|
|
11
|
+
import Error$1 from 'next/error';
|
|
11
12
|
|
|
12
13
|
/*! *****************************************************************************
|
|
13
14
|
Copyright (c) Microsoft Corporation.
|
|
@@ -28341,34 +28342,64 @@ var IkasSalesChannelStockLocation = /** @class */ (function () {
|
|
|
28341
28342
|
var SettingsHelper = /** @class */ (function () {
|
|
28342
28343
|
function SettingsHelper() {
|
|
28343
28344
|
}
|
|
28344
|
-
SettingsHelper.
|
|
28345
|
+
SettingsHelper.readSettingsFile = function () {
|
|
28345
28346
|
return new Promise(function (resolve) {
|
|
28346
28347
|
var serverRuntimeConfig = getConfig().serverRuntimeConfig;
|
|
28347
|
-
var
|
|
28348
|
-
|
|
28349
|
-
var salesChannel = new IkasSalesChannel(settings.salesChannel);
|
|
28350
|
-
var localizationMap = settings.localizationMap;
|
|
28351
|
-
var themeJSONPath = localizationMap[locale];
|
|
28352
|
-
var routing = storefront.routings.find(function (r) { return r.id === locale || r.path === locale; });
|
|
28353
|
-
if (!themeJSONPath || !routing) {
|
|
28354
|
-
return resolve(null);
|
|
28355
|
-
}
|
|
28356
|
-
fs.readFile(themeJSONPath, {
|
|
28348
|
+
var settingsPath = serverRuntimeConfig.SETTINGS;
|
|
28349
|
+
fs.readFile(settingsPath, {
|
|
28357
28350
|
flag: "a+",
|
|
28358
28351
|
}, function (err, file) {
|
|
28359
28352
|
if (err) {
|
|
28353
|
+
console.error("SETTINGS FILE READ ERROR!!!");
|
|
28354
|
+
console.error(err);
|
|
28360
28355
|
return resolve(null);
|
|
28361
28356
|
}
|
|
28362
28357
|
var result = file.length ? JSON.parse(file.toString()) : {};
|
|
28363
|
-
resolve(
|
|
28364
|
-
storefront: storefront,
|
|
28365
|
-
theme: new IkasTheme(result),
|
|
28366
|
-
salesChannel: salesChannel,
|
|
28367
|
-
routing: routing,
|
|
28368
|
-
});
|
|
28358
|
+
resolve(result);
|
|
28369
28359
|
});
|
|
28370
28360
|
});
|
|
28371
28361
|
};
|
|
28362
|
+
SettingsHelper.getSettings = function (locale) {
|
|
28363
|
+
var _this = this;
|
|
28364
|
+
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
|
28365
|
+
var settings, storefront, salesChannel, localizationMap, themeJSONPath, routing;
|
|
28366
|
+
return __generator(this, function (_a) {
|
|
28367
|
+
switch (_a.label) {
|
|
28368
|
+
case 0: return [4 /*yield*/, SettingsHelper.readSettingsFile()];
|
|
28369
|
+
case 1:
|
|
28370
|
+
settings = _a.sent();
|
|
28371
|
+
if (!settings)
|
|
28372
|
+
return [2 /*return*/, resolve(null)];
|
|
28373
|
+
storefront = new IkasStorefront(settings.storefront);
|
|
28374
|
+
salesChannel = new IkasSalesChannel(settings.salesChannel);
|
|
28375
|
+
localizationMap = settings.localizationMap;
|
|
28376
|
+
themeJSONPath = localizationMap[locale];
|
|
28377
|
+
routing = storefront.routings.find(function (r) { return r.id === locale || r.path === locale; });
|
|
28378
|
+
if (!themeJSONPath || !routing) {
|
|
28379
|
+
console.error("THEMEJSONPATH OR ROUTING MISSING!!!");
|
|
28380
|
+
return [2 /*return*/, resolve(null)];
|
|
28381
|
+
}
|
|
28382
|
+
fs.readFile(themeJSONPath, {
|
|
28383
|
+
flag: "a+",
|
|
28384
|
+
}, function (err, file) {
|
|
28385
|
+
if (err) {
|
|
28386
|
+
console.error("THEMEJSON FILE RED ERROR!!!");
|
|
28387
|
+
console.error(err);
|
|
28388
|
+
return resolve(null);
|
|
28389
|
+
}
|
|
28390
|
+
var result = file.length ? JSON.parse(file.toString()) : {};
|
|
28391
|
+
resolve({
|
|
28392
|
+
storefront: storefront,
|
|
28393
|
+
theme: new IkasTheme(result),
|
|
28394
|
+
salesChannel: salesChannel,
|
|
28395
|
+
routing: routing,
|
|
28396
|
+
});
|
|
28397
|
+
});
|
|
28398
|
+
return [2 /*return*/];
|
|
28399
|
+
}
|
|
28400
|
+
});
|
|
28401
|
+
}); });
|
|
28402
|
+
};
|
|
28372
28403
|
SettingsHelper.getPageData = function (context, isServer, pageType) {
|
|
28373
28404
|
var _a;
|
|
28374
28405
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -28382,8 +28413,7 @@ var SettingsHelper = /** @class */ (function () {
|
|
|
28382
28413
|
settings = _b.sent();
|
|
28383
28414
|
if (!settings ||
|
|
28384
28415
|
!settings.storefront.mainStorefrontThemeId ||
|
|
28385
|
-
!settings.storefront.salesChannelId
|
|
28386
|
-
!settings.routing.priceListId) {
|
|
28416
|
+
!settings.storefront.salesChannelId) {
|
|
28387
28417
|
return [2 /*return*/, {
|
|
28388
28418
|
props: {},
|
|
28389
28419
|
notFound: true,
|
|
@@ -28394,7 +28424,7 @@ var SettingsHelper = /** @class */ (function () {
|
|
|
28394
28424
|
IkasStorefrontConfig.storefrontRoutingId = routing.id;
|
|
28395
28425
|
IkasStorefrontConfig.storefrontThemeId = storefront.mainStorefrontThemeId;
|
|
28396
28426
|
IkasStorefrontConfig.salesChannelId = storefront.salesChannelId;
|
|
28397
|
-
IkasStorefrontConfig.priceListId = routing.priceListId;
|
|
28427
|
+
IkasStorefrontConfig.priceListId = routing.priceListId || undefined;
|
|
28398
28428
|
IkasStorefrontConfig.stockLocationIds = (_a = salesChannel.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return sl.id; });
|
|
28399
28429
|
provider = new IkasPageDataProvider(theme, context.params, pageType);
|
|
28400
28430
|
return [4 /*yield*/, provider.getPageData()];
|
|
@@ -28410,7 +28440,9 @@ var SettingsHelper = /** @class */ (function () {
|
|
|
28410
28440
|
return [2 /*return*/, provider.nextPageData];
|
|
28411
28441
|
else
|
|
28412
28442
|
return [2 /*return*/, {
|
|
28413
|
-
props: __assign(__assign({}, provider.nextPageData.props), { pageSpecificDataStr:
|
|
28443
|
+
props: __assign(__assign({}, provider.nextPageData.props), { pageSpecificDataStr: provider.pageSpecificData
|
|
28444
|
+
? JSON.stringify(provider.pageSpecificData || {})
|
|
28445
|
+
: "" }),
|
|
28414
28446
|
revalidate: 60,
|
|
28415
28447
|
}];
|
|
28416
28448
|
}
|
|
@@ -28610,7 +28642,7 @@ var getStaticPaths$1 = function (context) { return __awaiter(void 0, void 0, voi
|
|
|
28610
28642
|
!customPagePaths.some(function (p) { return p.params.slug === customPage.slug; })) {
|
|
28611
28643
|
customPagePaths.push({
|
|
28612
28644
|
params: { slug: customPage.slug },
|
|
28613
|
-
locale: routing.
|
|
28645
|
+
locale: routing.path || routing.id,
|
|
28614
28646
|
});
|
|
28615
28647
|
}
|
|
28616
28648
|
});
|
|
@@ -28966,15 +28998,27 @@ var search = /*#__PURE__*/Object.freeze({
|
|
|
28966
28998
|
|
|
28967
28999
|
var Page$f = function (_a) {
|
|
28968
29000
|
var page = _a.page, propValuesStr = _a.propValuesStr, settingsStr = _a.settingsStr, merchantSettings = _a.merchantSettings;
|
|
29001
|
+
if (!propValuesStr || !page)
|
|
29002
|
+
return createElement(Error$1, { statusCode: 404 });
|
|
28969
29003
|
var router = useRouter();
|
|
28970
29004
|
var propValues = useMemo(function () { return IkasPageDataProvider.initPropValues(propValuesStr, router); }, [propValuesStr]);
|
|
28971
29005
|
return (createElement(IkasPage, { merchantSettings: merchantSettings, settingsStr: settingsStr, page: page, propValues: propValues }));
|
|
28972
29006
|
};
|
|
28973
29007
|
var getStaticProps$d = function (context) { return __awaiter(void 0, void 0, void 0, function () {
|
|
29008
|
+
var props;
|
|
28974
29009
|
return __generator(this, function (_a) {
|
|
28975
29010
|
switch (_a.label) {
|
|
28976
29011
|
case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, IkasThemePageType.NOT_FOUND)];
|
|
28977
|
-
case 1:
|
|
29012
|
+
case 1:
|
|
29013
|
+
props = _a.sent();
|
|
29014
|
+
//@ts-ignore
|
|
29015
|
+
if (props.notFound)
|
|
29016
|
+
return [2 /*return*/, {
|
|
29017
|
+
props: {},
|
|
29018
|
+
revalidate: 60,
|
|
29019
|
+
}];
|
|
29020
|
+
else
|
|
29021
|
+
return [2 /*return*/, props];
|
|
28978
29022
|
}
|
|
28979
29023
|
});
|
|
28980
29024
|
}); };
|
package/build/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var Link = require('next/link');
|
|
|
12
12
|
var Head = require('next/head');
|
|
13
13
|
var fs = require('fs');
|
|
14
14
|
var dynamic = require('next/dynamic');
|
|
15
|
+
var Error$1 = require('next/error');
|
|
15
16
|
|
|
16
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
18
|
|
|
@@ -22,6 +23,7 @@ var Link__default = /*#__PURE__*/_interopDefaultLegacy(Link);
|
|
|
22
23
|
var Head__default = /*#__PURE__*/_interopDefaultLegacy(Head);
|
|
23
24
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
24
25
|
var dynamic__default = /*#__PURE__*/_interopDefaultLegacy(dynamic);
|
|
26
|
+
var Error__default = /*#__PURE__*/_interopDefaultLegacy(Error$1);
|
|
25
27
|
|
|
26
28
|
/*! *****************************************************************************
|
|
27
29
|
Copyright (c) Microsoft Corporation.
|
|
@@ -28320,34 +28322,64 @@ var IkasSalesChannelStockLocation = /** @class */ (function () {
|
|
|
28320
28322
|
var SettingsHelper = /** @class */ (function () {
|
|
28321
28323
|
function SettingsHelper() {
|
|
28322
28324
|
}
|
|
28323
|
-
SettingsHelper.
|
|
28325
|
+
SettingsHelper.readSettingsFile = function () {
|
|
28324
28326
|
return new Promise(function (resolve) {
|
|
28325
28327
|
var serverRuntimeConfig = getConfig__default['default']().serverRuntimeConfig;
|
|
28326
|
-
var
|
|
28327
|
-
|
|
28328
|
-
var salesChannel = new IkasSalesChannel(settings.salesChannel);
|
|
28329
|
-
var localizationMap = settings.localizationMap;
|
|
28330
|
-
var themeJSONPath = localizationMap[locale];
|
|
28331
|
-
var routing = storefront.routings.find(function (r) { return r.id === locale || r.path === locale; });
|
|
28332
|
-
if (!themeJSONPath || !routing) {
|
|
28333
|
-
return resolve(null);
|
|
28334
|
-
}
|
|
28335
|
-
fs__default['default'].readFile(themeJSONPath, {
|
|
28328
|
+
var settingsPath = serverRuntimeConfig.SETTINGS;
|
|
28329
|
+
fs__default['default'].readFile(settingsPath, {
|
|
28336
28330
|
flag: "a+",
|
|
28337
28331
|
}, function (err, file) {
|
|
28338
28332
|
if (err) {
|
|
28333
|
+
console.error("SETTINGS FILE READ ERROR!!!");
|
|
28334
|
+
console.error(err);
|
|
28339
28335
|
return resolve(null);
|
|
28340
28336
|
}
|
|
28341
28337
|
var result = file.length ? JSON.parse(file.toString()) : {};
|
|
28342
|
-
resolve(
|
|
28343
|
-
storefront: storefront,
|
|
28344
|
-
theme: new IkasTheme(result),
|
|
28345
|
-
salesChannel: salesChannel,
|
|
28346
|
-
routing: routing,
|
|
28347
|
-
});
|
|
28338
|
+
resolve(result);
|
|
28348
28339
|
});
|
|
28349
28340
|
});
|
|
28350
28341
|
};
|
|
28342
|
+
SettingsHelper.getSettings = function (locale) {
|
|
28343
|
+
var _this = this;
|
|
28344
|
+
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
|
28345
|
+
var settings, storefront, salesChannel, localizationMap, themeJSONPath, routing;
|
|
28346
|
+
return __generator(this, function (_a) {
|
|
28347
|
+
switch (_a.label) {
|
|
28348
|
+
case 0: return [4 /*yield*/, SettingsHelper.readSettingsFile()];
|
|
28349
|
+
case 1:
|
|
28350
|
+
settings = _a.sent();
|
|
28351
|
+
if (!settings)
|
|
28352
|
+
return [2 /*return*/, resolve(null)];
|
|
28353
|
+
storefront = new IkasStorefront(settings.storefront);
|
|
28354
|
+
salesChannel = new IkasSalesChannel(settings.salesChannel);
|
|
28355
|
+
localizationMap = settings.localizationMap;
|
|
28356
|
+
themeJSONPath = localizationMap[locale];
|
|
28357
|
+
routing = storefront.routings.find(function (r) { return r.id === locale || r.path === locale; });
|
|
28358
|
+
if (!themeJSONPath || !routing) {
|
|
28359
|
+
console.error("THEMEJSONPATH OR ROUTING MISSING!!!");
|
|
28360
|
+
return [2 /*return*/, resolve(null)];
|
|
28361
|
+
}
|
|
28362
|
+
fs__default['default'].readFile(themeJSONPath, {
|
|
28363
|
+
flag: "a+",
|
|
28364
|
+
}, function (err, file) {
|
|
28365
|
+
if (err) {
|
|
28366
|
+
console.error("THEMEJSON FILE RED ERROR!!!");
|
|
28367
|
+
console.error(err);
|
|
28368
|
+
return resolve(null);
|
|
28369
|
+
}
|
|
28370
|
+
var result = file.length ? JSON.parse(file.toString()) : {};
|
|
28371
|
+
resolve({
|
|
28372
|
+
storefront: storefront,
|
|
28373
|
+
theme: new IkasTheme(result),
|
|
28374
|
+
salesChannel: salesChannel,
|
|
28375
|
+
routing: routing,
|
|
28376
|
+
});
|
|
28377
|
+
});
|
|
28378
|
+
return [2 /*return*/];
|
|
28379
|
+
}
|
|
28380
|
+
});
|
|
28381
|
+
}); });
|
|
28382
|
+
};
|
|
28351
28383
|
SettingsHelper.getPageData = function (context, isServer, pageType) {
|
|
28352
28384
|
var _a;
|
|
28353
28385
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -28361,8 +28393,7 @@ var SettingsHelper = /** @class */ (function () {
|
|
|
28361
28393
|
settings = _b.sent();
|
|
28362
28394
|
if (!settings ||
|
|
28363
28395
|
!settings.storefront.mainStorefrontThemeId ||
|
|
28364
|
-
!settings.storefront.salesChannelId
|
|
28365
|
-
!settings.routing.priceListId) {
|
|
28396
|
+
!settings.storefront.salesChannelId) {
|
|
28366
28397
|
return [2 /*return*/, {
|
|
28367
28398
|
props: {},
|
|
28368
28399
|
notFound: true,
|
|
@@ -28373,7 +28404,7 @@ var SettingsHelper = /** @class */ (function () {
|
|
|
28373
28404
|
IkasStorefrontConfig.storefrontRoutingId = routing.id;
|
|
28374
28405
|
IkasStorefrontConfig.storefrontThemeId = storefront.mainStorefrontThemeId;
|
|
28375
28406
|
IkasStorefrontConfig.salesChannelId = storefront.salesChannelId;
|
|
28376
|
-
IkasStorefrontConfig.priceListId = routing.priceListId;
|
|
28407
|
+
IkasStorefrontConfig.priceListId = routing.priceListId || undefined;
|
|
28377
28408
|
IkasStorefrontConfig.stockLocationIds = (_a = salesChannel.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return sl.id; });
|
|
28378
28409
|
provider = new IkasPageDataProvider(theme, context.params, pageType);
|
|
28379
28410
|
return [4 /*yield*/, provider.getPageData()];
|
|
@@ -28389,7 +28420,9 @@ var SettingsHelper = /** @class */ (function () {
|
|
|
28389
28420
|
return [2 /*return*/, provider.nextPageData];
|
|
28390
28421
|
else
|
|
28391
28422
|
return [2 /*return*/, {
|
|
28392
|
-
props: __assign(__assign({}, provider.nextPageData.props), { pageSpecificDataStr:
|
|
28423
|
+
props: __assign(__assign({}, provider.nextPageData.props), { pageSpecificDataStr: provider.pageSpecificData
|
|
28424
|
+
? JSON.stringify(provider.pageSpecificData || {})
|
|
28425
|
+
: "" }),
|
|
28393
28426
|
revalidate: 60,
|
|
28394
28427
|
}];
|
|
28395
28428
|
}
|
|
@@ -28589,7 +28622,7 @@ var getStaticPaths$1 = function (context) { return __awaiter(void 0, void 0, voi
|
|
|
28589
28622
|
!customPagePaths.some(function (p) { return p.params.slug === customPage.slug; })) {
|
|
28590
28623
|
customPagePaths.push({
|
|
28591
28624
|
params: { slug: customPage.slug },
|
|
28592
|
-
locale: routing.
|
|
28625
|
+
locale: routing.path || routing.id,
|
|
28593
28626
|
});
|
|
28594
28627
|
}
|
|
28595
28628
|
});
|
|
@@ -28945,15 +28978,27 @@ var search = /*#__PURE__*/Object.freeze({
|
|
|
28945
28978
|
|
|
28946
28979
|
var Page$f = function (_a) {
|
|
28947
28980
|
var page = _a.page, propValuesStr = _a.propValuesStr, settingsStr = _a.settingsStr, merchantSettings = _a.merchantSettings;
|
|
28981
|
+
if (!propValuesStr || !page)
|
|
28982
|
+
return React.createElement(Error__default['default'], { statusCode: 404 });
|
|
28948
28983
|
var router$1 = router.useRouter();
|
|
28949
28984
|
var propValues = React.useMemo(function () { return IkasPageDataProvider.initPropValues(propValuesStr, router$1); }, [propValuesStr]);
|
|
28950
28985
|
return (React.createElement(IkasPage, { merchantSettings: merchantSettings, settingsStr: settingsStr, page: page, propValues: propValues }));
|
|
28951
28986
|
};
|
|
28952
28987
|
var getStaticProps$d = function (context) { return __awaiter(void 0, void 0, void 0, function () {
|
|
28988
|
+
var props;
|
|
28953
28989
|
return __generator(this, function (_a) {
|
|
28954
28990
|
switch (_a.label) {
|
|
28955
28991
|
case 0: return [4 /*yield*/, SettingsHelper.getStaticProps(context, exports.IkasThemePageType.NOT_FOUND)];
|
|
28956
|
-
case 1:
|
|
28992
|
+
case 1:
|
|
28993
|
+
props = _a.sent();
|
|
28994
|
+
//@ts-ignore
|
|
28995
|
+
if (props.notFound)
|
|
28996
|
+
return [2 /*return*/, {
|
|
28997
|
+
props: {},
|
|
28998
|
+
revalidate: 60,
|
|
28999
|
+
}];
|
|
29000
|
+
else
|
|
29001
|
+
return [2 /*return*/, props];
|
|
28957
29002
|
}
|
|
28958
29003
|
});
|
|
28959
29004
|
}); };
|
|
@@ -6,6 +6,7 @@ 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
8
|
export declare class SettingsHelper {
|
|
9
|
+
static readSettingsFile(): Promise<any>;
|
|
9
10
|
static getSettings(locale: string): Promise<SettingsData | null>;
|
|
10
11
|
static getPageData(context: GetStaticPropsContext<ParsedUrlQuery> | GetServerSidePropsContext<ParsedUrlQuery>, isServer: boolean, pageType?: IkasThemePageType): Promise<{
|
|
11
12
|
props: {
|