@websolutespa/bom-mixer-models 1.5.2 → 1.5.4
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/CHANGELOG.md +34 -17
- package/dist/index.d.ts +4 -2
- package/dist/index.js +40 -30
- package/dist/index.mjs +39 -31
- package/package.json +1 -1
- package/src/page/page.service.ts +10 -1
- package/src/route/route.interceptor.ts +6 -2
- package/src/route/route.service.ts +34 -27
- package/src/structured_data/structured_data.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-models
|
|
2
2
|
|
|
3
|
+
## 1.5.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: PageService, RouteInterceptor, RouteService, StructuredData
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @websolutespa/bom-mixer-store@1.4.3
|
|
10
|
+
|
|
11
|
+
## 1.5.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Modified: RouteService
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @websolutespa/bom-mixer-store@1.4.1
|
|
18
|
+
- @websolutespa/bom-core@0.6.3
|
|
19
|
+
|
|
3
20
|
## 1.5.2
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -20,95 +37,95 @@
|
|
|
20
37
|
|
|
21
38
|
### Minor Changes
|
|
22
39
|
|
|
23
|
-
- Added getDecoratedComponents, getPageProps
|
|
40
|
+
- Added getDecoratedComponents, getPageProps
|
|
24
41
|
|
|
25
42
|
## 1.4.0
|
|
26
43
|
|
|
27
44
|
### Minor Changes
|
|
28
45
|
|
|
29
|
-
- Modified: RouteService, LayoutService
|
|
46
|
+
- Modified: RouteService, LayoutService
|
|
30
47
|
|
|
31
48
|
## 1.3.0
|
|
32
49
|
|
|
33
50
|
### Minor Changes
|
|
34
51
|
|
|
35
|
-
- Added: ILazyProps, ILazyableProps, ILazyedProps
|
|
52
|
+
- Added: ILazyProps, ILazyableProps, ILazyedProps
|
|
36
53
|
|
|
37
54
|
## 1.2.1
|
|
38
55
|
|
|
39
56
|
### Patch Changes
|
|
40
57
|
|
|
41
|
-
- Added: IAppProps, ILazyProps
|
|
58
|
+
- Added: IAppProps, ILazyProps
|
|
42
59
|
|
|
43
60
|
## 1.2.0
|
|
44
61
|
|
|
45
62
|
### Minor Changes
|
|
46
63
|
|
|
47
|
-
- Updating: next 13
|
|
64
|
+
- Updating: next 13
|
|
48
65
|
|
|
49
66
|
## 1.1.0
|
|
50
67
|
|
|
51
68
|
### Minor Changes
|
|
52
69
|
|
|
53
|
-
- Added: storeApi
|
|
54
|
-
- Modified: SiteMapService
|
|
70
|
+
- Added: storeApi
|
|
71
|
+
- Modified: SiteMapService
|
|
55
72
|
|
|
56
73
|
## 1.0.1
|
|
57
74
|
|
|
58
75
|
### Patch Changes
|
|
59
76
|
|
|
60
|
-
- Added: env ROOT_CATEGORY
|
|
77
|
+
- Added: env ROOT_CATEGORY
|
|
61
78
|
|
|
62
79
|
## 0.5.0
|
|
63
80
|
|
|
64
81
|
### Minor Changes
|
|
65
82
|
|
|
66
|
-
- Modified routes, added redirects
|
|
83
|
+
- Modified routes, added redirects
|
|
67
84
|
|
|
68
85
|
## 0.4.2
|
|
69
86
|
|
|
70
87
|
### Patch Changes
|
|
71
88
|
|
|
72
|
-
- Fixing: avoid categories circular reference
|
|
89
|
+
- Fixing: avoid categories circular reference
|
|
73
90
|
|
|
74
91
|
## 0.4.1
|
|
75
92
|
|
|
76
93
|
### Patch Changes
|
|
77
94
|
|
|
78
|
-
- Added: source files
|
|
95
|
+
- Added: source files
|
|
79
96
|
|
|
80
97
|
## 0.4.0
|
|
81
98
|
|
|
82
99
|
### Minor Changes
|
|
83
100
|
|
|
84
|
-
- Added: splat routes
|
|
101
|
+
- Added: splat routes
|
|
85
102
|
|
|
86
103
|
## 0.3.0
|
|
87
104
|
|
|
88
105
|
### Minor Changes
|
|
89
106
|
|
|
90
|
-
- Added: @websolutespa/bom-core
|
|
107
|
+
- Added: @websolutespa/bom-core
|
|
91
108
|
|
|
92
109
|
## 0.2.0
|
|
93
110
|
|
|
94
111
|
### Minor Changes
|
|
95
112
|
|
|
96
|
-
- Added: LazyComponent Types
|
|
113
|
+
- Added: LazyComponent Types
|
|
97
114
|
|
|
98
115
|
## 0.1.1
|
|
99
116
|
|
|
100
117
|
### Patch Changes
|
|
101
118
|
|
|
102
|
-
- Modified: page service
|
|
119
|
+
- Modified: page service
|
|
103
120
|
|
|
104
121
|
## 0.1.0
|
|
105
122
|
|
|
106
123
|
### Minor Changes
|
|
107
124
|
|
|
108
|
-
- mock refactor
|
|
125
|
+
- mock refactor
|
|
109
126
|
|
|
110
127
|
## 0.0.2
|
|
111
128
|
|
|
112
129
|
### Patch Changes
|
|
113
130
|
|
|
114
|
-
- Added: first release
|
|
131
|
+
- Added: first release
|
package/dist/index.d.ts
CHANGED
|
@@ -276,6 +276,8 @@ declare function getErrorPageLayout(): Promise<{
|
|
|
276
276
|
}>;
|
|
277
277
|
type PartialPageProps<T extends ICategorized, B> = Omit<PageProps<T>, 'page'> & Partial<Pick<PageProps<T>, 'page'>> & B;
|
|
278
278
|
declare function getPageProps<T extends ICategorized, B = any>(props: PartialPageProps<T, B>): Promise<PageProps<T> & B>;
|
|
279
|
+
declare function getOrigin(): string;
|
|
280
|
+
declare function resolveHref(href?: string): string;
|
|
279
281
|
|
|
280
282
|
declare function getProvinces(locale?: string): Promise<INamedEntity[]>;
|
|
281
283
|
declare function getProvince(id: IEquatable, params?: QueryParams): Promise<INamedEntity | undefined>;
|
|
@@ -303,8 +305,8 @@ declare function getRoutesForTemplates(templates: string[], market?: string, loc
|
|
|
303
305
|
declare function getStaticPathsForSchema(schema: string): Promise<StaticPath[]>;
|
|
304
306
|
declare function getBreadcrumbFromSegments(segments: ICategory[], market: string, locale: string): Promise<IRouteLink[]>;
|
|
305
307
|
declare function getRouteLinkTree(market: string, locale: string): Promise<IRouteLink | undefined>;
|
|
308
|
+
declare function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string): IRouteLink | undefined;
|
|
306
309
|
declare function newRouteLink(category: ICategory, route: IRoute | undefined, locale: string): IRouteLink;
|
|
307
|
-
declare function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string): IRouteLink;
|
|
308
310
|
declare function resolveRoute(route: IRoute & {
|
|
309
311
|
splat?: string;
|
|
310
312
|
}): string;
|
|
@@ -403,4 +405,4 @@ type StructuredDataKeys = 'article';
|
|
|
403
405
|
type StructuredDataCollections = Record<StructuredDataKeys, string[]>;
|
|
404
406
|
declare function resolveStructuredData(page: IPage, types?: StructuredDataCollections): string | undefined;
|
|
405
407
|
|
|
406
|
-
export { IAddress, IAddressOptions, IAppProps, IApplication, IApplicationProps, ICartAddItem, ICartItem, ICheckout, ICheckoutDelivery, ICheckoutDiscount, ICheckoutInfo, ICheckoutItem, ICheckoutPartial, ICheckoutPayment, ICheckoutPaymentRedirect, ICheckoutStore, ICompanyAddress, IFeatureType, IKeyedList, ILazyComponent, ILazyComponentFunc, ILazyComponentProps, ILazyFuncProps, ILazyModules, ILazyProps, ILazyStaticProps, ILazyStaticPropsFunc, ILazyableProps, ILazyedProps, ILink, IList, IModelStore, IOrder, IOrderDetail, IOrderStatus, IOrderStatusValue, ISiteMap, IUser, IUserAddress, IUserChangePassword, IUserForgot, IUserLogin, IUserRegister, LAZY_PROPS, PartialPageProps, StaticPath, StructuredDataAddress, StructuredDataArticle, StructuredDataCollections, StructuredDataEvent, StructuredDataKeys, StructuredDataOffer, StructuredDataOrganization, StructuredDataPerformingGroup, StructuredDataPerson, StructuredDataPlace, categoryToRouteLink, findManyPages, findOnePage, getBreadcrumbFromSegments, getCategories, getCategory, getCountries, getCountry, getDecoratedComponents, getDeliveries, getErrorPageLayout, getFeatureType, getFeatureTypes, getInfo, getItems, getLabel, getLabels, getLayout, getListByKeys, getLists, getLocale, getLocaleFromProps, getLocales, getMarket, getMarkets, getMenu, getMenus, getOrder, getOrders, getPage, getPageCategory, getPageProps, getPageRoutes, getPayment, getPayments, getProvince, getProvinces, getRegion, getRegions, getRoute, getRouteLinkTree, getRoutes, getRoutesForSchemas, getRoutesForTemplates, getSegments, getSiteMapIndex, getSiteMapIndexProps, getSiteMapXML, getSiteMapXMLProps, getSiteMapXSL, getSiteMapXSLProps, getStaticPathsForSchema, getStores, newRouteLink, resolveLabel, resolveRoute, resolveStructuredData, routeInterceptor, routeRevalidateHandler, setDiscountCode, updateCheckout, withLazyProps };
|
|
408
|
+
export { IAddress, IAddressOptions, IAppProps, IApplication, IApplicationProps, ICartAddItem, ICartItem, ICheckout, ICheckoutDelivery, ICheckoutDiscount, ICheckoutInfo, ICheckoutItem, ICheckoutPartial, ICheckoutPayment, ICheckoutPaymentRedirect, ICheckoutStore, ICompanyAddress, IFeatureType, IKeyedList, ILazyComponent, ILazyComponentFunc, ILazyComponentProps, ILazyFuncProps, ILazyModules, ILazyProps, ILazyStaticProps, ILazyStaticPropsFunc, ILazyableProps, ILazyedProps, ILink, IList, IModelStore, IOrder, IOrderDetail, IOrderStatus, IOrderStatusValue, ISiteMap, IUser, IUserAddress, IUserChangePassword, IUserForgot, IUserLogin, IUserRegister, LAZY_PROPS, PartialPageProps, StaticPath, StructuredDataAddress, StructuredDataArticle, StructuredDataCollections, StructuredDataEvent, StructuredDataKeys, StructuredDataOffer, StructuredDataOrganization, StructuredDataPerformingGroup, StructuredDataPerson, StructuredDataPlace, categoryToRouteLink, findManyPages, findOnePage, getBreadcrumbFromSegments, getCategories, getCategory, getCountries, getCountry, getDecoratedComponents, getDeliveries, getErrorPageLayout, getFeatureType, getFeatureTypes, getInfo, getItems, getLabel, getLabels, getLayout, getListByKeys, getLists, getLocale, getLocaleFromProps, getLocales, getMarket, getMarkets, getMenu, getMenus, getOrder, getOrders, getOrigin, getPage, getPageCategory, getPageProps, getPageRoutes, getPayment, getPayments, getProvince, getProvinces, getRegion, getRegions, getRoute, getRouteLinkTree, getRoutes, getRoutesForSchemas, getRoutesForTemplates, getSegments, getSiteMapIndex, getSiteMapIndexProps, getSiteMapXML, getSiteMapXMLProps, getSiteMapXSL, getSiteMapXSLProps, getStaticPathsForSchema, getStores, newRouteLink, resolveHref, resolveLabel, resolveRoute, resolveStructuredData, routeInterceptor, routeRevalidateHandler, setDiscountCode, updateCheckout, withLazyProps };
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,7 @@ __export(src_exports, {
|
|
|
51
51
|
getMenus: () => getMenus,
|
|
52
52
|
getOrder: () => getOrder,
|
|
53
53
|
getOrders: () => getOrders,
|
|
54
|
+
getOrigin: () => getOrigin,
|
|
54
55
|
getPage: () => getPage,
|
|
55
56
|
getPageCategory: () => getPageCategory,
|
|
56
57
|
getPageProps: () => getPageProps,
|
|
@@ -76,6 +77,7 @@ __export(src_exports, {
|
|
|
76
77
|
getStaticPathsForSchema: () => getStaticPathsForSchema,
|
|
77
78
|
getStores: () => getStores,
|
|
78
79
|
newRouteLink: () => newRouteLink,
|
|
80
|
+
resolveHref: () => resolveHref,
|
|
79
81
|
resolveLabel: () => resolveLabel,
|
|
80
82
|
resolveRoute: () => resolveRoute,
|
|
81
83
|
resolveStructuredData: () => resolveStructuredData,
|
|
@@ -170,9 +172,7 @@ async function getRoutesForSchemas(schemas, market, locale) {
|
|
|
170
172
|
locale: {
|
|
171
173
|
equals: locale
|
|
172
174
|
}
|
|
173
|
-
}
|
|
174
|
-
market,
|
|
175
|
-
locale
|
|
175
|
+
}
|
|
176
176
|
});
|
|
177
177
|
const items = {};
|
|
178
178
|
routes.forEach((route) => {
|
|
@@ -193,9 +193,7 @@ async function getRoutesForTemplates(templates, market, locale) {
|
|
|
193
193
|
locale: {
|
|
194
194
|
equals: locale
|
|
195
195
|
}
|
|
196
|
-
}
|
|
197
|
-
market,
|
|
198
|
-
locale
|
|
196
|
+
}
|
|
199
197
|
});
|
|
200
198
|
const items = {};
|
|
201
199
|
routes.forEach((route) => {
|
|
@@ -253,9 +251,7 @@ async function getRouteLinkTree(market, locale) {
|
|
|
253
251
|
locale: {
|
|
254
252
|
equals: locale
|
|
255
253
|
}
|
|
256
|
-
}
|
|
257
|
-
market,
|
|
258
|
-
locale
|
|
254
|
+
}
|
|
259
255
|
});
|
|
260
256
|
const categories = await store.category.findMany();
|
|
261
257
|
const rootCategory = (0, import_bom_core2.getRootCategory)(categories);
|
|
@@ -265,6 +261,22 @@ async function getRouteLinkTree(market, locale) {
|
|
|
265
261
|
}
|
|
266
262
|
return void 0;
|
|
267
263
|
}
|
|
264
|
+
function categoryToRouteLink(routes, categories, category, locale) {
|
|
265
|
+
const route = routes.find(
|
|
266
|
+
(r) => r.category === category.id && r.isDefault
|
|
267
|
+
);
|
|
268
|
+
if (!route) {
|
|
269
|
+
return void 0;
|
|
270
|
+
}
|
|
271
|
+
const rootCategory = (0, import_bom_core2.getRootCategory)(categories);
|
|
272
|
+
const childCategories = categories.filter((x) => {
|
|
273
|
+
const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
|
|
274
|
+
return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
|
|
275
|
+
});
|
|
276
|
+
const routeLink = newRouteLink(category, route, locale);
|
|
277
|
+
routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale)).filter((x) => x !== void 0);
|
|
278
|
+
return routeLink;
|
|
279
|
+
}
|
|
268
280
|
function newRouteLink(category, route, locale) {
|
|
269
281
|
const href = route && route.id ? route.id.toString() : "/";
|
|
270
282
|
const id = route?.page || category.id;
|
|
@@ -282,19 +294,6 @@ function newRouteLink(category, route, locale) {
|
|
|
282
294
|
};
|
|
283
295
|
return routeLink;
|
|
284
296
|
}
|
|
285
|
-
function categoryToRouteLink(routes, categories, category, locale) {
|
|
286
|
-
const route = routes.find(
|
|
287
|
-
(r) => r.category === category.id
|
|
288
|
-
);
|
|
289
|
-
const rootCategory = (0, import_bom_core2.getRootCategory)(categories);
|
|
290
|
-
const childCategories = categories.filter((x) => {
|
|
291
|
-
const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
|
|
292
|
-
return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
|
|
293
|
-
});
|
|
294
|
-
const routeLink = newRouteLink(category, route, locale);
|
|
295
|
-
routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale));
|
|
296
|
-
return routeLink;
|
|
297
|
-
}
|
|
298
297
|
function resolveRoute(route) {
|
|
299
298
|
const routepath = route.template ? route.template : route.schema;
|
|
300
299
|
const resolvedPathname = `/${route.market}/${route.locale}/${routepath}/${route.page}${route.splat || ""}`;
|
|
@@ -1140,9 +1139,7 @@ async function getPageRoutes(schema, id, market, locale) {
|
|
|
1140
1139
|
schema: {
|
|
1141
1140
|
equals: schema
|
|
1142
1141
|
}
|
|
1143
|
-
}
|
|
1144
|
-
market,
|
|
1145
|
-
locale
|
|
1142
|
+
}
|
|
1146
1143
|
});
|
|
1147
1144
|
} catch (error) {
|
|
1148
1145
|
console.error("No routes found for page " + schema + ":" + id);
|
|
@@ -1220,6 +1217,13 @@ async function getPageProps(props) {
|
|
|
1220
1217
|
}
|
|
1221
1218
|
return (0, import_bom_core3.asServerProps)(props);
|
|
1222
1219
|
}
|
|
1220
|
+
function getOrigin() {
|
|
1221
|
+
const origin = process.env && process.env.NEXT_PUBLIC_URL ? process.env.NEXT_PUBLIC_URL : "";
|
|
1222
|
+
return origin;
|
|
1223
|
+
}
|
|
1224
|
+
function resolveHref(href = "") {
|
|
1225
|
+
return href.startsWith("http") ? href : `${getOrigin()}${href}`;
|
|
1226
|
+
}
|
|
1223
1227
|
|
|
1224
1228
|
// src/route/route-revalidate.handler.ts
|
|
1225
1229
|
var import_bom_mixer_store13 = require("@websolutespa/bom-mixer-store");
|
|
@@ -1254,7 +1258,11 @@ async function routeInterceptor(request, next) {
|
|
|
1254
1258
|
let url = request.nextUrl;
|
|
1255
1259
|
let route;
|
|
1256
1260
|
try {
|
|
1257
|
-
|
|
1261
|
+
if (import_bom_mixer_store14.storeStrategy === import_bom_mixer_store14.StoreStrategy.DecoratedApi) {
|
|
1262
|
+
route = await (0, import_bom_mixer_store14.localApiPost)("/route", { pathname: url.pathname, href: url.href });
|
|
1263
|
+
} else {
|
|
1264
|
+
route = await (0, import_bom_mixer_store14.storeApiPost)("/route", { pathname: url.pathname, href: url.href });
|
|
1265
|
+
}
|
|
1258
1266
|
if (!route) {
|
|
1259
1267
|
console.log("routeInterceptor.route.notfound", url.pathname);
|
|
1260
1268
|
return;
|
|
@@ -1538,7 +1546,7 @@ async function getSiteMapXSL() {
|
|
|
1538
1546
|
|
|
1539
1547
|
// src/sitemap/sitemap.handler.ts
|
|
1540
1548
|
var ORIGIN = process.env.NEXT_PUBLIC_URL || "";
|
|
1541
|
-
function
|
|
1549
|
+
function getOrigin2(host) {
|
|
1542
1550
|
if (host) {
|
|
1543
1551
|
return host.indexOf("localhost") !== -1 ? "http://" + host : "https://" + host;
|
|
1544
1552
|
} else {
|
|
@@ -1547,7 +1555,7 @@ function getOrigin(host) {
|
|
|
1547
1555
|
}
|
|
1548
1556
|
var getSiteMapIndexProps = async (context) => {
|
|
1549
1557
|
const { req, res } = context;
|
|
1550
|
-
const sitemap = await getSiteMapIndex(
|
|
1558
|
+
const sitemap = await getSiteMapIndex(getOrigin2(req.headers.host));
|
|
1551
1559
|
res.setHeader("Content-Type", "application/xml; charset=UTF-8");
|
|
1552
1560
|
res.setHeader("X-Frame-Options", "SAMEORIGIN");
|
|
1553
1561
|
res.setHeader("X-Robots-Tag", "noindex, follow");
|
|
@@ -1562,7 +1570,7 @@ var getSiteMapXMLProps = async (context) => {
|
|
|
1562
1570
|
const params = context.params;
|
|
1563
1571
|
const market = params?.market;
|
|
1564
1572
|
const locale = params?.locale;
|
|
1565
|
-
const sitemap = await getSiteMapXML(
|
|
1573
|
+
const sitemap = await getSiteMapXML(getOrigin2(req.headers.host), market, locale);
|
|
1566
1574
|
res.setHeader("Content-Type", "application/xml; charset=UTF-8");
|
|
1567
1575
|
res.setHeader("X-Frame-Options", "SAMEORIGIN");
|
|
1568
1576
|
res.setHeader("X-Robots-Tag", "noindex, follow");
|
|
@@ -1598,7 +1606,7 @@ function resolveStructuredData(page, types = DefaultStructuredDataCollections) {
|
|
|
1598
1606
|
"@context": "https://schema.org",
|
|
1599
1607
|
"@type": "NewsArticle",
|
|
1600
1608
|
headline: page.title,
|
|
1601
|
-
image: page.media ? [page.media.src] : [],
|
|
1609
|
+
image: page.media ? [resolveHref(page.media.src)] : [],
|
|
1602
1610
|
datePublished: page.createdAt,
|
|
1603
1611
|
dateModified: page.updatedAt,
|
|
1604
1612
|
author: [{
|
|
@@ -1647,6 +1655,7 @@ function resolveStructuredData(page, types = DefaultStructuredDataCollections) {
|
|
|
1647
1655
|
getMenus,
|
|
1648
1656
|
getOrder,
|
|
1649
1657
|
getOrders,
|
|
1658
|
+
getOrigin,
|
|
1650
1659
|
getPage,
|
|
1651
1660
|
getPageCategory,
|
|
1652
1661
|
getPageProps,
|
|
@@ -1672,6 +1681,7 @@ function resolveStructuredData(page, types = DefaultStructuredDataCollections) {
|
|
|
1672
1681
|
getStaticPathsForSchema,
|
|
1673
1682
|
getStores,
|
|
1674
1683
|
newRouteLink,
|
|
1684
|
+
resolveHref,
|
|
1675
1685
|
resolveLabel,
|
|
1676
1686
|
resolveRoute,
|
|
1677
1687
|
resolveStructuredData,
|
package/dist/index.mjs
CHANGED
|
@@ -81,9 +81,7 @@ async function getRoutesForSchemas(schemas, market, locale) {
|
|
|
81
81
|
locale: {
|
|
82
82
|
equals: locale
|
|
83
83
|
}
|
|
84
|
-
}
|
|
85
|
-
market,
|
|
86
|
-
locale
|
|
84
|
+
}
|
|
87
85
|
});
|
|
88
86
|
const items = {};
|
|
89
87
|
routes.forEach((route) => {
|
|
@@ -104,9 +102,7 @@ async function getRoutesForTemplates(templates, market, locale) {
|
|
|
104
102
|
locale: {
|
|
105
103
|
equals: locale
|
|
106
104
|
}
|
|
107
|
-
}
|
|
108
|
-
market,
|
|
109
|
-
locale
|
|
105
|
+
}
|
|
110
106
|
});
|
|
111
107
|
const items = {};
|
|
112
108
|
routes.forEach((route) => {
|
|
@@ -164,9 +160,7 @@ async function getRouteLinkTree(market, locale) {
|
|
|
164
160
|
locale: {
|
|
165
161
|
equals: locale
|
|
166
162
|
}
|
|
167
|
-
}
|
|
168
|
-
market,
|
|
169
|
-
locale
|
|
163
|
+
}
|
|
170
164
|
});
|
|
171
165
|
const categories = await store.category.findMany();
|
|
172
166
|
const rootCategory = getRootCategory(categories);
|
|
@@ -176,6 +170,22 @@ async function getRouteLinkTree(market, locale) {
|
|
|
176
170
|
}
|
|
177
171
|
return void 0;
|
|
178
172
|
}
|
|
173
|
+
function categoryToRouteLink(routes, categories, category, locale) {
|
|
174
|
+
const route = routes.find(
|
|
175
|
+
(r) => r.category === category.id && r.isDefault
|
|
176
|
+
);
|
|
177
|
+
if (!route) {
|
|
178
|
+
return void 0;
|
|
179
|
+
}
|
|
180
|
+
const rootCategory = getRootCategory(categories);
|
|
181
|
+
const childCategories = categories.filter((x) => {
|
|
182
|
+
const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
|
|
183
|
+
return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
|
|
184
|
+
});
|
|
185
|
+
const routeLink = newRouteLink(category, route, locale);
|
|
186
|
+
routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale)).filter((x) => x !== void 0);
|
|
187
|
+
return routeLink;
|
|
188
|
+
}
|
|
179
189
|
function newRouteLink(category, route, locale) {
|
|
180
190
|
const href = route && route.id ? route.id.toString() : "/";
|
|
181
191
|
const id = route?.page || category.id;
|
|
@@ -193,19 +203,6 @@ function newRouteLink(category, route, locale) {
|
|
|
193
203
|
};
|
|
194
204
|
return routeLink;
|
|
195
205
|
}
|
|
196
|
-
function categoryToRouteLink(routes, categories, category, locale) {
|
|
197
|
-
const route = routes.find(
|
|
198
|
-
(r) => r.category === category.id
|
|
199
|
-
);
|
|
200
|
-
const rootCategory = getRootCategory(categories);
|
|
201
|
-
const childCategories = categories.filter((x) => {
|
|
202
|
-
const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
|
|
203
|
-
return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
|
|
204
|
-
});
|
|
205
|
-
const routeLink = newRouteLink(category, route, locale);
|
|
206
|
-
routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale));
|
|
207
|
-
return routeLink;
|
|
208
|
-
}
|
|
209
206
|
function resolveRoute(route) {
|
|
210
207
|
const routepath = route.template ? route.template : route.schema;
|
|
211
208
|
const resolvedPathname = `/${route.market}/${route.locale}/${routepath}/${route.page}${route.splat || ""}`;
|
|
@@ -1051,9 +1048,7 @@ async function getPageRoutes(schema, id, market, locale) {
|
|
|
1051
1048
|
schema: {
|
|
1052
1049
|
equals: schema
|
|
1053
1050
|
}
|
|
1054
|
-
}
|
|
1055
|
-
market,
|
|
1056
|
-
locale
|
|
1051
|
+
}
|
|
1057
1052
|
});
|
|
1058
1053
|
} catch (error) {
|
|
1059
1054
|
console.error("No routes found for page " + schema + ":" + id);
|
|
@@ -1131,6 +1126,13 @@ async function getPageProps(props) {
|
|
|
1131
1126
|
}
|
|
1132
1127
|
return asServerProps(props);
|
|
1133
1128
|
}
|
|
1129
|
+
function getOrigin() {
|
|
1130
|
+
const origin = process.env && process.env.NEXT_PUBLIC_URL ? process.env.NEXT_PUBLIC_URL : "";
|
|
1131
|
+
return origin;
|
|
1132
|
+
}
|
|
1133
|
+
function resolveHref(href = "") {
|
|
1134
|
+
return href.startsWith("http") ? href : `${getOrigin()}${href}`;
|
|
1135
|
+
}
|
|
1134
1136
|
|
|
1135
1137
|
// src/route/route-revalidate.handler.ts
|
|
1136
1138
|
import { apiHandler } from "@websolutespa/bom-mixer-store";
|
|
@@ -1159,13 +1161,17 @@ function routeRevalidateHandler() {
|
|
|
1159
1161
|
}
|
|
1160
1162
|
|
|
1161
1163
|
// src/route/route.interceptor.ts
|
|
1162
|
-
import { storeApiPost } from "@websolutespa/bom-mixer-store";
|
|
1164
|
+
import { StoreStrategy, localApiPost, storeApiPost, storeStrategy } from "@websolutespa/bom-mixer-store";
|
|
1163
1165
|
import { NextResponse } from "next/server";
|
|
1164
1166
|
async function routeInterceptor(request, next) {
|
|
1165
1167
|
let url = request.nextUrl;
|
|
1166
1168
|
let route;
|
|
1167
1169
|
try {
|
|
1168
|
-
|
|
1170
|
+
if (storeStrategy === StoreStrategy.DecoratedApi) {
|
|
1171
|
+
route = await localApiPost("/route", { pathname: url.pathname, href: url.href });
|
|
1172
|
+
} else {
|
|
1173
|
+
route = await storeApiPost("/route", { pathname: url.pathname, href: url.href });
|
|
1174
|
+
}
|
|
1169
1175
|
if (!route) {
|
|
1170
1176
|
console.log("routeInterceptor.route.notfound", url.pathname);
|
|
1171
1177
|
return;
|
|
@@ -1449,7 +1455,7 @@ async function getSiteMapXSL() {
|
|
|
1449
1455
|
|
|
1450
1456
|
// src/sitemap/sitemap.handler.ts
|
|
1451
1457
|
var ORIGIN = process.env.NEXT_PUBLIC_URL || "";
|
|
1452
|
-
function
|
|
1458
|
+
function getOrigin2(host) {
|
|
1453
1459
|
if (host) {
|
|
1454
1460
|
return host.indexOf("localhost") !== -1 ? "http://" + host : "https://" + host;
|
|
1455
1461
|
} else {
|
|
@@ -1458,7 +1464,7 @@ function getOrigin(host) {
|
|
|
1458
1464
|
}
|
|
1459
1465
|
var getSiteMapIndexProps = async (context) => {
|
|
1460
1466
|
const { req, res } = context;
|
|
1461
|
-
const sitemap = await getSiteMapIndex(
|
|
1467
|
+
const sitemap = await getSiteMapIndex(getOrigin2(req.headers.host));
|
|
1462
1468
|
res.setHeader("Content-Type", "application/xml; charset=UTF-8");
|
|
1463
1469
|
res.setHeader("X-Frame-Options", "SAMEORIGIN");
|
|
1464
1470
|
res.setHeader("X-Robots-Tag", "noindex, follow");
|
|
@@ -1473,7 +1479,7 @@ var getSiteMapXMLProps = async (context) => {
|
|
|
1473
1479
|
const params = context.params;
|
|
1474
1480
|
const market = params?.market;
|
|
1475
1481
|
const locale = params?.locale;
|
|
1476
|
-
const sitemap = await getSiteMapXML(
|
|
1482
|
+
const sitemap = await getSiteMapXML(getOrigin2(req.headers.host), market, locale);
|
|
1477
1483
|
res.setHeader("Content-Type", "application/xml; charset=UTF-8");
|
|
1478
1484
|
res.setHeader("X-Frame-Options", "SAMEORIGIN");
|
|
1479
1485
|
res.setHeader("X-Robots-Tag", "noindex, follow");
|
|
@@ -1509,7 +1515,7 @@ function resolveStructuredData(page, types = DefaultStructuredDataCollections) {
|
|
|
1509
1515
|
"@context": "https://schema.org",
|
|
1510
1516
|
"@type": "NewsArticle",
|
|
1511
1517
|
headline: page.title,
|
|
1512
|
-
image: page.media ? [page.media.src] : [],
|
|
1518
|
+
image: page.media ? [resolveHref(page.media.src)] : [],
|
|
1513
1519
|
datePublished: page.createdAt,
|
|
1514
1520
|
dateModified: page.updatedAt,
|
|
1515
1521
|
author: [{
|
|
@@ -1557,6 +1563,7 @@ export {
|
|
|
1557
1563
|
getMenus,
|
|
1558
1564
|
getOrder,
|
|
1559
1565
|
getOrders,
|
|
1566
|
+
getOrigin,
|
|
1560
1567
|
getPage,
|
|
1561
1568
|
getPageCategory,
|
|
1562
1569
|
getPageProps,
|
|
@@ -1582,6 +1589,7 @@ export {
|
|
|
1582
1589
|
getStaticPathsForSchema,
|
|
1583
1590
|
getStores,
|
|
1584
1591
|
newRouteLink,
|
|
1592
|
+
resolveHref,
|
|
1585
1593
|
resolveLabel,
|
|
1586
1594
|
resolveRoute,
|
|
1587
1595
|
resolveStructuredData,
|
package/package.json
CHANGED
package/src/page/page.service.ts
CHANGED
|
@@ -70,7 +70,7 @@ export async function getPageRoutes(schema: string, id: IEquatable, market?: str
|
|
|
70
70
|
schema: {
|
|
71
71
|
equals: schema,
|
|
72
72
|
},
|
|
73
|
-
},
|
|
73
|
+
},
|
|
74
74
|
});
|
|
75
75
|
} catch (error: any) {
|
|
76
76
|
console.error('No routes found for page ' + schema + ':' + id);
|
|
@@ -156,3 +156,12 @@ export async function getPageProps<T extends ICategorized, B = any>(props: Parti
|
|
|
156
156
|
}
|
|
157
157
|
return asServerProps(props) as PageProps<T> & B;
|
|
158
158
|
}
|
|
159
|
+
|
|
160
|
+
export function getOrigin() {
|
|
161
|
+
const origin = process.env && process.env.NEXT_PUBLIC_URL ? process.env.NEXT_PUBLIC_URL : '';
|
|
162
|
+
return origin;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function resolveHref(href: string = '') {
|
|
166
|
+
return href.startsWith('http') ? href : `${getOrigin()}${href}`;
|
|
167
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IRoute } from '@websolutespa/bom-core';
|
|
2
|
-
import { storeApiPost } from '@websolutespa/bom-mixer-store';
|
|
2
|
+
import { StoreStrategy, localApiPost, storeApiPost, storeStrategy } from '@websolutespa/bom-mixer-store';
|
|
3
3
|
import { NextFetchEvent, NextRequest, NextResponse } from 'next/server';
|
|
4
4
|
import { resolveRoute } from './route.service';
|
|
5
5
|
|
|
@@ -8,7 +8,11 @@ export async function routeInterceptor(request: NextRequest, next: NextFetchEven
|
|
|
8
8
|
let route: IRoute | undefined;
|
|
9
9
|
try {
|
|
10
10
|
// console.log('routeInterceptor', url.pathname);
|
|
11
|
-
|
|
11
|
+
if (storeStrategy === StoreStrategy.DecoratedApi) {
|
|
12
|
+
route = await localApiPost('/route', { pathname: url.pathname, href: url.href });
|
|
13
|
+
} else {
|
|
14
|
+
route = await storeApiPost('/route', { pathname: url.pathname, href: url.href });
|
|
15
|
+
}
|
|
12
16
|
// console.log('route', route);
|
|
13
17
|
if (!route) {
|
|
14
18
|
console.log('routeInterceptor.route.notfound', url.pathname);
|
|
@@ -30,7 +30,7 @@ export async function getRoutesForSchemas(schemas: string[], market?: string, lo
|
|
|
30
30
|
locale: {
|
|
31
31
|
equals: locale,
|
|
32
32
|
},
|
|
33
|
-
},
|
|
33
|
+
},
|
|
34
34
|
});
|
|
35
35
|
const items: {
|
|
36
36
|
[key: string]: string;
|
|
@@ -54,7 +54,7 @@ export async function getRoutesForTemplates(templates: string[], market?: string
|
|
|
54
54
|
locale: {
|
|
55
55
|
equals: locale,
|
|
56
56
|
},
|
|
57
|
-
},
|
|
57
|
+
},
|
|
58
58
|
});
|
|
59
59
|
const items: {
|
|
60
60
|
[key: string]: string;
|
|
@@ -109,7 +109,7 @@ export async function getBreadcrumbFromSegments(segments: ICategory[], market: s
|
|
|
109
109
|
|
|
110
110
|
export async function getRouteLinkTree(market: string, locale: string): Promise<IRouteLink | undefined> {
|
|
111
111
|
const store = await getStore<IModelStore>();
|
|
112
|
-
// console.log('getRouteLinkTree.store');
|
|
112
|
+
// console.log('getRouteLinkTree.store', store);
|
|
113
113
|
const routes = await store.route.findMany({
|
|
114
114
|
where: {
|
|
115
115
|
market: {
|
|
@@ -118,13 +118,13 @@ export async function getRouteLinkTree(market: string, locale: string): Promise<
|
|
|
118
118
|
locale: {
|
|
119
119
|
equals: locale,
|
|
120
120
|
},
|
|
121
|
-
},
|
|
121
|
+
},
|
|
122
122
|
});
|
|
123
|
-
// console.log('getRouteLinkTree.routes');
|
|
123
|
+
// console.log('getRouteLinkTree.routes', routes);
|
|
124
124
|
const categories = await store.category.findMany();
|
|
125
|
-
// console.log('getRouteLinkTree.categories');
|
|
125
|
+
// console.log('getRouteLinkTree.categories', categories);
|
|
126
126
|
const rootCategory = getRootCategory(categories);
|
|
127
|
-
// console.log('getRouteLinkTree.rootCategory');
|
|
127
|
+
// console.log('getRouteLinkTree.rootCategory', rootCategory);
|
|
128
128
|
if (rootCategory) {
|
|
129
129
|
const root = categoryToRouteLink(routes, categories, rootCategory, locale);
|
|
130
130
|
// console.log('getRouteLinkTree', root);
|
|
@@ -133,6 +133,33 @@ export async function getRouteLinkTree(market: string, locale: string): Promise<
|
|
|
133
133
|
return undefined;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
// !!! todo refactor: only category with linked route.isDefault on tree.
|
|
137
|
+
export function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string): IRouteLink | undefined {
|
|
138
|
+
const route = routes.find(r =>
|
|
139
|
+
r.category === category.id &&
|
|
140
|
+
r.isDefault
|
|
141
|
+
);
|
|
142
|
+
if (!route) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
const rootCategory = getRootCategory(categories);
|
|
146
|
+
const childCategories = categories.filter(x => {
|
|
147
|
+
const parentId = x.category && typeof x.category === 'object' ? x.category['id'] : x.category;
|
|
148
|
+
return rootCategory && category.id === rootCategory.id ?
|
|
149
|
+
(x.id !== rootCategory.id && (parentId === category.id || !parentId)) :
|
|
150
|
+
parentId === category.id;
|
|
151
|
+
});
|
|
152
|
+
// console.log('childCategories', category.id, childCategories);
|
|
153
|
+
const routeLink = newRouteLink(category, route, locale);
|
|
154
|
+
// const title = localize(category.title || 'untitled', locale);
|
|
155
|
+
// const href = (route && route.id) ? route.id.toString() : '/';
|
|
156
|
+
// console.log('categoryToRouteLink', href, category.id, route);
|
|
157
|
+
routeLink.items = childCategories
|
|
158
|
+
.map(x => categoryToRouteLink(routes, categories, x, locale))
|
|
159
|
+
.filter(x => x !== undefined) as IRouteLink[];
|
|
160
|
+
return routeLink;
|
|
161
|
+
}
|
|
162
|
+
|
|
136
163
|
export function newRouteLink(category: ICategory, route: IRoute | undefined, locale: string): IRouteLink {
|
|
137
164
|
const href = (route && route.id) ? route.id.toString() : '/';
|
|
138
165
|
const id = route?.page || category.id;
|
|
@@ -151,26 +178,6 @@ export function newRouteLink(category: ICategory, route: IRoute | undefined, loc
|
|
|
151
178
|
return routeLink;
|
|
152
179
|
}
|
|
153
180
|
|
|
154
|
-
export function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string): IRouteLink {
|
|
155
|
-
const route = routes.find(r =>
|
|
156
|
-
r.category === category.id
|
|
157
|
-
);
|
|
158
|
-
const rootCategory = getRootCategory(categories);
|
|
159
|
-
const childCategories = categories.filter(x => {
|
|
160
|
-
const parentId = x.category && typeof x.category === 'object' ? x.category['id'] : x.category;
|
|
161
|
-
return rootCategory && category.id === rootCategory.id ?
|
|
162
|
-
(x.id !== rootCategory.id && (parentId === category.id || !parentId)) :
|
|
163
|
-
parentId === category.id;
|
|
164
|
-
});
|
|
165
|
-
// console.log('childCategories', category.id, childCategories);
|
|
166
|
-
const routeLink = newRouteLink(category, route, locale);
|
|
167
|
-
// const title = localize(category.title || 'untitled', locale);
|
|
168
|
-
// const href = (route && route.id) ? route.id.toString() : '/';
|
|
169
|
-
// console.log('categoryToRouteLink', href, category.id, route);
|
|
170
|
-
routeLink.items = childCategories.map(x => categoryToRouteLink(routes, categories, x, locale));
|
|
171
|
-
return routeLink;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
181
|
export function resolveRoute(route: IRoute & { splat?: string }) {
|
|
175
182
|
// console.log('resolveRoute', route);
|
|
176
183
|
const routepath: string = route.template ? route.template : route.schema;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IPage } from '@websolutespa/bom-core';
|
|
2
|
+
import { resolveHref } from '../page/page.service';
|
|
2
3
|
|
|
3
4
|
export type StructuredDataPerson = {
|
|
4
5
|
'@type': 'Person';
|
|
@@ -91,7 +92,7 @@ export function resolveStructuredData(page: IPage, types: StructuredDataCollecti
|
|
|
91
92
|
'@context': 'https://schema.org',
|
|
92
93
|
'@type': 'NewsArticle',
|
|
93
94
|
headline: page.title,
|
|
94
|
-
image: page.media ? [page.media.src] : [],
|
|
95
|
+
image: page.media ? [resolveHref(page.media.src)] : [],
|
|
95
96
|
datePublished: page.createdAt,
|
|
96
97
|
dateModified: page.updatedAt,
|
|
97
98
|
author: [{
|