@websolutespa/bom-core 3.0.4 → 3.0.5

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,11 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 3.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - added: IRoute isProtected
8
+
3
9
  ## 3.0.4
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -383,25 +383,19 @@ type IMarket = IEntity & {
383
383
  type IRoute = {
384
384
  category: IEquatable;
385
385
  id: string;
386
+ isDefault?: boolean;
387
+ isRoot?: boolean;
386
388
  locale: string;
387
389
  market: string;
390
+ media?: IMedia;
391
+ noindex?: boolean;
392
+ order?: number;
388
393
  page: IEquatable;
389
394
  resolvedCategory: IEquatable;
390
395
  schema: string;
391
- title: string;
392
- _status?: 'published' | 'draft';
393
- isDefault?: boolean;
394
- isRoot?: boolean;
395
- media?: {
396
- url: string;
397
- src?: string;
398
- type: string;
399
- updatedAt?: Date | string;
400
- };
401
- noindex?: boolean;
402
- order?: number;
403
396
  template?: string;
404
- updatedAt?: Date | string;
397
+ title: string;
398
+ updatedAt?: Date;
405
399
  useSplat?: boolean;
406
400
  };
407
401
  type IRouteCanonical = IRoute & {
@@ -490,9 +484,7 @@ type IPageUnresolvedRelation = {
490
484
 
491
485
  declare enum MenuCategoryStrategy {
492
486
  Default = "default",// show hidden categories recursively,
493
- ExcludeHidden = "exclude-hidden",
494
- ExcludeRoute = "exclude-route",
495
- ExcludeHiddenAndRoute = "exclude-hidden-and-route"
487
+ ExcludeHidden = "exclude-hidden"
496
488
  }
497
489
  type IMenuBase = {
498
490
  abstract?: ILocalizable;
package/dist/index.js CHANGED
@@ -417,8 +417,6 @@ function isMedia(item) {
417
417
  var MenuCategoryStrategy = /* @__PURE__ */ ((MenuCategoryStrategy2) => {
418
418
  MenuCategoryStrategy2["Default"] = "default";
419
419
  MenuCategoryStrategy2["ExcludeHidden"] = "exclude-hidden";
420
- MenuCategoryStrategy2["ExcludeRoute"] = "exclude-route";
421
- MenuCategoryStrategy2["ExcludeHiddenAndRoute"] = "exclude-hidden-and-route";
422
420
  return MenuCategoryStrategy2;
423
421
  })(MenuCategoryStrategy || {});
424
422
  function isMenuHref(item) {
@@ -1441,7 +1439,8 @@ function qsDeserializeKey(value) {
1441
1439
  return value;
1442
1440
  }
1443
1441
  function qsDeserializeKeys(key) {
1444
- return key.replace(/[\]]/g, "").split("[").map((value) => qsDeserializeKey(value)).filter((value) => value !== "");
1442
+ const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x));
1443
+ return keys;
1445
1444
  }
1446
1445
  function getNextKeyItem(key) {
1447
1446
  if (typeof key === "number") {
@@ -1539,37 +1538,8 @@ function collectRoutes(store, categories, markets, locales, medias) {
1539
1538
  const routes = [];
1540
1539
  if (locales.length > 0 && markets.length > 0) {
1541
1540
  const rootCategory = getRootCategory(categories);
1542
- const activeLocales = locales.filter((locale) => locale.isActive !== false);
1543
- const activeMarkets = markets.filter((market) => market.isActive !== false);
1544
- const categoryById = new Map(categories.filter((category) => typeof category.id === "string").map((category) => [category.id, category]));
1545
- const localeById = new Map(activeLocales.filter((locale) => typeof locale.id === "string").map((locale) => [locale.id, locale]));
1546
- const mediaById = new Map((medias || []).filter((media) => typeof media.id === "string").map((media) => [media.id, media]));
1547
- const marketLocales = activeMarkets.flatMap((market) => {
1548
- const localesForMarket = market.languages && market.languages.length > 0 ? market.languages.map((language) => localeById.get(String(asEntityId(language)))).filter((locale) => locale !== void 0) : activeLocales;
1549
- return localesForMarket.map((locale) => ({ market, locale }));
1550
- });
1551
- const getSegments = (item) => {
1552
- const routeCategories = [];
1553
- const segments = [];
1554
- let parentId = asCategoryId(item.category);
1555
- while (parentId != null) {
1556
- const parentCategory = categoryById.get(parentId);
1557
- if (parentCategory) {
1558
- segments.unshift({ ...parentCategory });
1559
- routeCategories.push(parentId);
1560
- parentId = asCategoryId(parentCategory.category);
1561
- if (parentId && routeCategories.includes(parentId)) {
1562
- console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
1563
- parentId = void 0;
1564
- }
1565
- } else {
1566
- parentId = void 0;
1567
- }
1568
- }
1569
- return segments;
1570
- };
1571
1541
  eachCategorized(store, (item, key) => {
1572
- const segments = getSegments(item);
1542
+ const segments = getCategorySegments(categories, item);
1573
1543
  const visibleSegments = segments.filter((x) => x.id !== rootCategory?.id && Boolean(x.isHidden) === false);
1574
1544
  const visibleCategory = visibleSegments.length > 0 ? visibleSegments[visibleSegments.length - 1] : rootCategory;
1575
1545
  if (visibleCategory) {
@@ -1578,10 +1548,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
1578
1548
  slugs.push({ slug: item.slug });
1579
1549
  }
1580
1550
  const isRootCategory = rootCategory && item.category === rootCategory.id && item.isDefault;
1581
- marketLocales.forEach(({ market, locale }) => {
1551
+ eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
1582
1552
  if (hasMarket(item, market)) {
1583
1553
  const title = localize(item.title, locale.id);
1584
- const id = getRouteHref(slugs, market, locale, activeMarkets, activeLocales);
1554
+ const id = getRouteHref(slugs, market, locale, markets2, locales2);
1585
1555
  const {
1586
1556
  _status,
1587
1557
  category,
@@ -1595,10 +1565,11 @@ function collectRoutes(store, categories, markets, locales, medias) {
1595
1565
  const route = {
1596
1566
  _status,
1597
1567
  category,
1568
+ // id: isDefaultRootCategory ? '/' : id,
1598
1569
  id,
1599
1570
  locale: locale.id,
1600
1571
  market: market.id,
1601
- media: routeMedia(media),
1572
+ media,
1602
1573
  page: item.id,
1603
1574
  resolvedCategory: visibleCategory.id,
1604
1575
  schema: key,
@@ -1623,10 +1594,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
1623
1594
  route.useSplat = true;
1624
1595
  }
1625
1596
  const mediaId = typeof item.media === "string" ? item.media : void 0;
1626
- if (mediaId) {
1627
- const media2 = mediaById.get(mediaId);
1597
+ if (Array.isArray(medias) && mediaId) {
1598
+ const media2 = item.media && medias.find((x) => x.id === mediaId);
1628
1599
  if (media2) {
1629
- route.media = routeMedia(media2);
1600
+ route.media = media2;
1630
1601
  }
1631
1602
  }
1632
1603
  routes.push(route);
@@ -1637,18 +1608,6 @@ function collectRoutes(store, categories, markets, locales, medias) {
1637
1608
  }
1638
1609
  return routes;
1639
1610
  }
1640
- function routeMedia(media) {
1641
- const url = media?.url || media?.src;
1642
- return media && url ? {
1643
- // createdAt: media.createdAt,
1644
- updatedAt: media.updatedAt,
1645
- // filename: media.filename,
1646
- // mimeType: media.mimeType,
1647
- // id: media.id,
1648
- url,
1649
- type: media.type
1650
- } : void 0;
1651
- }
1652
1611
  function eachMarketLocale(markets, locales, callback) {
1653
1612
  locales = locales.filter((x) => x.isActive !== false);
1654
1613
  markets = markets.filter((x) => x.isActive !== false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",