@websolutespa/bom-mixer-store 1.7.6 → 1.7.8

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @websolutespa/bom-mixer-store
2
2
 
3
+ ## 1.7.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: RouteService, MenuService to handle isHidden Category segments
8
+ - Updated dependencies
9
+ - @websolutespa/bom-core@1.7.12
10
+
11
+ ## 1.7.7
12
+
13
+ ### Patch Changes
14
+
15
+ - Added: getRemoteApiRequestOptions, getLocalApiRequestOptions
16
+
3
17
  ## 1.7.6
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -4,7 +4,11 @@ import { NextRequest } from 'next/server';
4
4
  import * as _websolutespa_bom_mixer_store from '@websolutespa/bom-mixer-store';
5
5
 
6
6
  type ApiRequestOptions = FetchRequestOptions;
7
- declare function getDefaultApiRequestOptions(): ApiRequestOptions;
7
+ /**
8
+ * !!! todo: evaluate authenticated end user bearer
9
+ */
10
+ declare function getLocalApiRequestOptions(): ApiRequestOptions;
11
+ declare function getRemoteApiRequestOptions(): ApiRequestOptions;
8
12
 
9
13
  type ICrudMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | string;
10
14
  type IHandler<T = any> = (request: NextApiRequest, response: NextApiResponse<T>) => Promise<NextApiResponse<T> | void>;
@@ -238,4 +242,4 @@ declare function getStore<T extends IStore>(): Promise<T>;
238
242
 
239
243
  declare function varsHandler(): _websolutespa_bom_mixer_store.IHandler<any>;
240
244
 
241
- export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy, SERVICE_DEFAULT_DEPTH, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, fromCache, getDefaultApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteApiUrl, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, optimizeMany_, optimizeOne_, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy, varsHandler };
245
+ export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy, SERVICE_DEFAULT_DEPTH, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, fromCache, getLocalApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteApiRequestOptions, getRemoteApiUrl, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, optimizeMany_, optimizeOne_, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy, varsHandler };
package/dist/index.js CHANGED
@@ -72,10 +72,11 @@ __export(src_exports, {
72
72
  errorHandler: () => errorHandler,
73
73
  findRoute: () => findRoute,
74
74
  fromCache: () => fromCache,
75
- getDefaultApiRequestOptions: () => getDefaultApiRequestOptions,
75
+ getLocalApiRequestOptions: () => getLocalApiRequestOptions,
76
76
  getLocalApiUrl: () => getLocalApiUrl,
77
77
  getMockStore: () => getMockStore,
78
78
  getMockStoreFromData_: () => getMockStoreFromData_,
79
+ getRemoteApiRequestOptions: () => getRemoteApiRequestOptions,
79
80
  getRemoteApiUrl: () => getRemoteApiUrl,
80
81
  getRemoteStore: () => getRemoteStore,
81
82
  getStore: () => getStore,
@@ -120,7 +121,12 @@ __export(src_exports, {
120
121
  module.exports = __toCommonJS(src_exports);
121
122
 
122
123
  // src/api/api.ts
123
- function getDefaultApiRequestOptions() {
124
+ function getLocalApiRequestOptions() {
125
+ return {
126
+ headers: {}
127
+ };
128
+ }
129
+ function getRemoteApiRequestOptions() {
124
130
  return {
125
131
  // mode: 'cors',
126
132
  headers: {
@@ -178,6 +184,7 @@ async function fromCache(callback, key) {
178
184
  }
179
185
 
180
186
  // src/decorators/category.ts
187
+ var import_bom_core = require("@websolutespa/bom-core");
181
188
  async function decorateCategory_(store, item, params = {}) {
182
189
  if (typeof item.category === "string") {
183
190
  const categories = await store.category.findMany({
@@ -190,9 +197,7 @@ async function decorateCategory_(store, item, params = {}) {
190
197
  if (categories.length > 0) {
191
198
  const category = categories[0];
192
199
  const routes = await store.route.findMany();
193
- const route = routes.find(
194
- (x) => x.market === params.market && x.locale === params.locale && x.isDefault && x.category === category.id
195
- );
200
+ const route = (0, import_bom_core.findRouteOfCategory)(routes, category.id, params.market, params.locale);
196
201
  if (route) {
197
202
  category.href = route.id;
198
203
  }
@@ -210,7 +215,7 @@ async function decorateCategories_(store, items, params = {}) {
210
215
  return items.map((item) => {
211
216
  const category = categories.find((x) => x.id === item.category);
212
217
  if (category) {
213
- const route = routes.find((x) => x.isDefault && x.category === category.id);
218
+ const route = (0, import_bom_core.findRouteOfCategory)(routes, category.id);
214
219
  if (route) {
215
220
  category.href = route.id;
216
221
  }
@@ -272,25 +277,25 @@ async function decorateHrefs_(store, items, params = {}) {
272
277
  }
273
278
 
274
279
  // src/decorators/localizable.ts
275
- var import_bom_core = require("@websolutespa/bom-core");
280
+ var import_bom_core2 = require("@websolutespa/bom-core");
276
281
  async function decorateLocalizable_(item, params = {}) {
277
282
  if (params.locale) {
278
- return (0, import_bom_core.localizeItem)(item, params.locale);
283
+ return (0, import_bom_core2.localizeItem)(item, params.locale);
279
284
  } else {
280
- return (0, import_bom_core.cloneItem)(item);
285
+ return (0, import_bom_core2.cloneItem)(item);
281
286
  }
282
287
  }
283
288
  async function decorateLocalizables_(items, params = {}) {
284
289
  const decoratedItems = [];
285
290
  for (const item of items) {
286
- const decoratedItem = params.locale ? (0, import_bom_core.localizeItem)(item, params.locale) : (0, import_bom_core.cloneItem)(item);
291
+ const decoratedItem = params.locale ? (0, import_bom_core2.localizeItem)(item, params.locale) : (0, import_bom_core2.cloneItem)(item);
287
292
  decoratedItems.push(decoratedItem);
288
293
  }
289
294
  return decoratedItems;
290
295
  }
291
296
 
292
297
  // src/decorators/menu.ts
293
- var import_bom_core2 = require("@websolutespa/bom-core");
298
+ var import_bom_core3 = require("@websolutespa/bom-core");
294
299
  async function decorateMenu_(store, item, params) {
295
300
  const { market, locale } = params;
296
301
  const items = itemsFilteredByMarket_(item.items || [], market);
@@ -344,7 +349,7 @@ function itemHasMarket_(item, market) {
344
349
  }
345
350
  function collectUndecoratedCategories(items, undecoratedCategories = []) {
346
351
  items.forEach((item) => {
347
- if ((0, import_bom_core2.isUndecoratedMenuCategory)(item)) {
352
+ if ((0, import_bom_core3.isUndecoratedMenuCategory)(item)) {
348
353
  undecoratedCategories.push(item);
349
354
  }
350
355
  if (item.items) {
@@ -355,7 +360,7 @@ function collectUndecoratedCategories(items, undecoratedCategories = []) {
355
360
  }
356
361
  function collectUndecoratedPages(items, undecoratedPages = []) {
357
362
  items.forEach((item) => {
358
- if ((0, import_bom_core2.isUndecoratedMenuPage)(item)) {
363
+ if ((0, import_bom_core3.isUndecoratedMenuPage)(item)) {
359
364
  undecoratedPages.push(item);
360
365
  }
361
366
  if (item.items) {
@@ -371,17 +376,17 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
371
376
  category: "",
372
377
  customClass: item.customClass,
373
378
  href: "",
374
- id: item.id || "",
379
+ id: item.id || (0, import_bom_core3.uuidv4)(),
375
380
  items: [],
376
381
  title: "",
377
382
  type: item.type
378
383
  };
379
- const category = typeof item.category === "string" ? categories.find((x) => x.id === item.category) : item.category;
384
+ const category = (0, import_bom_core3.findCategoryInCategories)(categories, item.category);
380
385
  if (category) {
381
386
  decoratedItem.category = category.id;
382
387
  decoratedItem.title = item.title || category.title || "";
383
- decoratedItem.media = decoratedItem.media || category.media;
384
- const route = routes.find((x) => x.isDefault && x.category === category.id);
388
+ decoratedItem.media = item.media || category.media;
389
+ const route = (0, import_bom_core3.findRouteOfCategory)(routes, category.id);
385
390
  if (route) {
386
391
  decoratedItem.href = route.id;
387
392
  } else {
@@ -393,7 +398,7 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
393
398
  }
394
399
  maxDepth--;
395
400
  }
396
- const childCategories = categories.filter((x) => x.category && (typeof x.category === "object" ? x.category.id === category.id : x.category === category.id));
401
+ const childCategories = (0, import_bom_core3.findChildCategories)(categories, category.id).filter((x) => Boolean(x.isHidden) === false);
397
402
  if (childCategories.length) {
398
403
  childCategories.sort((a, b) => {
399
404
  return (a.order || MAX_INT) - (b.order || MAX_INT);
@@ -405,13 +410,15 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
405
410
  maxDepth,
406
411
  items: []
407
412
  }, categories, routes, market, depth + 1));
408
- } else {
409
- const childRoutes = routes.filter((x) => !x.isDefault && x.category === category.id);
410
- childRoutes.sort((a, b) => {
411
- return (a.order || MAX_INT) - (b.order || MAX_INT);
412
- });
413
- decoratedItem.items = childRoutes.map((x) => decorateMenuRoute_(x));
414
413
  }
414
+ const childRoutes = (0, import_bom_core3.findRoutesOfCategory)(routes, category.id, false);
415
+ childRoutes.sort((a, b) => {
416
+ return (a.order || MAX_INT) - (b.order || MAX_INT);
417
+ });
418
+ decoratedItem.items = [
419
+ ...decoratedItem.items || [],
420
+ ...childRoutes.map((x) => decorateMenuRoute_(x))
421
+ ];
415
422
  }
416
423
  return decoratedItem;
417
424
  }
@@ -429,13 +436,13 @@ function decorateMenuRoute_(item) {
429
436
  return decoratedItem;
430
437
  }
431
438
  async function decorateMenuPage_(item, routes, store, params = {}) {
432
- const id = (0, import_bom_core2.isEquatable)(item.page.value) ? item.page.value : item.page.value.id;
439
+ const id = (0, import_bom_core3.isEquatable)(item.page.value) ? item.page.value : item.page.value.id;
433
440
  const route = routes.find(
434
441
  (x) => x.schema === item.page.relationTo && x.page === id
435
442
  );
436
443
  const page = await store[item.page.relationTo].findOne(id, { ...params });
437
444
  const decoratedItem = {
438
- id: item.id || "",
445
+ id: item.id || (0, import_bom_core3.uuidv4)(),
439
446
  type: item.type,
440
447
  title: item.title || page?.title || "",
441
448
  abstract: item.abstract || page?.abstract || "",
@@ -450,7 +457,7 @@ async function decorateMenuPage_(item, routes, store, params = {}) {
450
457
  }
451
458
 
452
459
  // src/decorators/nav.ts
453
- var import_bom_core3 = require("@websolutespa/bom-core");
460
+ var import_bom_core4 = require("@websolutespa/bom-core");
454
461
  async function decorateNav_(store, item, params = {}, routes) {
455
462
  if (!routes) {
456
463
  routes = await store.route.findMany({
@@ -480,12 +487,12 @@ async function decorateNavs_(store, items, params = {}) {
480
487
  return items;
481
488
  }
482
489
  function collectNavs_(item, navs = []) {
483
- if ((0, import_bom_core3.isUndecoratedNav)(item)) {
490
+ if ((0, import_bom_core4.isUndecoratedNav)(item)) {
484
491
  navs.push(item);
485
492
  }
486
- if ((0, import_bom_core3.isArray)(item)) {
493
+ if ((0, import_bom_core4.isArray)(item)) {
487
494
  item.forEach((x) => collectNavs_(x, navs));
488
- } else if ((0, import_bom_core3.isObject)(item)) {
495
+ } else if ((0, import_bom_core4.isObject)(item)) {
489
496
  Object.values(item).forEach((value) => {
490
497
  collectNavs_(value, navs);
491
498
  });
@@ -515,7 +522,7 @@ function decorateNav__(item, routes) {
515
522
  }
516
523
 
517
524
  // src/decorators/optimize.ts
518
- var import_bom_core4 = require("@websolutespa/bom-core");
525
+ var import_bom_core5 = require("@websolutespa/bom-core");
519
526
  async function optimizeOne_(item) {
520
527
  const validEntries = Object.entries(item).filter(([key, value]) => {
521
528
  switch (key) {
@@ -523,7 +530,7 @@ async function optimizeOne_(item) {
523
530
  case "meta":
524
531
  return false;
525
532
  default:
526
- if ((0, import_bom_core4.isUnresolvedRelation)(value) || Array.isArray(value) && value.reduce((p, c) => p && (0, import_bom_core4.isUnresolvedRelation)(c), true)) {
533
+ if ((0, import_bom_core5.isUnresolvedRelation)(value) || Array.isArray(value) && value.reduce((p, c) => p && (0, import_bom_core5.isUnresolvedRelation)(c), true)) {
527
534
  return false;
528
535
  }
529
536
  }
@@ -541,7 +548,7 @@ async function optimizeMany_(items) {
541
548
  }
542
549
 
543
550
  // src/decorators/relation.ts
544
- var import_bom_core5 = require("@websolutespa/bom-core");
551
+ var import_bom_core6 = require("@websolutespa/bom-core");
545
552
  var SERVICE_DEFAULT_DEPTH = 3;
546
553
  async function decorateRelation_(store, item, params = {}) {
547
554
  const depth = params.depth != null ? params.depth : SERVICE_DEFAULT_DEPTH;
@@ -558,7 +565,7 @@ async function decorateRelations_(store, items, params = {}) {
558
565
  return items;
559
566
  }
560
567
  async function collectRelations_(context, item, relations = []) {
561
- if ((0, import_bom_core5.isUnresolvedRelation)(item)) {
568
+ if ((0, import_bom_core6.isUnresolvedRelation)(item)) {
562
569
  const index = relations.findIndex(
563
570
  (x) => x.relationTo === item.relationTo && x.value === item.value
564
571
  );
@@ -587,13 +594,13 @@ async function collectRelations_(context, item, relations = []) {
587
594
  } else {
588
595
  return relations[index].resolvedValue;
589
596
  }
590
- } else if ((0, import_bom_core5.isArray)(item)) {
597
+ } else if ((0, import_bom_core6.isArray)(item)) {
591
598
  const items = [];
592
599
  for (let i = 0; i < item.length; i++) {
593
600
  items[i] = await collectRelations_(context, item[i], relations);
594
601
  }
595
602
  return items;
596
- } else if ((0, import_bom_core5.isObject)(item)) {
603
+ } else if ((0, import_bom_core6.isObject)(item)) {
597
604
  for (const [key, value] of Object.entries(item)) {
598
605
  item[key] = await collectRelations_(context, value, relations);
599
606
  }
@@ -612,12 +619,12 @@ async function decorateSchemas_(store, items, schema) {
612
619
  }
613
620
 
614
621
  // src/local/local.api.ts
615
- var import_bom_core6 = require("@websolutespa/bom-core");
622
+ var import_bom_core7 = require("@websolutespa/bom-core");
616
623
  var API_URL = process.env.NEXT_PUBLIC_URL === "https://" ? process.env.NEXT_PUBLIC_MOCK_FALLBACK_URL : process.env.NEXT_PUBLIC_URL;
617
624
  var API_BASE = process.env.NEXT_PUBLIC_API || "/api";
618
625
  function getLocalApiUrl(pathname) {
619
- let url = `${import_bom_core6.isBrowser ? window.location.origin : API_URL}${API_BASE}${pathname}`;
620
- url = import_bom_core6.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
626
+ let url = `${import_bom_core7.isBrowser ? window.location.origin : API_URL}${API_BASE}${pathname}`;
627
+ url = import_bom_core7.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
621
628
  return url;
622
629
  }
623
630
  async function localApiFetch(pathname, options = {}, serviceOptions) {
@@ -626,9 +633,9 @@ async function localApiFetch(pathname, options = {}, serviceOptions) {
626
633
  url.searchParams.append("locale", serviceOptions.locale);
627
634
  url.searchParams.append("market", serviceOptions.market);
628
635
  }
629
- const apiOptions = (0, import_bom_core6.merge)({ ...getDefaultApiRequestOptions() }, options);
636
+ const apiOptions = (0, import_bom_core7.merge)({ ...getLocalApiRequestOptions() }, options);
630
637
  console.log("localApiFetch", apiOptions.method, url.href);
631
- const apiResponse = await (0, import_bom_core6.httpFetch)(url.href, apiOptions);
638
+ const apiResponse = await (0, import_bom_core7.httpFetch)(url.href, apiOptions);
632
639
  return apiResponse;
633
640
  }
634
641
  async function localApiGet(url, options = {}, serviceOptions) {
@@ -667,8 +674,8 @@ function isApiRequest(request) {
667
674
  }
668
675
 
669
676
  // src/mock/mock.service.ts
670
- var import_bom_core7 = require("@websolutespa/bom-core");
671
- var MockService = class extends import_bom_core7.JsonService {
677
+ var import_bom_core8 = require("@websolutespa/bom-core");
678
+ var MockService = class extends import_bom_core8.JsonService {
672
679
  constructor(items, store) {
673
680
  super(items);
674
681
  this.store = store;
@@ -753,19 +760,19 @@ var MockPageService = class extends MockService {
753
760
  };
754
761
 
755
762
  // src/mock/mock.api.ts
756
- var import_bom_core8 = require("@websolutespa/bom-core");
763
+ var import_bom_core9 = require("@websolutespa/bom-core");
757
764
  var API_URL2 = process.env.NEXT_PUBLIC_URL;
758
765
  var API_BASE3 = process.env.NEXT_PUBLIC_API || "/api";
759
766
  function getMockApiUrl(pathname) {
760
767
  let url = `${API_URL2}${API_BASE3}/_mock${pathname}`;
761
- url = import_bom_core8.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
768
+ url = import_bom_core9.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
762
769
  return url;
763
770
  }
764
771
  async function mockApiFetch(pathname, options = {}) {
765
772
  const url = getMockApiUrl(pathname);
766
- const apiOptions = (0, import_bom_core8.merge)({ ...getDefaultApiRequestOptions() }, options);
773
+ const apiOptions = (0, import_bom_core9.merge)({ ...getLocalApiRequestOptions() }, options);
767
774
  console.log("mockApiFetch", apiOptions.method, url);
768
- const apiResponse = await (0, import_bom_core8.httpFetch)(url, apiOptions);
775
+ const apiResponse = await (0, import_bom_core9.httpFetch)(url, apiOptions);
769
776
  return apiResponse;
770
777
  }
771
778
  async function mockApiGet(url, options = {}) {
@@ -785,7 +792,7 @@ async function mockApiDelete(url, options = {}) {
785
792
  }
786
793
 
787
794
  // src/store/store.handler.ts
788
- var import_bom_core14 = require("@websolutespa/bom-core");
795
+ var import_bom_core15 = require("@websolutespa/bom-core");
789
796
 
790
797
  // src/static/static.ts
791
798
  var staticCollections = [{
@@ -1060,7 +1067,7 @@ var KNOWN_COLLECTIONS = [
1060
1067
  var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
1061
1068
 
1062
1069
  // src/mock/mock.store.ts
1063
- var import_bom_core10 = require("@websolutespa/bom-core");
1070
+ var import_bom_core11 = require("@websolutespa/bom-core");
1064
1071
 
1065
1072
  // src/fs/fs.service.ts
1066
1073
  var fs = __toESM(require("fs"));
@@ -1088,8 +1095,8 @@ async function fsReadJson(pathname) {
1088
1095
  }
1089
1096
 
1090
1097
  // src/static/static.service.ts
1091
- var import_bom_core9 = require("@websolutespa/bom-core");
1092
- var StaticService = class extends import_bom_core9.JsonService {
1098
+ var import_bom_core10 = require("@websolutespa/bom-core");
1099
+ var StaticService = class extends import_bom_core10.JsonService {
1093
1100
  constructor(config, store) {
1094
1101
  super([]);
1095
1102
  this.loaded = false;
@@ -1117,7 +1124,7 @@ var StaticService = class extends import_bom_core9.JsonService {
1117
1124
  const config = this.config;
1118
1125
  const src = config.src;
1119
1126
  if (typeof src === "string") {
1120
- const response = await (0, import_bom_core9.httpGet)(src, {});
1127
+ const response = await (0, import_bom_core10.httpGet)(src, {});
1121
1128
  items = response.items;
1122
1129
  } else if (typeof src === "function") {
1123
1130
  if (src instanceof Promise) {
@@ -1233,7 +1240,7 @@ function getMockStoreFromData_(data) {
1233
1240
  return store;
1234
1241
  }
1235
1242
  async function getStoreData_() {
1236
- if (import_bom_core10.isDevelopment) {
1243
+ if (import_bom_core11.isDevelopment) {
1237
1244
  const path = require("path");
1238
1245
  const pathname = path.join(process.cwd(), ".mixer", "store.json");
1239
1246
  return await fsReadJson(pathname) || {};
@@ -1249,17 +1256,17 @@ async function getMockStore_() {
1249
1256
  }
1250
1257
  async function getMockStore() {
1251
1258
  return fromCache(async () => {
1252
- if (!import_bom_core10.isDevelopment) {
1259
+ if (!import_bom_core11.isDevelopment) {
1253
1260
  console.warn("getMockStore");
1254
1261
  }
1255
1262
  const store = await getMockStore_();
1256
1263
  return store;
1257
- }, import_bom_core10.isDevelopment ? void 0 : "STORE_MOCK_");
1264
+ }, import_bom_core11.isDevelopment ? void 0 : "STORE_MOCK_");
1258
1265
  }
1259
1266
 
1260
1267
  // src/cached/cached.service.ts
1261
- var import_bom_core11 = require("@websolutespa/bom-core");
1262
- var CachedService = class extends import_bom_core11.JsonService {
1268
+ var import_bom_core12 = require("@websolutespa/bom-core");
1269
+ var CachedService = class extends import_bom_core12.JsonService {
1263
1270
  constructor(service, options = {}) {
1264
1271
  super([]);
1265
1272
  this.cache_ = /* @__PURE__ */ new Map();
@@ -1298,7 +1305,7 @@ var CachedService = class extends import_bom_core11.JsonService {
1298
1305
  });
1299
1306
  }
1300
1307
  async findOne(id, params = {}) {
1301
- const serializedParams = (0, import_bom_core11.qsSerialize)(params);
1308
+ const serializedParams = (0, import_bom_core12.qsSerialize)(params);
1302
1309
  const key = `findOne[${id}]?${serializedParams}`;
1303
1310
  return await this.fromCache_(async () => {
1304
1311
  return await this.service_.findOne(id, params);
@@ -1307,7 +1314,7 @@ var CachedService = class extends import_bom_core11.JsonService {
1307
1314
  async findMany(params = {}) {
1308
1315
  if (storeStrategy === "decoratedApi" /* DecoratedApi */) {
1309
1316
  const { market, locale, ...otherParams } = params;
1310
- const serializedParams = (0, import_bom_core11.qsSerialize)({ market, locale });
1317
+ const serializedParams = (0, import_bom_core12.qsSerialize)({ market, locale });
1311
1318
  const key = `findMany?${serializedParams}`;
1312
1319
  let items = await this.fromCache_(async () => {
1313
1320
  return await this.service_.findMany({ market, locale });
@@ -1320,7 +1327,7 @@ var CachedService = class extends import_bom_core11.JsonService {
1320
1327
  }
1321
1328
  return items;
1322
1329
  } else {
1323
- const serializedParams = (0, import_bom_core11.qsSerialize)(params);
1330
+ const serializedParams = (0, import_bom_core12.qsSerialize)(params);
1324
1331
  const key = `findMany?${serializedParams}`;
1325
1332
  return await this.fromCache_(async () => {
1326
1333
  return await this.service_.findMany(params);
@@ -1328,7 +1335,7 @@ var CachedService = class extends import_bom_core11.JsonService {
1328
1335
  }
1329
1336
  }
1330
1337
  async findPaged(params = {}) {
1331
- const serializedParams = (0, import_bom_core11.qsSerialize)(params);
1338
+ const serializedParams = (0, import_bom_core12.qsSerialize)(params);
1332
1339
  const key = `findPaged?${serializedParams}`;
1333
1340
  return await this.fromCache_(async () => {
1334
1341
  return await this.service_.findPaged(params);
@@ -1346,22 +1353,22 @@ var CachedService = class extends import_bom_core11.JsonService {
1346
1353
  };
1347
1354
 
1348
1355
  // src/remote/remote.service.ts
1349
- var import_bom_core13 = require("@websolutespa/bom-core");
1356
+ var import_bom_core14 = require("@websolutespa/bom-core");
1350
1357
 
1351
1358
  // src/remote/remote.api.ts
1352
- var import_bom_core12 = require("@websolutespa/bom-core");
1359
+ var import_bom_core13 = require("@websolutespa/bom-core");
1353
1360
  var API_URL3 = process.env.STORE_URL;
1354
1361
  var API_BASE4 = process.env.STORE_API || "/api";
1355
1362
  function getRemoteApiUrl(pathname) {
1356
1363
  let url = `${API_URL3}${API_BASE4}${pathname}`;
1357
- url = import_bom_core12.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
1364
+ url = import_bom_core13.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
1358
1365
  return url;
1359
1366
  }
1360
1367
  async function remoteApiFetch(pathname, options = {}) {
1361
1368
  const url = getRemoteApiUrl(pathname);
1362
- const apiOptions = (0, import_bom_core12.merge)({ ...getDefaultApiRequestOptions() }, options);
1369
+ const apiOptions = (0, import_bom_core13.merge)({ ...getRemoteApiRequestOptions() }, options);
1363
1370
  console.log("remoteApiFetch", apiOptions.method, url);
1364
- const apiResponse = await (0, import_bom_core12.httpFetch)(url, apiOptions);
1371
+ const apiResponse = await (0, import_bom_core13.httpFetch)(url, apiOptions);
1365
1372
  return apiResponse;
1366
1373
  }
1367
1374
  async function remoteApiGet(url, options = {}) {
@@ -1398,7 +1405,7 @@ var RemoteService = class {
1398
1405
  async findOne(id, params = {}) {
1399
1406
  params.richText = String(params.richText) === "true" ? true : false;
1400
1407
  params.draft = RemoteServiceStrategy.draft;
1401
- const query = (0, import_bom_core13.qsSerialize)(params);
1408
+ const query = (0, import_bom_core14.qsSerialize)(params);
1402
1409
  const search = query ? `?${query}` : "";
1403
1410
  const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
1404
1411
  const item = await remoteApiGet(url);
@@ -1411,7 +1418,7 @@ var RemoteService = class {
1411
1418
  params.richText = String(params.richText) === "true" ? true : false;
1412
1419
  params.draft = RemoteServiceStrategy.draft;
1413
1420
  params.pagination = false;
1414
- const query = (0, import_bom_core13.qsSerialize)(params);
1421
+ const query = (0, import_bom_core14.qsSerialize)(params);
1415
1422
  const search = query ? `?${query}` : "";
1416
1423
  const url = `/${this.key}${search}`;
1417
1424
  const response = await remoteApiGet(url);
@@ -1422,7 +1429,7 @@ var RemoteService = class {
1422
1429
  params.richText = String(params.richText) === "true" ? true : false;
1423
1430
  params.draft = RemoteServiceStrategy.draft;
1424
1431
  params.pagination = true;
1425
- const query = (0, import_bom_core13.qsSerialize)(params);
1432
+ const query = (0, import_bom_core14.qsSerialize)(params);
1426
1433
  const search = query ? `?${query}` : "";
1427
1434
  const url = `/${this.key}${search}`;
1428
1435
  const response = await remoteApiGet(url);
@@ -1451,7 +1458,7 @@ var RemoteService = class {
1451
1458
  }
1452
1459
  }
1453
1460
  };
1454
- const query = (0, import_bom_core13.qsSerialize)(params);
1461
+ const query = (0, import_bom_core14.qsSerialize)(params);
1455
1462
  const search = query ? `?${query}` : "";
1456
1463
  const url = `/${this.key}${search}`;
1457
1464
  const item = await remoteApiDelete(url);
@@ -1631,7 +1638,7 @@ function collectionGet(storePromise) {
1631
1638
  const collection = collections[0];
1632
1639
  const id = collections[1];
1633
1640
  const qs = Object.entries(query).map((kv) => kv.join("=")).join("&");
1634
- const params = (0, import_bom_core14.qsDeserialize)(qs);
1641
+ const params = (0, import_bom_core15.qsDeserialize)(qs);
1635
1642
  if (!COLLECTIONS.includes(collection)) {
1636
1643
  console.error("storeHandler.collectionGet", "method not allowed", collection);
1637
1644
  return response.status(405).send("method not allowed");
@@ -1643,7 +1650,7 @@ function collectionGet(storePromise) {
1643
1650
  return response.status(405).send("method not allowed");
1644
1651
  }
1645
1652
  if (id) {
1646
- const item = await service.findOne((0, import_bom_core14.asEquatable)(id), params);
1653
+ const item = await service.findOne((0, import_bom_core15.asEquatable)(id), params);
1647
1654
  if (item) {
1648
1655
  return response.status(200).json(item);
1649
1656
  } else {
@@ -1763,8 +1770,8 @@ function storeIndexHandler() {
1763
1770
  return apiHandler({
1764
1771
  get: async (request, response) => {
1765
1772
  try {
1766
- const market = import_bom_core14.defaultMarket;
1767
- const locale = import_bom_core14.defaultLocale;
1773
+ const market = import_bom_core15.defaultMarket;
1774
+ const locale = import_bom_core15.defaultLocale;
1768
1775
  if (!Array.isArray(COLLECTIONS) || COLLECTIONS?.length === 0) {
1769
1776
  console.error("apiHome.collectionGet", "collections not found", COLLECTIONS);
1770
1777
  return response.status(405).send("method not allowed");
@@ -2031,10 +2038,10 @@ async function storeApiDelete(url, options = {}) {
2031
2038
  }
2032
2039
 
2033
2040
  // src/vars/vars.handler.ts
2034
- var import_bom_core16 = require("@websolutespa/bom-core");
2041
+ var import_bom_core17 = require("@websolutespa/bom-core");
2035
2042
 
2036
2043
  // ../models/src/route/route.service.ts
2037
- var import_bom_core15 = require("@websolutespa/bom-core");
2044
+ var import_bom_core16 = require("@websolutespa/bom-core");
2038
2045
  async function getRouteLinkTree(market, locale) {
2039
2046
  const store = await getStore();
2040
2047
  const routes = await store.route.findMany({
@@ -2048,7 +2055,7 @@ async function getRouteLinkTree(market, locale) {
2048
2055
  }
2049
2056
  });
2050
2057
  const categories = await store.category.findMany();
2051
- const rootCategory = (0, import_bom_core15.getRootCategory)(categories);
2058
+ const rootCategory = (0, import_bom_core16.getRootCategory)(categories);
2052
2059
  if (rootCategory) {
2053
2060
  const root = categoryToRouteLink(routes, categories, rootCategory, locale);
2054
2061
  return root;
@@ -2056,15 +2063,13 @@ async function getRouteLinkTree(market, locale) {
2056
2063
  return void 0;
2057
2064
  }
2058
2065
  function categoryToRouteLink(routes, categories, category, locale) {
2059
- const route = routes.find(
2060
- (r) => r.category === category.id && r.isDefault
2061
- );
2066
+ const route = (0, import_bom_core16.findRouteOfCategory)(routes, category.id);
2062
2067
  if (!route) {
2063
2068
  return void 0;
2064
2069
  }
2065
- const rootCategory = (0, import_bom_core15.getRootCategory)(categories);
2070
+ const rootCategory = (0, import_bom_core16.getRootCategory)(categories);
2066
2071
  const childCategories = categories.filter((x) => {
2067
- const parentId = x.category ? (0, import_bom_core15.asCategoryId)(x.category) : null;
2072
+ const parentId = (0, import_bom_core16.asCategoryId)(x.category);
2068
2073
  return rootCategory && rootCategory.id === category.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
2069
2074
  });
2070
2075
  const routeLink = newRouteLink(category, route, locale);
@@ -2076,7 +2081,7 @@ function newRouteLink(category, route, locale) {
2076
2081
  const id = route?.page || category.id;
2077
2082
  const media = category.media || route?.media;
2078
2083
  const schema = route?.schema || category?.schema || "unknown";
2079
- const title = (0, import_bom_core15.localize)(category.title || route?.title || "untitled", locale);
2084
+ const title = (0, import_bom_core16.localize)(category.title || route?.title || "untitled", locale);
2080
2085
  const routeLink = {
2081
2086
  category: category.id,
2082
2087
  href,
@@ -2179,10 +2184,10 @@ function varsHandler() {
2179
2184
  const { locale = defaultLocale3, market = defaultMaket } = request.query || {};
2180
2185
  const layout = typeof locale === "string" && typeof market === "string" ? await getLayout(market, locale) : void 0;
2181
2186
  const info = {
2182
- production: import_bom_core16.isProduction,
2183
- development: import_bom_core16.isDevelopment,
2184
- origin: (0, import_bom_core16.getOrigin)(request.headers),
2185
- host: (0, import_bom_core16.getHost)(request.headers),
2187
+ production: import_bom_core17.isProduction,
2188
+ development: import_bom_core17.isDevelopment,
2189
+ origin: (0, import_bom_core17.getOrigin)(request.headers),
2190
+ host: (0, import_bom_core17.getHost)(request.headers),
2186
2191
  headers: { ...sortKeys(request.headers) },
2187
2192
  env: { ...getFilteredEnv(process.env) },
2188
2193
  layout: { ...sortKeys(layout) }
@@ -2338,10 +2343,11 @@ function varsHandler() {
2338
2343
  errorHandler,
2339
2344
  findRoute,
2340
2345
  fromCache,
2341
- getDefaultApiRequestOptions,
2346
+ getLocalApiRequestOptions,
2342
2347
  getLocalApiUrl,
2343
2348
  getMockStore,
2344
2349
  getMockStoreFromData_,
2350
+ getRemoteApiRequestOptions,
2345
2351
  getRemoteApiUrl,
2346
2352
  getRemoteStore,
2347
2353
  getStore,
package/dist/index.mjs CHANGED
@@ -7,7 +7,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
  });
8
8
 
9
9
  // src/api/api.ts
10
- function getDefaultApiRequestOptions() {
10
+ function getLocalApiRequestOptions() {
11
+ return {
12
+ headers: {}
13
+ };
14
+ }
15
+ function getRemoteApiRequestOptions() {
11
16
  return {
12
17
  // mode: 'cors',
13
18
  headers: {
@@ -65,6 +70,7 @@ async function fromCache(callback, key) {
65
70
  }
66
71
 
67
72
  // src/decorators/category.ts
73
+ import { findRouteOfCategory } from "@websolutespa/bom-core";
68
74
  async function decorateCategory_(store, item, params = {}) {
69
75
  if (typeof item.category === "string") {
70
76
  const categories = await store.category.findMany({
@@ -77,9 +83,7 @@ async function decorateCategory_(store, item, params = {}) {
77
83
  if (categories.length > 0) {
78
84
  const category = categories[0];
79
85
  const routes = await store.route.findMany();
80
- const route = routes.find(
81
- (x) => x.market === params.market && x.locale === params.locale && x.isDefault && x.category === category.id
82
- );
86
+ const route = findRouteOfCategory(routes, category.id, params.market, params.locale);
83
87
  if (route) {
84
88
  category.href = route.id;
85
89
  }
@@ -97,7 +101,7 @@ async function decorateCategories_(store, items, params = {}) {
97
101
  return items.map((item) => {
98
102
  const category = categories.find((x) => x.id === item.category);
99
103
  if (category) {
100
- const route = routes.find((x) => x.isDefault && x.category === category.id);
104
+ const route = findRouteOfCategory(routes, category.id);
101
105
  if (route) {
102
106
  category.href = route.id;
103
107
  }
@@ -178,9 +182,14 @@ async function decorateLocalizables_(items, params = {}) {
178
182
 
179
183
  // src/decorators/menu.ts
180
184
  import {
185
+ findCategoryInCategories,
186
+ findChildCategories,
187
+ findRouteOfCategory as findRouteOfCategory2,
188
+ findRoutesOfCategory,
181
189
  isEquatable,
182
190
  isUndecoratedMenuCategory,
183
- isUndecoratedMenuPage
191
+ isUndecoratedMenuPage,
192
+ uuidv4
184
193
  } from "@websolutespa/bom-core";
185
194
  async function decorateMenu_(store, item, params) {
186
195
  const { market, locale } = params;
@@ -262,17 +271,17 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
262
271
  category: "",
263
272
  customClass: item.customClass,
264
273
  href: "",
265
- id: item.id || "",
274
+ id: item.id || uuidv4(),
266
275
  items: [],
267
276
  title: "",
268
277
  type: item.type
269
278
  };
270
- const category = typeof item.category === "string" ? categories.find((x) => x.id === item.category) : item.category;
279
+ const category = findCategoryInCategories(categories, item.category);
271
280
  if (category) {
272
281
  decoratedItem.category = category.id;
273
282
  decoratedItem.title = item.title || category.title || "";
274
- decoratedItem.media = decoratedItem.media || category.media;
275
- const route = routes.find((x) => x.isDefault && x.category === category.id);
283
+ decoratedItem.media = item.media || category.media;
284
+ const route = findRouteOfCategory2(routes, category.id);
276
285
  if (route) {
277
286
  decoratedItem.href = route.id;
278
287
  } else {
@@ -284,7 +293,7 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
284
293
  }
285
294
  maxDepth--;
286
295
  }
287
- const childCategories = categories.filter((x) => x.category && (typeof x.category === "object" ? x.category.id === category.id : x.category === category.id));
296
+ const childCategories = findChildCategories(categories, category.id).filter((x) => Boolean(x.isHidden) === false);
288
297
  if (childCategories.length) {
289
298
  childCategories.sort((a, b) => {
290
299
  return (a.order || MAX_INT) - (b.order || MAX_INT);
@@ -296,13 +305,15 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
296
305
  maxDepth,
297
306
  items: []
298
307
  }, categories, routes, market, depth + 1));
299
- } else {
300
- const childRoutes = routes.filter((x) => !x.isDefault && x.category === category.id);
301
- childRoutes.sort((a, b) => {
302
- return (a.order || MAX_INT) - (b.order || MAX_INT);
303
- });
304
- decoratedItem.items = childRoutes.map((x) => decorateMenuRoute_(x));
305
308
  }
309
+ const childRoutes = findRoutesOfCategory(routes, category.id, false);
310
+ childRoutes.sort((a, b) => {
311
+ return (a.order || MAX_INT) - (b.order || MAX_INT);
312
+ });
313
+ decoratedItem.items = [
314
+ ...decoratedItem.items || [],
315
+ ...childRoutes.map((x) => decorateMenuRoute_(x))
316
+ ];
306
317
  }
307
318
  return decoratedItem;
308
319
  }
@@ -326,7 +337,7 @@ async function decorateMenuPage_(item, routes, store, params = {}) {
326
337
  );
327
338
  const page = await store[item.page.relationTo].findOne(id, { ...params });
328
339
  const decoratedItem = {
329
- id: item.id || "",
340
+ id: item.id || uuidv4(),
330
341
  type: item.type,
331
342
  title: item.title || page?.title || "",
332
343
  abstract: item.abstract || page?.abstract || "",
@@ -517,7 +528,7 @@ async function localApiFetch(pathname, options = {}, serviceOptions) {
517
528
  url.searchParams.append("locale", serviceOptions.locale);
518
529
  url.searchParams.append("market", serviceOptions.market);
519
530
  }
520
- const apiOptions = merge({ ...getDefaultApiRequestOptions() }, options);
531
+ const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);
521
532
  console.log("localApiFetch", apiOptions.method, url.href);
522
533
  const apiResponse = await httpFetch(url.href, apiOptions);
523
534
  return apiResponse;
@@ -654,7 +665,7 @@ function getMockApiUrl(pathname) {
654
665
  }
655
666
  async function mockApiFetch(pathname, options = {}) {
656
667
  const url = getMockApiUrl(pathname);
657
- const apiOptions = merge2({ ...getDefaultApiRequestOptions() }, options);
668
+ const apiOptions = merge2({ ...getLocalApiRequestOptions() }, options);
658
669
  console.log("mockApiFetch", apiOptions.method, url);
659
670
  const apiResponse = await httpFetch2(url, apiOptions);
660
671
  return apiResponse;
@@ -1250,7 +1261,7 @@ function getRemoteApiUrl(pathname) {
1250
1261
  }
1251
1262
  async function remoteApiFetch(pathname, options = {}) {
1252
1263
  const url = getRemoteApiUrl(pathname);
1253
- const apiOptions = merge3({ ...getDefaultApiRequestOptions() }, options);
1264
+ const apiOptions = merge3({ ...getRemoteApiRequestOptions() }, options);
1254
1265
  console.log("remoteApiFetch", apiOptions.method, url);
1255
1266
  const apiResponse = await httpFetch3(url, apiOptions);
1256
1267
  return apiResponse;
@@ -1925,7 +1936,7 @@ async function storeApiDelete(url, options = {}) {
1925
1936
  import { getHost, getOrigin, isDevelopment as isDevelopment2, isProduction } from "@websolutespa/bom-core";
1926
1937
 
1927
1938
  // ../models/src/route/route.service.ts
1928
- import { asCategoryId, defaultLocale as defaultLocale2, defaultMarket as defaultMarket2, getRootCategory, localize } from "@websolutespa/bom-core";
1939
+ import { asCategoryId, defaultLocale as defaultLocale2, defaultMarket as defaultMarket2, findRouteOfCategory as findRouteOfCategory3, getRootCategory, localize } from "@websolutespa/bom-core";
1929
1940
  async function getRouteLinkTree(market, locale) {
1930
1941
  const store = await getStore();
1931
1942
  const routes = await store.route.findMany({
@@ -1947,15 +1958,13 @@ async function getRouteLinkTree(market, locale) {
1947
1958
  return void 0;
1948
1959
  }
1949
1960
  function categoryToRouteLink(routes, categories, category, locale) {
1950
- const route = routes.find(
1951
- (r) => r.category === category.id && r.isDefault
1952
- );
1961
+ const route = findRouteOfCategory3(routes, category.id);
1953
1962
  if (!route) {
1954
1963
  return void 0;
1955
1964
  }
1956
1965
  const rootCategory = getRootCategory(categories);
1957
1966
  const childCategories = categories.filter((x) => {
1958
- const parentId = x.category ? asCategoryId(x.category) : null;
1967
+ const parentId = asCategoryId(x.category);
1959
1968
  return rootCategory && rootCategory.id === category.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
1960
1969
  });
1961
1970
  const routeLink = newRouteLink(category, route, locale);
@@ -2228,10 +2237,11 @@ export {
2228
2237
  errorHandler,
2229
2238
  findRoute,
2230
2239
  fromCache,
2231
- getDefaultApiRequestOptions,
2240
+ getLocalApiRequestOptions,
2232
2241
  getLocalApiUrl,
2233
2242
  getMockStore,
2234
2243
  getMockStoreFromData_,
2244
+ getRemoteApiRequestOptions,
2235
2245
  getRemoteApiUrl,
2236
2246
  getRemoteStore,
2237
2247
  getStore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-store",
3
- "version": "1.7.6",
3
+ "version": "1.7.8",
4
4
  "description": "Mixer Store module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "lint": "eslint *.ts*",
17
17
  "test": "jest",
18
- "test-watch": "npm test -- --watch",
18
+ "test-watch": "npm test -- --watch --silent=false",
19
19
  "coverage:integration": "npm run test -- --coverage",
20
20
  "coverage": "run-s -c --silent coverage:*",
21
21
  "compile": "tsup ./src/index.ts --format esm,cjs --dts",
package/src/api/api.ts CHANGED
@@ -2,7 +2,18 @@ import { FetchRequestOptions } from '@websolutespa/bom-core';
2
2
 
3
3
  export type ApiRequestOptions = FetchRequestOptions;
4
4
 
5
- export function getDefaultApiRequestOptions(): ApiRequestOptions {
5
+ /**
6
+ * !!! todo: evaluate authenticated end user bearer
7
+ */
8
+
9
+ export function getLocalApiRequestOptions(): ApiRequestOptions {
10
+ return {
11
+ headers: {
12
+ },
13
+ };
14
+ }
15
+
16
+ export function getRemoteApiRequestOptions(): ApiRequestOptions {
6
17
  return {
7
18
  // mode: 'cors',
8
19
  headers: {
@@ -1,4 +1,4 @@
1
- import { ICategorized, ICategory, IRoute, IStore, QueryParams } from '@websolutespa/bom-core';
1
+ import { ICategorized, ICategory, IRoute, IStore, QueryParams, findRouteOfCategory } from '@websolutespa/bom-core';
2
2
 
3
3
  export async function decorateCategory_<T extends ICategorized = ICategorized>(store: IStore, item: T, params: QueryParams = {}): Promise<T | (T & { category: ICategory })> {
4
4
  if (typeof item.category === 'string') {
@@ -12,12 +12,7 @@ export async function decorateCategory_<T extends ICategorized = ICategorized>(s
12
12
  if (categories.length > 0) {
13
13
  const category = categories[0];
14
14
  const routes = await store.route.findMany<IRoute>();
15
- const route = routes.find(x =>
16
- x.market === params.market &&
17
- x.locale === params.locale &&
18
- x.isDefault &&
19
- x.category === category.id
20
- );
15
+ const route = findRouteOfCategory(routes, category.id, params.market, params.locale);
21
16
  if (route) {
22
17
  category.href = route.id;
23
18
  }
@@ -36,7 +31,7 @@ export async function decorateCategories_<T extends ICategorized = ICategorized>
36
31
  return items.map(item => {
37
32
  const category = categories.find(x => x.id === item.category);
38
33
  if (category) {
39
- const route = routes.find(x => x.isDefault && x.category === category.id);
34
+ const route = findRouteOfCategory(routes, category.id);
40
35
  if (route) {
41
36
  category.href = route.id;
42
37
  }
@@ -1,7 +1,10 @@
1
1
  import {
2
- ICategorized, ICategory, IMenu, IMenuCategory, IMenuItem, IMenuPage, IMenuRoute, IRoute,
3
- IStore, IUndecoratedMenu, IUndecoratedMenuCategory, IUndecoratedMenuItem, IUndecoratedMenuPage,
4
- QueryParams, isEquatable, isUndecoratedMenuCategory, isUndecoratedMenuPage
2
+ ICategorized, ICategory, IMenu, IMenuCategory, IMenuItem, IMenuPage, IMenuRoute, IRoute, IStore,
3
+ IUndecoratedMenu, IUndecoratedMenuCategory, IUndecoratedMenuItem, IUndecoratedMenuPage, QueryParams,
4
+ findCategoryInCategories,
5
+ findChildCategories,
6
+ findRouteOfCategory, findRoutesOfCategory, isEquatable, isUndecoratedMenuCategory, isUndecoratedMenuPage,
7
+ uuidv4
5
8
  } from '@websolutespa/bom-core';
6
9
 
7
10
  export async function decorateMenu_(store: IStore, item: IUndecoratedMenu, params: { market: string, locale: string }): Promise<IMenu> {
@@ -100,21 +103,21 @@ function decorateMenuCategory_(
100
103
  category: '',
101
104
  customClass: item.customClass,
102
105
  href: '',
103
- id: item.id || '',
106
+ id: item.id || uuidv4(),
104
107
  items: [],
105
108
  title: '',
106
109
  type: item.type,
107
110
  };
108
- const category = (typeof item.category === 'string' ? categories.find(x => x.id === item.category) : item.category) as ICategory;
111
+ const category = findCategoryInCategories(categories, item.category);
109
112
  if (category) {
110
113
  // assigning category id
111
114
  decoratedItem.category = category.id;
112
115
  // assigning category title
113
116
  decoratedItem.title = item.title || category.title || '';
114
117
  // assigning current or category media
115
- decoratedItem.media = decoratedItem.media || category.media;
118
+ decoratedItem.media = item.media || category.media;
116
119
  // find category's index page route
117
- const route = routes.find(x => x.isDefault && x.category === category.id);
120
+ const route = findRouteOfCategory(routes, category.id);
118
121
  if (route) {
119
122
  // hasLink
120
123
  decoratedItem.href = route.id;
@@ -130,11 +133,7 @@ function decorateMenuCategory_(
130
133
  maxDepth--;
131
134
  }
132
135
  // search child categories
133
- const childCategories = categories.filter(x => (
134
- x.category && (typeof x.category === 'object' ?
135
- x.category.id === category.id :
136
- x.category === category.id)
137
- ));
136
+ const childCategories = findChildCategories(categories, category.id).filter(x => Boolean(x.isHidden) === false);
138
137
  if (childCategories.length) {
139
138
  // sort child categories
140
139
  childCategories.sort((a, b) => {
@@ -147,15 +146,18 @@ function decorateMenuCategory_(
147
146
  maxDepth,
148
147
  items: [],
149
148
  } as IUndecoratedMenuCategory, categories, routes, market, depth + 1));
150
- } else {
151
- // find child routes
152
- const childRoutes = routes.filter(x => !x.isDefault && x.category === category.id);
153
- // sort child routes
154
- childRoutes.sort((a, b) => {
155
- return (a.order || MAX_INT) - (b.order || MAX_INT);
156
- });
157
- decoratedItem.items = childRoutes.map(x => decorateMenuRoute_(x));
158
149
  }
150
+ // find child routes
151
+ const childRoutes = findRoutesOfCategory(routes, category.id, false);
152
+ // console.log('childRoutes', childRoutes, category.id);
153
+ // sort child routes
154
+ childRoutes.sort((a, b) => {
155
+ return (a.order || MAX_INT) - (b.order || MAX_INT);
156
+ });
157
+ decoratedItem.items = [
158
+ ...(decoratedItem.items || []),
159
+ ...childRoutes.map(x => decorateMenuRoute_(x)),
160
+ ];
159
161
  }
160
162
  return decoratedItem;
161
163
  }
@@ -189,7 +191,7 @@ async function decorateMenuPage_(
189
191
  );
190
192
  const page = await store[item.page.relationTo].findOne<ICategorized>(id, { ...params });
191
193
  const decoratedItem: IMenuPage = {
192
- id: item.id || '',
194
+ id: item.id || uuidv4(),
193
195
  type: item.type,
194
196
  title: item.title || page?.title || '',
195
197
  abstract: item.abstract || page?.abstract || '',
@@ -1,5 +1,5 @@
1
1
  import { httpFetch, isBrowser, merge } from '@websolutespa/bom-core';
2
- import { ApiRequestOptions, getDefaultApiRequestOptions } from '../api/api';
2
+ import { ApiRequestOptions, getLocalApiRequestOptions } from '../api/api';
3
3
 
4
4
  /**
5
5
  * This methods handle api requests / responses to local api (mixer)
@@ -27,7 +27,7 @@ export async function localApiFetch<T = unknown>(pathname: string, options: ApiR
27
27
  url.searchParams.append('locale', serviceOptions.locale);
28
28
  url.searchParams.append('market', serviceOptions.market);
29
29
  }
30
- const apiOptions = merge({ ...getDefaultApiRequestOptions() }, options);
30
+ const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);
31
31
  console.log('localApiFetch', apiOptions.method, url.href);
32
32
  const apiResponse = await httpFetch(url.href, apiOptions);
33
33
  // console.log('localApiFetch', pathname, apiResponse);
@@ -1,10 +1,9 @@
1
1
  import { httpFetch, isBrowser, merge } from '@websolutespa/bom-core';
2
- import { ApiRequestOptions, getDefaultApiRequestOptions } from '../api/api';
2
+ import { ApiRequestOptions, getLocalApiRequestOptions } from '../api/api';
3
3
 
4
4
  /**
5
5
  * This methods handle api requests / responses to local /api/_mock data
6
6
  */
7
-
8
7
  const API_URL = process.env.NEXT_PUBLIC_URL;
9
8
  const API_BASE = process.env.NEXT_PUBLIC_API || '/api';
10
9
 
@@ -18,7 +17,7 @@ function getMockApiUrl(pathname: string): string {
18
17
 
19
18
  export async function mockApiFetch<T = unknown>(pathname: string, options: ApiRequestOptions = {}): Promise<T> {
20
19
  const url = getMockApiUrl(pathname);
21
- const apiOptions = merge({ ...getDefaultApiRequestOptions() }, options);
20
+ const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);
22
21
  console.log('mockApiFetch', apiOptions.method, url);
23
22
  const apiResponse = await httpFetch(url, apiOptions);
24
23
  return apiResponse;
@@ -1,5 +1,5 @@
1
1
  import { httpFetch, isBrowser, merge } from '@websolutespa/bom-core';
2
- import { ApiRequestOptions, getDefaultApiRequestOptions } from '../api/api';
2
+ import { ApiRequestOptions, getRemoteApiRequestOptions } from '../api/api';
3
3
 
4
4
  /**
5
5
  * This methods handle api requests / responses to remote api (bowl or over)
@@ -18,7 +18,7 @@ export function getRemoteApiUrl(pathname: string): string {
18
18
 
19
19
  export async function remoteApiFetch<T = unknown>(pathname: string, options: ApiRequestOptions = {}): Promise<T> {
20
20
  const url = getRemoteApiUrl(pathname);
21
- const apiOptions = merge({ ...getDefaultApiRequestOptions() }, options);
21
+ const apiOptions = merge({ ...getRemoteApiRequestOptions() }, options);
22
22
  console.log('remoteApiFetch', apiOptions.method, url);
23
23
  const apiResponse = await httpFetch(url, apiOptions);
24
24
  return apiResponse;