@websolutespa/bom-mixer-store 1.4.2 → 1.4.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 +35 -20
- package/dist/index.d.ts +9 -1
- package/dist/index.js +149 -107
- package/dist/index.mjs +142 -103
- package/package.json +1 -1
- package/src/cached/cached.service.ts +26 -8
- package/src/decorators/href.ts +0 -4
- package/src/decorators/index.ts +1 -0
- package/src/decorators/menu.ts +0 -1
- package/src/decorators/nav.ts +0 -1
- package/src/decorators/schema.ts +11 -0
- package/src/local/local.api.ts +2 -2
- package/src/mock/mock-menu.service.ts +0 -2
- package/src/mock/mock.api.ts +2 -1
- package/src/mock/mock.store.ts +1 -1
- package/src/remote/remote-menu.service.ts +5 -3
- package/src/remote/remote-page.service.ts +5 -3
- package/src/remote/remote.api.ts +2 -1
- package/src/remote/remote.service.ts +7 -2
- package/src/remote/remote.store.ts +4 -4
- package/src/store/store.handler.ts +116 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-store
|
|
2
2
|
|
|
3
|
+
## 1.4.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added: Schema decorator
|
|
8
|
+
- Modified: RemoteMenuService, RemotePageService, RemoteService
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @websolutespa/bom-core@0.6.5
|
|
11
|
+
|
|
12
|
+
## 1.4.3
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Modified: CachedService, Decorators, LocalApi, MockApi, MockStore, RemoteApi, RemoteStore, StoreHandler
|
|
17
|
+
|
|
3
18
|
## 1.4.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
6
21
|
|
|
7
|
-
- Added: Decorators, CachedService, RemotePageService, RemoteMenuService, StoreStrategy.DecoratedApi, nextPhase, storeCacheDuration
|
|
8
|
-
- Modified: RemoteStore
|
|
22
|
+
- Added: Decorators, CachedService, RemotePageService, RemoteMenuService, StoreStrategy.DecoratedApi, nextPhase, storeCacheDuration
|
|
23
|
+
- Modified: RemoteStore
|
|
9
24
|
- Updated dependencies
|
|
10
25
|
- @websolutespa/bom-core@0.6.4
|
|
11
26
|
|
|
@@ -13,7 +28,7 @@
|
|
|
13
28
|
|
|
14
29
|
### Patch Changes
|
|
15
30
|
|
|
16
|
-
- Modified: MockPageService
|
|
31
|
+
- Modified: MockPageService
|
|
17
32
|
- Updated dependencies
|
|
18
33
|
- @websolutespa/bom-core@0.6.3
|
|
19
34
|
|
|
@@ -21,95 +36,95 @@
|
|
|
21
36
|
|
|
22
37
|
### Minor Changes
|
|
23
38
|
|
|
24
|
-
- Added: BuildStrategy
|
|
39
|
+
- Added: BuildStrategy
|
|
25
40
|
|
|
26
41
|
## 1.3.0
|
|
27
42
|
|
|
28
43
|
### Minor Changes
|
|
29
44
|
|
|
30
|
-
- Added: storeIndexHandler
|
|
31
|
-
- Modified: Store, StoreHandler, RemoteService, MockService, MockPageService, MockMenuService, StaticService
|
|
45
|
+
- Added: storeIndexHandler
|
|
46
|
+
- Modified: Store, StoreHandler, RemoteService, MockService, MockPageService, MockMenuService, StaticService
|
|
32
47
|
|
|
33
48
|
## 1.2.2
|
|
34
49
|
|
|
35
50
|
### Patch Changes
|
|
36
51
|
|
|
37
|
-
- Modified: MockMenuService IPageRelationResult
|
|
52
|
+
- Modified: MockMenuService IPageRelationResult
|
|
38
53
|
|
|
39
54
|
## 1.2.1
|
|
40
55
|
|
|
41
56
|
### Patch Changes
|
|
42
57
|
|
|
43
|
-
- Fixing: MockMenuService collectPages
|
|
58
|
+
- Fixing: MockMenuService collectPages
|
|
44
59
|
|
|
45
60
|
## 1.2.0
|
|
46
61
|
|
|
47
62
|
### Minor Changes
|
|
48
63
|
|
|
49
|
-
- Updating: next 13
|
|
64
|
+
- Updating: next 13
|
|
50
65
|
|
|
51
66
|
## 1.1.1
|
|
52
67
|
|
|
53
68
|
### Patch Changes
|
|
54
69
|
|
|
55
|
-
- Fixing: check redirects by pattern
|
|
70
|
+
- Fixing: check redirects by pattern
|
|
56
71
|
|
|
57
72
|
## 1.1.0
|
|
58
73
|
|
|
59
74
|
### Minor Changes
|
|
60
75
|
|
|
61
|
-
- Modified: store refactor
|
|
76
|
+
- Modified: store refactor
|
|
62
77
|
|
|
63
78
|
## 1.0.1
|
|
64
79
|
|
|
65
80
|
### Patch Changes
|
|
66
81
|
|
|
67
|
-
- Fixing: localhost url
|
|
82
|
+
- Fixing: localhost url
|
|
68
83
|
|
|
69
84
|
## 1.0.0
|
|
70
85
|
|
|
71
86
|
### Minor Changes
|
|
72
87
|
|
|
73
|
-
- Modified routes, added redirects
|
|
88
|
+
- Modified routes, added redirects
|
|
74
89
|
|
|
75
90
|
## 0.3.2
|
|
76
91
|
|
|
77
92
|
### Patch Changes
|
|
78
93
|
|
|
79
|
-
- Modified: MockMenuService
|
|
94
|
+
- Modified: MockMenuService
|
|
80
95
|
|
|
81
96
|
## 0.3.1
|
|
82
97
|
|
|
83
98
|
### Patch Changes
|
|
84
99
|
|
|
85
|
-
- Added: source files
|
|
100
|
+
- Added: source files
|
|
86
101
|
|
|
87
102
|
## 0.3.0
|
|
88
103
|
|
|
89
104
|
### Minor Changes
|
|
90
105
|
|
|
91
|
-
- Added: splat routes
|
|
106
|
+
- Added: splat routes
|
|
92
107
|
|
|
93
108
|
## 0.2.0
|
|
94
109
|
|
|
95
110
|
### Minor Changes
|
|
96
111
|
|
|
97
|
-
- Added: @websolutespa/bom-core
|
|
112
|
+
- Added: @websolutespa/bom-core
|
|
98
113
|
|
|
99
114
|
## 0.1.1
|
|
100
115
|
|
|
101
116
|
### Patch Changes
|
|
102
117
|
|
|
103
|
-
- Modified: store service
|
|
118
|
+
- Modified: store service
|
|
104
119
|
|
|
105
120
|
## 0.1.0
|
|
106
121
|
|
|
107
122
|
### Minor Changes
|
|
108
123
|
|
|
109
|
-
- mock refactor
|
|
124
|
+
- mock refactor
|
|
110
125
|
|
|
111
126
|
## 0.0.2
|
|
112
127
|
|
|
113
128
|
### Patch Changes
|
|
114
129
|
|
|
115
|
-
- Added: first release
|
|
130
|
+
- Added: first release
|
package/dist/index.d.ts
CHANGED
|
@@ -41,6 +41,13 @@ declare const SERVICE_DEFAULT_DEPTH = 2;
|
|
|
41
41
|
declare function decorateRelation_<T extends ISchema = ISchema>(store: IStore, item: T, params?: QueryParams): Promise<T>;
|
|
42
42
|
declare function decorateRelations_<T extends ISchema = ISchema>(store: IStore, items: T[], params?: QueryParams): Promise<T[]>;
|
|
43
43
|
|
|
44
|
+
declare function decorateSchema_<T extends ISchema = ISchema>(store: IStore, item: T, schema: string): Promise<T | T & {
|
|
45
|
+
schema: string;
|
|
46
|
+
}>;
|
|
47
|
+
declare function decorateSchemas_<T extends ISchema = ISchema>(store: IStore, items: T[], schema: string): Promise<(T & {
|
|
48
|
+
schema: string;
|
|
49
|
+
})[]>;
|
|
50
|
+
|
|
44
51
|
declare function getLocalApiUrl(pathname: string): string;
|
|
45
52
|
declare function localApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions, serviceOptions?: {
|
|
46
53
|
locale: string;
|
|
@@ -206,7 +213,8 @@ declare function collectionPatch<T extends IStore>(storePromise: () => Promise<T
|
|
|
206
213
|
declare function collectionDelete<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
|
|
207
214
|
declare function routePost(store: IStore, request: NextApiRequest, response: NextApiResponse): Promise<void>;
|
|
208
215
|
declare function storeIndexHandler(): any;
|
|
216
|
+
declare function findRoute(store: IStore, pathname: string, href: string): Promise<IRoute | undefined>;
|
|
209
217
|
|
|
210
218
|
declare function getStore<T extends IStore>(): Promise<T>;
|
|
211
219
|
|
|
212
|
-
export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, SERVICE_DEFAULT_DEPTH, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateHref_, decorateHrefs_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateStaticRelation_, decorateStaticRelations_, defaultApiRequestOptions, errorHandler, fromCache, getDefaultApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, localizeItem_, localizeItems_, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy };
|
|
220
|
+
export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, SERVICE_DEFAULT_DEPTH, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateHref_, decorateHrefs_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, defaultApiRequestOptions, errorHandler, findRoute, fromCache, getDefaultApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, localizeItem_, localizeItems_, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy };
|
package/dist/index.js
CHANGED
|
@@ -60,10 +60,13 @@ __export(src_exports, {
|
|
|
60
60
|
decorateNavs_: () => decorateNavs_,
|
|
61
61
|
decorateRelation_: () => decorateRelation_,
|
|
62
62
|
decorateRelations_: () => decorateRelations_,
|
|
63
|
+
decorateSchema_: () => decorateSchema_,
|
|
64
|
+
decorateSchemas_: () => decorateSchemas_,
|
|
63
65
|
decorateStaticRelation_: () => decorateStaticRelation_,
|
|
64
66
|
decorateStaticRelations_: () => decorateStaticRelations_,
|
|
65
67
|
defaultApiRequestOptions: () => defaultApiRequestOptions,
|
|
66
68
|
errorHandler: () => errorHandler,
|
|
69
|
+
findRoute: () => findRoute,
|
|
67
70
|
fromCache: () => fromCache,
|
|
68
71
|
getDefaultApiRequestOptions: () => getDefaultApiRequestOptions,
|
|
69
72
|
getLocalApiUrl: () => getLocalApiUrl,
|
|
@@ -203,10 +206,6 @@ async function decorateHrefs_(store, items, params = {}) {
|
|
|
203
206
|
locale: {
|
|
204
207
|
equals: params.locale
|
|
205
208
|
}
|
|
206
|
-
/*
|
|
207
|
-
...(params.market ? { market: { equals: params.market } } : {}),
|
|
208
|
-
...(params.locale ? { locale: { equals: params.locale } } : {}),
|
|
209
|
-
*/
|
|
210
209
|
}
|
|
211
210
|
});
|
|
212
211
|
return items.map((item) => {
|
|
@@ -252,7 +251,6 @@ async function decorateMenu_(store, item, params) {
|
|
|
252
251
|
const undecoratedPages = collectUndecoratedPages(items);
|
|
253
252
|
if (undecoratedCategories.length > 0 || undecoratedPages.length > 0) {
|
|
254
253
|
const routes = await store.route.findMany({
|
|
255
|
-
...params,
|
|
256
254
|
where: {
|
|
257
255
|
...market ? { market: { equals: market } } : {},
|
|
258
256
|
...locale ? { locale: { equals: locale } } : {}
|
|
@@ -419,7 +417,6 @@ async function decorateNav_(store, item, params = {}, routes) {
|
|
|
419
417
|
}
|
|
420
418
|
async function decorateNavs_(store, items, params = {}) {
|
|
421
419
|
const routes = await store.route.findMany({
|
|
422
|
-
...params,
|
|
423
420
|
where: {
|
|
424
421
|
...params.market ? { market: { equals: params.market } } : {},
|
|
425
422
|
...params.locale ? { locale: { equals: params.locale } } : {}
|
|
@@ -514,6 +511,16 @@ function collectRelations_(item, relations = []) {
|
|
|
514
511
|
return relations;
|
|
515
512
|
}
|
|
516
513
|
|
|
514
|
+
// src/decorators/schema.ts
|
|
515
|
+
async function decorateSchema_(store, item, schema) {
|
|
516
|
+
return { ...item, schema };
|
|
517
|
+
}
|
|
518
|
+
async function decorateSchemas_(store, items, schema) {
|
|
519
|
+
return items.map((item) => {
|
|
520
|
+
return { ...item, schema };
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
517
524
|
// src/local/local.api.ts
|
|
518
525
|
var import_bom_core5 = require("@websolutespa/bom-core");
|
|
519
526
|
var API_URL = process.env.NEXT_PUBLIC_URL === "https://" ? process.env.NEXT_PUBLIC_MOCK_FALLBACK_URL : process.env.NEXT_PUBLIC_URL;
|
|
@@ -521,7 +528,6 @@ var API_BASE = process.env.NEXT_PUBLIC_API || "/api";
|
|
|
521
528
|
function getLocalApiUrl(pathname) {
|
|
522
529
|
let url = `${import_bom_core5.isBrowser ? window.location.origin : API_URL}${API_BASE}${pathname}`;
|
|
523
530
|
url = import_bom_core5.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
|
|
524
|
-
console.log("getLocalApiUrl", url);
|
|
525
531
|
return url;
|
|
526
532
|
}
|
|
527
533
|
async function localApiFetch(pathname, options = {}, serviceOptions) {
|
|
@@ -531,6 +537,7 @@ async function localApiFetch(pathname, options = {}, serviceOptions) {
|
|
|
531
537
|
url.searchParams.append("market", serviceOptions.market);
|
|
532
538
|
}
|
|
533
539
|
const apiOptions = (0, import_bom_core5.merge)({ ...getDefaultApiRequestOptions() }, options);
|
|
540
|
+
console.log("localApiFetch", apiOptions.method, url.href);
|
|
534
541
|
const apiResponse = await (0, import_bom_core5.httpFetch)(url.href, apiOptions);
|
|
535
542
|
return apiResponse;
|
|
536
543
|
}
|
|
@@ -665,12 +672,12 @@ var API_BASE3 = process.env.NEXT_PUBLIC_API || "/api";
|
|
|
665
672
|
function getMockApiUrl(pathname) {
|
|
666
673
|
let url = `${API_URL2}${API_BASE3}/_mock${pathname}`;
|
|
667
674
|
url = import_bom_core7.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
|
|
668
|
-
console.log("getMockApiUrl", url);
|
|
669
675
|
return url;
|
|
670
676
|
}
|
|
671
677
|
async function mockApiFetch(pathname, options = {}) {
|
|
672
678
|
const url = getMockApiUrl(pathname);
|
|
673
679
|
const apiOptions = (0, import_bom_core7.merge)({ ...getDefaultApiRequestOptions() }, options);
|
|
680
|
+
console.log("mockApiFetch", apiOptions.method, url);
|
|
674
681
|
const apiResponse = await (0, import_bom_core7.httpFetch)(url, apiOptions);
|
|
675
682
|
return apiResponse;
|
|
676
683
|
}
|
|
@@ -691,7 +698,7 @@ async function mockApiDelete(url, options = {}) {
|
|
|
691
698
|
}
|
|
692
699
|
|
|
693
700
|
// src/store/store.handler.ts
|
|
694
|
-
var
|
|
701
|
+
var import_bom_core13 = require("@websolutespa/bom-core");
|
|
695
702
|
|
|
696
703
|
// src/static/static.ts
|
|
697
704
|
var staticCollections = [{
|
|
@@ -1128,7 +1135,7 @@ function getMockStoreFromData_(data) {
|
|
|
1128
1135
|
}
|
|
1129
1136
|
}
|
|
1130
1137
|
} else {
|
|
1131
|
-
console.
|
|
1138
|
+
console.warn("mock store not found");
|
|
1132
1139
|
}
|
|
1133
1140
|
staticCollections.forEach((config) => {
|
|
1134
1141
|
store[config.slug] = new StaticService(config, store);
|
|
@@ -1160,13 +1167,11 @@ async function getMockStore() {
|
|
|
1160
1167
|
}, import_bom_core9.isDevelopment ? void 0 : "STORE_MOCK_");
|
|
1161
1168
|
}
|
|
1162
1169
|
|
|
1163
|
-
// src/remote/remote.store.ts
|
|
1164
|
-
var import_bom_core13 = require("@websolutespa/bom-core");
|
|
1165
|
-
|
|
1166
1170
|
// src/cached/cached.service.ts
|
|
1167
1171
|
var import_bom_core10 = require("@websolutespa/bom-core");
|
|
1168
|
-
var CachedService = class {
|
|
1172
|
+
var CachedService = class extends import_bom_core10.JsonService {
|
|
1169
1173
|
constructor(service, options = {}) {
|
|
1174
|
+
super([]);
|
|
1170
1175
|
this.cache_ = /* @__PURE__ */ new Map();
|
|
1171
1176
|
this.duration_ = storeCacheDuration;
|
|
1172
1177
|
if (!service) {
|
|
@@ -1210,11 +1215,27 @@ var CachedService = class {
|
|
|
1210
1215
|
}, key);
|
|
1211
1216
|
}
|
|
1212
1217
|
async findMany(params = {}) {
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
+
if (storeStrategy === "decoratedApi" /* DecoratedApi */) {
|
|
1219
|
+
const { market, locale, ...otherParams } = params;
|
|
1220
|
+
const serializedParams = (0, import_bom_core10.qsSerialize)({ market, locale });
|
|
1221
|
+
const key = `findMany?${serializedParams}`;
|
|
1222
|
+
return await this.fromCache_(async () => {
|
|
1223
|
+
let items = await this.service_.findMany({ market, locale });
|
|
1224
|
+
if (otherParams.where) {
|
|
1225
|
+
items = this.whereItems_(items, otherParams.where);
|
|
1226
|
+
}
|
|
1227
|
+
if (otherParams.sort) {
|
|
1228
|
+
items = this.sortCollection_(items, otherParams.sort);
|
|
1229
|
+
}
|
|
1230
|
+
return items;
|
|
1231
|
+
}, key);
|
|
1232
|
+
} else {
|
|
1233
|
+
const serializedParams = (0, import_bom_core10.qsSerialize)(params);
|
|
1234
|
+
const key = `findMany?${serializedParams}`;
|
|
1235
|
+
return await this.fromCache_(async () => {
|
|
1236
|
+
return await this.service_.findMany(params);
|
|
1237
|
+
}, key);
|
|
1238
|
+
}
|
|
1218
1239
|
}
|
|
1219
1240
|
async findPaged(params = {}) {
|
|
1220
1241
|
const serializedParams = (0, import_bom_core10.qsSerialize)(params);
|
|
@@ -1244,12 +1265,12 @@ var API_BASE4 = process.env.STORE_API || "/api";
|
|
|
1244
1265
|
function getRemoteApiUrl(pathname) {
|
|
1245
1266
|
let url = `${API_URL3}${API_BASE4}${pathname}`;
|
|
1246
1267
|
url = import_bom_core11.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
|
|
1247
|
-
console.log("getRemoteApiUrl", url);
|
|
1248
1268
|
return url;
|
|
1249
1269
|
}
|
|
1250
1270
|
async function remoteApiFetch(pathname, options = {}) {
|
|
1251
1271
|
const url = getRemoteApiUrl(pathname);
|
|
1252
1272
|
const apiOptions = (0, import_bom_core11.merge)({ ...getDefaultApiRequestOptions() }, options);
|
|
1273
|
+
console.log("remoteApiFetch", apiOptions.method, url);
|
|
1253
1274
|
const apiResponse = await (0, import_bom_core11.httpFetch)(url, apiOptions);
|
|
1254
1275
|
return apiResponse;
|
|
1255
1276
|
}
|
|
@@ -1341,10 +1362,14 @@ var RemoteService = class {
|
|
|
1341
1362
|
return await this.decorateOne_(item, {});
|
|
1342
1363
|
}
|
|
1343
1364
|
async decorateOne_(item, params = {}) {
|
|
1344
|
-
|
|
1365
|
+
let decoratedItem = item;
|
|
1366
|
+
decoratedItem = await decorateSchema_(this.store, decoratedItem, this.key);
|
|
1367
|
+
return decoratedItem;
|
|
1345
1368
|
}
|
|
1346
1369
|
async decorateMany_(items, params = {}) {
|
|
1347
|
-
|
|
1370
|
+
let decoratedItems = items;
|
|
1371
|
+
decoratedItems = await decorateSchemas_(this.store, decoratedItems, this.key);
|
|
1372
|
+
return decoratedItems;
|
|
1348
1373
|
}
|
|
1349
1374
|
};
|
|
1350
1375
|
|
|
@@ -1353,6 +1378,7 @@ var RemoteMenuService = class extends RemoteService {
|
|
|
1353
1378
|
async decorateOne_(item, params = {}) {
|
|
1354
1379
|
const store = this.store;
|
|
1355
1380
|
let decoratedItem = item;
|
|
1381
|
+
decoratedItem = await decorateSchema_(store, decoratedItem, this.key);
|
|
1356
1382
|
decoratedItem = await localizeItem_(item, params);
|
|
1357
1383
|
if (params.market && params.locale) {
|
|
1358
1384
|
decoratedItem = await decorateMenu_(store, decoratedItem, {
|
|
@@ -1365,6 +1391,7 @@ var RemoteMenuService = class extends RemoteService {
|
|
|
1365
1391
|
async decorateMany_(items, params = {}) {
|
|
1366
1392
|
const store = this.store;
|
|
1367
1393
|
let decoratedItems = items;
|
|
1394
|
+
decoratedItems = await decorateSchemas_(store, decoratedItems, this.key);
|
|
1368
1395
|
decoratedItems = await localizeItems_(items, params);
|
|
1369
1396
|
if (params.market && params.locale) {
|
|
1370
1397
|
decoratedItems = await decorateMenus_(store, decoratedItems, {
|
|
@@ -1381,6 +1408,8 @@ var RemotePageService = class extends RemoteService {
|
|
|
1381
1408
|
async decorateOne_(item, params = {}) {
|
|
1382
1409
|
const store = this.store;
|
|
1383
1410
|
let decoratedItem = item;
|
|
1411
|
+
decoratedItem = await decorateSchema_(store, decoratedItem, this.key);
|
|
1412
|
+
decoratedItem = await decorateHref_(store, decoratedItem, params);
|
|
1384
1413
|
decoratedItem = await decorateNav_(store, decoratedItem, params);
|
|
1385
1414
|
decoratedItem = await decorateRelation_(store, decoratedItem, {
|
|
1386
1415
|
market: params.market,
|
|
@@ -1392,6 +1421,8 @@ var RemotePageService = class extends RemoteService {
|
|
|
1392
1421
|
async decorateMany_(items, params = {}) {
|
|
1393
1422
|
const store = this.store;
|
|
1394
1423
|
let decoratedItems = items;
|
|
1424
|
+
decoratedItems = await decorateSchemas_(store, decoratedItems, this.key);
|
|
1425
|
+
decoratedItems = await decorateHrefs_(store, decoratedItems, params);
|
|
1395
1426
|
decoratedItems = await decorateNavs_(store, decoratedItems, params);
|
|
1396
1427
|
decoratedItems = await decorateRelations_(store, decoratedItems, {
|
|
1397
1428
|
market: params.market,
|
|
@@ -1406,7 +1437,6 @@ var RemotePageService = class extends RemoteService {
|
|
|
1406
1437
|
var PAGES2 = process.env.PAGES ? process.env.PAGES.split(",") : [];
|
|
1407
1438
|
async function getRemoteStore_() {
|
|
1408
1439
|
return fromCache(async () => {
|
|
1409
|
-
console.log("getRemoteStore_");
|
|
1410
1440
|
if (COLLECTIONS.length === 0) {
|
|
1411
1441
|
console.error("RemoteStore.getRemoteStore_ no collections");
|
|
1412
1442
|
throw "RemoteStore.getRemoteStore_ no collections";
|
|
@@ -1426,7 +1456,7 @@ async function getRemoteStore_() {
|
|
|
1426
1456
|
store[key] = new CachedService(
|
|
1427
1457
|
new RemoteMenuService(key, store)
|
|
1428
1458
|
);
|
|
1429
|
-
} else if (KNOWN_COLLECTIONS.includes(key)
|
|
1459
|
+
} else if (KNOWN_COLLECTIONS.includes(key)) {
|
|
1430
1460
|
store[key] = new CachedService(
|
|
1431
1461
|
new RemoteService(key, store)
|
|
1432
1462
|
);
|
|
@@ -1508,7 +1538,7 @@ function collectionGet(storePromise) {
|
|
|
1508
1538
|
const collection = collections[0];
|
|
1509
1539
|
const id = collections[1];
|
|
1510
1540
|
const qs = Object.entries(query).map((kv) => kv.join("=")).join("&");
|
|
1511
|
-
const params = (0,
|
|
1541
|
+
const params = (0, import_bom_core13.qsDeserialize)(qs);
|
|
1512
1542
|
if (!COLLECTIONS.includes(collection)) {
|
|
1513
1543
|
console.error("storeHandler.collectionGet", "method not allowed", collection);
|
|
1514
1544
|
return response.status(405).send("method not allowed");
|
|
@@ -1520,7 +1550,7 @@ function collectionGet(storePromise) {
|
|
|
1520
1550
|
return response.status(405).send("method not allowed");
|
|
1521
1551
|
}
|
|
1522
1552
|
if (id) {
|
|
1523
|
-
const item = await service.findOne((0,
|
|
1553
|
+
const item = await service.findOne((0, import_bom_core13.asEquatable)(id), params);
|
|
1524
1554
|
if (item) {
|
|
1525
1555
|
return response.status(200).json(item);
|
|
1526
1556
|
} else {
|
|
@@ -1612,87 +1642,20 @@ async function routePost(store, request, response) {
|
|
|
1612
1642
|
if (request.body.pathname && request.body.href) {
|
|
1613
1643
|
try {
|
|
1614
1644
|
const { pathname, href } = request.body;
|
|
1615
|
-
const
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
return response.status(200).json(routes[0]);
|
|
1624
|
-
} else {
|
|
1625
|
-
const splatRoutes = await store.route.findMany({
|
|
1626
|
-
where: {
|
|
1627
|
-
useSplat: {
|
|
1628
|
-
equals: true
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
});
|
|
1632
|
-
const splatRoute = splatRoutes.reduce((p, c) => {
|
|
1633
|
-
const match = pathname.indexOf(c.id) === 0;
|
|
1634
|
-
if (match && (!p || p.id.length < c.id.length)) {
|
|
1635
|
-
return { ...c, splat: pathname.substring(c.id.length, pathname.length) };
|
|
1636
|
-
} else {
|
|
1637
|
-
return p;
|
|
1638
|
-
}
|
|
1639
|
-
}, void 0);
|
|
1640
|
-
if (splatRoute) {
|
|
1641
|
-
return response.status(200).json(splatRoute);
|
|
1642
|
-
}
|
|
1643
|
-
const redirects = await store.redirect.findMany({
|
|
1644
|
-
where: {
|
|
1645
|
-
isActive: {
|
|
1646
|
-
equals: true
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
});
|
|
1650
|
-
const exactMatchResolver = (redirect) => {
|
|
1651
|
-
const status = parseInt(redirect.status) || 307;
|
|
1652
|
-
if (status < 400) {
|
|
1653
|
-
const redirectUrl = redirect.to;
|
|
1654
|
-
return response.status(status).send({
|
|
1655
|
-
redirectUrl
|
|
1656
|
-
});
|
|
1657
|
-
} else {
|
|
1658
|
-
return response.status(status).send("gone");
|
|
1659
|
-
}
|
|
1660
|
-
};
|
|
1661
|
-
const exactMatchRedirect = redirects.find((x) => x.from === href);
|
|
1662
|
-
if (exactMatchRedirect !== void 0) {
|
|
1663
|
-
return exactMatchResolver(exactMatchRedirect);
|
|
1645
|
+
const route = await findRoute(store, pathname, href);
|
|
1646
|
+
return response.status(200).json(route);
|
|
1647
|
+
} catch (error) {
|
|
1648
|
+
if (error.status < 500) {
|
|
1649
|
+
if (error.status < 400) {
|
|
1650
|
+
return response.status(error.status).send({
|
|
1651
|
+
redirectUrl: error.redirectUrl
|
|
1652
|
+
});
|
|
1664
1653
|
}
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
let i = 0;
|
|
1670
|
-
let redirectUrl = redirect.to.replace(/\*/g, (...rest) => {
|
|
1671
|
-
return `$${++i}`;
|
|
1672
|
-
});
|
|
1673
|
-
redirectUrl = href.replace(regexp, redirectUrl);
|
|
1674
|
-
return response.status(status).send({
|
|
1675
|
-
redirectUrl
|
|
1676
|
-
});
|
|
1677
|
-
} else {
|
|
1678
|
-
return response.status(status).send("gone");
|
|
1679
|
-
}
|
|
1680
|
-
};
|
|
1681
|
-
redirects.forEach((x) => {
|
|
1682
|
-
let expression = x.from;
|
|
1683
|
-
expression = expression.replace(/\*(?!\))/g, "(.*)");
|
|
1684
|
-
expression = `^${expression.replace(/(^\^)|(\$$)/g, "")}$`;
|
|
1685
|
-
x.from = expression;
|
|
1686
|
-
});
|
|
1687
|
-
const firstMatch = redirects.find((x) => href.match(x.from));
|
|
1688
|
-
if (firstMatch) {
|
|
1689
|
-
return patternMatchResolver(firstMatch);
|
|
1654
|
+
if (error.status === 404) {
|
|
1655
|
+
return response.status(404).send("not found");
|
|
1656
|
+
} else {
|
|
1657
|
+
return response.status(error.status).send("gone");
|
|
1690
1658
|
}
|
|
1691
|
-
return response.status(404).send("not found");
|
|
1692
|
-
}
|
|
1693
|
-
} catch (error) {
|
|
1694
|
-
if (error.status === 404) {
|
|
1695
|
-
return response.status(404).send("not found");
|
|
1696
1659
|
} else {
|
|
1697
1660
|
console.error("storeHandler.error.500", error);
|
|
1698
1661
|
throw error;
|
|
@@ -1706,8 +1669,8 @@ function storeIndexHandler() {
|
|
|
1706
1669
|
return apiHandler({
|
|
1707
1670
|
get: async (request, response) => {
|
|
1708
1671
|
try {
|
|
1709
|
-
const market =
|
|
1710
|
-
const locale =
|
|
1672
|
+
const market = import_bom_core13.defaultMarket;
|
|
1673
|
+
const locale = import_bom_core13.defaultLocale;
|
|
1711
1674
|
if (!Array.isArray(COLLECTIONS) || COLLECTIONS?.length === 0) {
|
|
1712
1675
|
console.error("apiHome.collectionGet", "collections not found", COLLECTIONS);
|
|
1713
1676
|
return response.status(405).send("method not allowed");
|
|
@@ -1833,6 +1796,82 @@ function storeIndexHandler() {
|
|
|
1833
1796
|
}
|
|
1834
1797
|
});
|
|
1835
1798
|
}
|
|
1799
|
+
async function findRoute(store, pathname, href) {
|
|
1800
|
+
const routes = await store.route.findMany({
|
|
1801
|
+
where: {
|
|
1802
|
+
id: {
|
|
1803
|
+
equals: pathname
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
});
|
|
1807
|
+
if (routes.length > 0) {
|
|
1808
|
+
return routes[0];
|
|
1809
|
+
} else {
|
|
1810
|
+
const splatRoutes = await store.route.findMany({
|
|
1811
|
+
where: {
|
|
1812
|
+
useSplat: {
|
|
1813
|
+
equals: true
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
});
|
|
1817
|
+
const splatRoute = splatRoutes.reduce((p, c) => {
|
|
1818
|
+
const match = pathname.indexOf(c.id) === 0;
|
|
1819
|
+
if (match && (!p || p.id.length < c.id.length)) {
|
|
1820
|
+
return { ...c, splat: pathname.substring(c.id.length, pathname.length) };
|
|
1821
|
+
} else {
|
|
1822
|
+
return p;
|
|
1823
|
+
}
|
|
1824
|
+
}, void 0);
|
|
1825
|
+
if (splatRoute) {
|
|
1826
|
+
return splatRoute;
|
|
1827
|
+
}
|
|
1828
|
+
const redirects = await store.redirect.findMany({
|
|
1829
|
+
where: {
|
|
1830
|
+
isActive: {
|
|
1831
|
+
equals: true
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
});
|
|
1835
|
+
const exactMatchResolver = (redirect) => {
|
|
1836
|
+
const status = parseInt(redirect.status) || 307;
|
|
1837
|
+
if (status < 400) {
|
|
1838
|
+
const redirectUrl = redirect.to;
|
|
1839
|
+
throw { status, redirectUrl };
|
|
1840
|
+
} else {
|
|
1841
|
+
throw { status };
|
|
1842
|
+
}
|
|
1843
|
+
};
|
|
1844
|
+
const exactMatchRedirect = redirects.find((x) => x.from === href);
|
|
1845
|
+
if (exactMatchRedirect !== void 0) {
|
|
1846
|
+
return exactMatchResolver(exactMatchRedirect);
|
|
1847
|
+
}
|
|
1848
|
+
const patternMatchResolver = (redirect) => {
|
|
1849
|
+
const status = parseInt(redirect.status) || 307;
|
|
1850
|
+
if (status < 400) {
|
|
1851
|
+
const regexp = new RegExp(redirect.from);
|
|
1852
|
+
let i = 0;
|
|
1853
|
+
let redirectUrl = redirect.to.replace(/\*/g, (...rest) => {
|
|
1854
|
+
return `$${++i}`;
|
|
1855
|
+
});
|
|
1856
|
+
redirectUrl = href.replace(regexp, redirectUrl);
|
|
1857
|
+
throw { status, redirectUrl };
|
|
1858
|
+
} else {
|
|
1859
|
+
throw { status };
|
|
1860
|
+
}
|
|
1861
|
+
};
|
|
1862
|
+
redirects.forEach((x) => {
|
|
1863
|
+
let expression = x.from;
|
|
1864
|
+
expression = expression.replace(/\*(?!\))/g, "(.*)");
|
|
1865
|
+
expression = `^${expression.replace(/(^\^)|(\$$)/g, "")}$`;
|
|
1866
|
+
x.from = expression;
|
|
1867
|
+
});
|
|
1868
|
+
const firstMatch = redirects.find((x) => href.match(x.from));
|
|
1869
|
+
if (firstMatch) {
|
|
1870
|
+
return patternMatchResolver(firstMatch);
|
|
1871
|
+
}
|
|
1872
|
+
throw { status: 404 };
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1836
1875
|
|
|
1837
1876
|
// src/mock/mock.handler.ts
|
|
1838
1877
|
function mockHandler() {
|
|
@@ -1888,10 +1927,13 @@ async function storeApiDelete(url, options = {}) {
|
|
|
1888
1927
|
decorateNavs_,
|
|
1889
1928
|
decorateRelation_,
|
|
1890
1929
|
decorateRelations_,
|
|
1930
|
+
decorateSchema_,
|
|
1931
|
+
decorateSchemas_,
|
|
1891
1932
|
decorateStaticRelation_,
|
|
1892
1933
|
decorateStaticRelations_,
|
|
1893
1934
|
defaultApiRequestOptions,
|
|
1894
1935
|
errorHandler,
|
|
1936
|
+
findRoute,
|
|
1895
1937
|
fromCache,
|
|
1896
1938
|
getDefaultApiRequestOptions,
|
|
1897
1939
|
getLocalApiUrl,
|