@websolutespa/bom-core 1.10.0-next.1 → 2.0.0

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.
@@ -1,172 +1,3 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- ImageStrategy: () => ImageStrategy,
34
- JsonService: () => JsonService,
35
- Logger: () => Logger,
36
- LoggerLevel: () => LoggerLevel,
37
- MenuCategoryStrategy: () => MenuCategoryStrategy,
38
- RedirectReason: () => RedirectReason,
39
- RouteStrategy: () => RouteStrategy,
40
- arrayShuffle: () => arrayShuffle,
41
- asCategoryId: () => asCategoryId,
42
- asEntityId: () => asEntityId,
43
- asEquatable: () => asEquatable,
44
- asEquatableNumber: () => asEquatableNumber,
45
- asEquatableString: () => asEquatableString,
46
- asServerProps: () => asServerProps,
47
- asSortedOptions: () => asSortedOptions,
48
- awaitAll: () => awaitAll,
49
- base64ToString: () => base64ToString,
50
- camelToSnakeCase: () => camelToSnakeCase,
51
- cloneItem: () => cloneItem,
52
- collectFeatureTypes: () => collectFeatureTypes,
53
- collectFeatureTypes__: () => collectFeatureTypes__,
54
- collectOptions: () => collectOptions,
55
- collectRoutes: () => collectRoutes,
56
- consoleWarn: () => consoleWarn,
57
- decryptImageResize: () => decryptImageResize,
58
- deepMerge: () => deepMerge,
59
- defaultLocale: () => defaultLocale,
60
- defaultMarket: () => defaultMarket,
61
- eachCategorized: () => eachCategorized,
62
- eachMarketLocale: () => eachMarketLocale,
63
- eachMedia: () => eachMedia,
64
- eachValue: () => eachValue,
65
- encryptImageToken: () => encryptImageToken,
66
- enumToList: () => enumToList,
67
- excludeComponent: () => excludeComponent,
68
- findCategoryInCategories: () => findCategoryInCategories,
69
- findChildCategories: () => findChildCategories,
70
- findRouteOfCategory: () => findRouteOfCategory,
71
- findRoutesOfCategory: () => findRoutesOfCategory,
72
- getCategorySegments: () => getCategorySegments,
73
- getCategorySegmentsByCategory: () => getCategorySegmentsByCategory,
74
- getClassNames: () => getClassNames,
75
- getCollectionDescription: () => getCollectionDescription,
76
- getEnv: () => getEnv,
77
- getHost: () => getHost,
78
- getIsDevelopment: () => getIsDevelopment,
79
- getIsProduction: () => getIsProduction,
80
- getOrigin: () => getOrigin,
81
- getParentCategoriesById: () => getParentCategoriesById,
82
- getParentCategory: () => getParentCategory,
83
- getProto: () => getProto,
84
- getRootCategory: () => getRootCategory,
85
- getRouteHref: () => getRouteHref,
86
- groupComponents: () => groupComponents,
87
- hasComponents: () => hasComponents,
88
- hasMarket: () => hasMarket,
89
- httpDelete: () => httpDelete,
90
- httpFetch: () => httpFetch,
91
- httpGet: () => httpGet,
92
- httpPatch: () => httpPatch,
93
- httpPost: () => httpPost,
94
- httpPut: () => httpPut,
95
- isArray: () => isArray,
96
- isBrowser: () => isBrowser,
97
- isComponent: () => isComponent,
98
- isComponentOfType: () => isComponentOfType,
99
- isDevelopment: () => isDevelopment,
100
- isEntity: () => isEntity,
101
- isEquatable: () => isEquatable,
102
- isHeaders: () => isHeaders,
103
- isIncomingHttpHeaders: () => isIncomingHttpHeaders,
104
- isLocalizedString: () => isLocalizedString,
105
- isMedia: () => isMedia,
106
- isMediaImage: () => isMediaImage,
107
- isMediaJson: () => isMediaJson,
108
- isMediaPdf: () => isMediaPdf,
109
- isMediaVideo: () => isMediaVideo,
110
- isMenuCategory: () => isMenuCategory,
111
- isMenuGroup: () => isMenuGroup,
112
- isMenuHref: () => isMenuHref,
113
- isMenuLink: () => isMenuLink,
114
- isMenuPage: () => isMenuPage,
115
- isMenuRoute: () => isMenuRoute,
116
- isNonEmptyArray: () => isNonEmptyArray,
117
- isNotNullString: () => isNotNullString,
118
- isNumber: () => isNumber,
119
- isObject: () => isObject,
120
- isProduction: () => isProduction,
121
- isPromise: () => isPromise,
122
- isRelation: () => isRelation,
123
- isReservedCollectionDescription: () => isReservedCollectionDescription,
124
- isStage: () => isStage,
125
- isString: () => isString,
126
- isUndecoratedCategory: () => isUndecoratedCategory,
127
- isUndecoratedMenuCategory: () => isUndecoratedMenuCategory,
128
- isUndecoratedMenuItem: () => isUndecoratedMenuItem,
129
- isUndecoratedMenuPage: () => isUndecoratedMenuPage,
130
- isUndecoratedNav: () => isUndecoratedNav,
131
- isUnresolvedCategory: () => isUnresolvedCategory,
132
- isUnresolvedRelation: () => isUnresolvedRelation,
133
- isValidCollectionDescription: () => isValidCollectionDescription,
134
- isValidString: () => isValidString,
135
- localize: () => localize,
136
- localizeItem: () => localizeItem,
137
- localizeValue: () => localizeValue,
138
- localizedToString: () => localizedToString,
139
- merge: () => merge,
140
- pascalCaseToCamelCase: () => pascalCaseToCamelCase,
141
- pascalCaseToCharCase: () => pascalCaseToCharCase,
142
- pascalCaseToKebabCase: () => pascalCaseToKebabCase,
143
- pascalCaseToSnakeCase: () => pascalCaseToSnakeCase,
144
- passwordStrategy: () => passwordStrategy,
145
- pickComponent: () => pickComponent,
146
- pickHero: () => pickHero,
147
- prependHero: () => prependHero,
148
- qsDeserialize: () => qsDeserialize,
149
- qsDeserializeRaw: () => qsDeserializeRaw,
150
- qsSerialize: () => qsSerialize,
151
- qsSerializeRaw: () => qsSerializeRaw,
152
- resolveMediaType: () => resolveMediaType,
153
- stringToBase64: () => stringToBase64,
154
- toCamelCase: () => toCamelCase,
155
- toCharCase: () => toCharCase,
156
- toDisplayName: () => toDisplayName,
157
- toFindParams: () => toFindParams,
158
- toKebabCase: () => toKebabCase,
159
- toPascalCase: () => toPascalCase,
160
- toPluralName: () => toPluralName,
161
- toSnakeCase: () => toSnakeCase,
162
- toTitleCase: () => toTitleCase,
163
- toValidCollectionName: () => toValidCollectionName,
164
- unknownCaseToPascalCase: () => unknownCaseToPascalCase,
165
- uuidv4: () => uuidv4,
166
- withSchema: () => withSchema
167
- });
168
- module.exports = __toCommonJS(index_exports);
169
-
170
1
  // src/utils/arrayShuffle.ts
171
2
  function arrayShuffle(items) {
172
3
  return items.map((item) => ({ item, order: Math.random() })).sort((a, b) => a.order - b.order).map(({ item }) => item);
@@ -793,7 +624,7 @@ function classNameCollectionToString(className) {
793
624
  let classNames = "";
794
625
  for (let i = 0; i < total; i++) {
795
626
  const key = keys[i];
796
- const value = className[key];
627
+ const value = className[keys[i]];
797
628
  if (!value) {
798
629
  continue;
799
630
  }
@@ -822,7 +653,7 @@ function getClassNames(...props) {
822
653
  }
823
654
 
824
655
  // src/collection/collection.ts
825
- var import_pluralize = __toESM(require("pluralize"), 1);
656
+ import pluralize from "pluralize";
826
657
  function getCollectionDescription(text) {
827
658
  text = toValidCollectionName(text);
828
659
  const displayName = toDisplayName(text);
@@ -862,7 +693,7 @@ function toDisplayName(text) {
862
693
  return toTitleCase(text).replace(/\s/g, "");
863
694
  }
864
695
  function toPluralName(text) {
865
- const plural = import_pluralize.default.plural(text);
696
+ const plural = pluralize.plural(text);
866
697
  return plural === text ? `${plural}es` : plural;
867
698
  }
868
699
  function toTitleCase(text) {
@@ -992,13 +823,21 @@ function decryptImageResize(token) {
992
823
 
993
824
  // src/json/json.service.ts
994
825
  var JsonService = class {
995
- items;
996
826
  constructor(items) {
997
827
  this.items = items;
998
828
  }
999
829
  async getItems() {
1000
830
  return this.items;
1001
831
  }
832
+ async findGlobal(params = {}) {
833
+ const items = await this.getItems();
834
+ if (items.length > 0) {
835
+ return await this.decorateOne_(items[0], params);
836
+ } else {
837
+ console.log("JsonService.findGlobal.notfound", params);
838
+ return void 0;
839
+ }
840
+ }
1002
841
  async findOne(id, params = {}) {
1003
842
  let items = await this.getItems();
1004
843
  params.where = params.where || {};
@@ -1249,7 +1088,7 @@ var JsonService = class {
1249
1088
  return false;
1250
1089
  }
1251
1090
  const [longitude, latitude, maxDistance, minDistance] = near;
1252
- const distance = longitude && latitude ? calculateDistanceInMeters_(itemLongitude, itemLatitude, longitude, latitude) : 0;
1091
+ const distance = calculateDistanceInMeters_(itemLongitude, itemLatitude, longitude, latitude);
1253
1092
  if (typeof maxDistance === "number" && typeof minDistance === "number") {
1254
1093
  return distance <= maxDistance && distance >= minDistance;
1255
1094
  } else if (typeof maxDistance === "number") {
@@ -1393,7 +1232,11 @@ function getValue(item, key) {
1393
1232
  const keys = key.split(".");
1394
1233
  const value = keys.reduce((p, c) => {
1395
1234
  if (isObject(p)) {
1396
- return p[c];
1235
+ const v = p[c];
1236
+ if (isUnresolvedRelation(v)) {
1237
+ return v.value;
1238
+ }
1239
+ return v;
1397
1240
  } else {
1398
1241
  return void 0;
1399
1242
  }
@@ -1435,7 +1278,7 @@ function isLocalizedString(value) {
1435
1278
  return isLocalizedString2;
1436
1279
  }
1437
1280
  function localizedToString(json, locale, defaultLocale2 = DEFAULT_LOCALE) {
1438
- const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0] || "";
1281
+ const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
1439
1282
  return localizedString;
1440
1283
  }
1441
1284
  function localize(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
@@ -1474,7 +1317,6 @@ var LoggerLevel = /* @__PURE__ */ ((LoggerLevel2) => {
1474
1317
  return LoggerLevel2;
1475
1318
  })(LoggerLevel || {});
1476
1319
  var Logger = class {
1477
- static level_ = 5 /* ALL */;
1478
1320
  static setLevel(level) {
1479
1321
  this.level_ = level;
1480
1322
  }
@@ -1506,6 +1348,7 @@ var Logger = class {
1506
1348
  }
1507
1349
  }
1508
1350
  };
1351
+ Logger.level_ = 5 /* ALL */;
1509
1352
 
1510
1353
  // src/market/market.ts
1511
1354
  function getDefaultMarket() {
@@ -1678,22 +1521,7 @@ var RouteStrategy = /* @__PURE__ */ ((RouteStrategy2) => {
1678
1521
  RouteStrategy2["Manual"] = "manual";
1679
1522
  return RouteStrategy2;
1680
1523
  })(RouteStrategy || {});
1681
- var ROUTE_STRATEGY = process.env.ROUTE_STRATEGY || "auto" /* Auto */;
1682
- function getPickedProps(item) {
1683
- const pickedProps = Object.fromEntries(Object.entries(item).filter(([k, v]) => [
1684
- "category",
1685
- "isDefault",
1686
- "media",
1687
- "order",
1688
- "template",
1689
- "updatedAt",
1690
- "useSplat",
1691
- // 'createdAt',
1692
- "updatedAt",
1693
- "_status"
1694
- ].includes(k)));
1695
- return pickedProps;
1696
- }
1524
+ var ROUTE_STRATEGY = process.env.ROUTE_STRATEGY || "manual" /* Manual */;
1697
1525
  function collectRoutes(store, categories, markets, locales, medias) {
1698
1526
  const routes = [];
1699
1527
  if (locales.length > 0 && markets.length > 0) {
@@ -1707,31 +1535,57 @@ function collectRoutes(store, categories, markets, locales, medias) {
1707
1535
  if (Boolean(item.isDefault) === false) {
1708
1536
  slugs.push({ slug: item.slug });
1709
1537
  }
1710
- const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
1711
- const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
1712
- const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? asEntityId(defaultMarket2.defaultLanguage) : defaultLocale2.id;
1713
1538
  const isRootCategory = rootCategory && item.category === rootCategory.id && item.isDefault;
1714
1539
  eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
1715
1540
  if (hasMarket(item, market)) {
1716
1541
  const title = localize(item.title, locale.id);
1717
1542
  const id = getRouteHref(slugs, market, locale, markets2, locales2);
1718
- const isDefaultRootCategory = isRootCategory && market.id === defaultMarket2.id && locale.id === defaultMarketLocale;
1719
- const pickedProps = getPickedProps(item);
1543
+ const {
1544
+ _status,
1545
+ category,
1546
+ isDefault,
1547
+ media,
1548
+ order,
1549
+ template,
1550
+ updatedAt,
1551
+ useSplat
1552
+ } = item;
1720
1553
  const route = {
1721
- ...pickedProps,
1722
- resolvedCategory: visibleCategory.id,
1723
- id: isDefaultRootCategory ? "/" : id,
1554
+ _status,
1555
+ category,
1556
+ // id: isDefaultRootCategory ? '/' : id,
1557
+ id,
1724
1558
  locale: locale.id,
1725
1559
  market: market.id,
1560
+ media,
1726
1561
  page: item.id,
1562
+ resolvedCategory: visibleCategory.id,
1727
1563
  schema: key,
1728
- title
1564
+ template,
1565
+ title,
1566
+ updatedAt
1729
1567
  };
1568
+ if (isDefault) {
1569
+ route.isDefault = true;
1570
+ }
1571
+ if (isRootCategory) {
1572
+ route.isRoot = true;
1573
+ }
1574
+ const noindex = (item.meta?.robots || "").includes("noindex");
1575
+ if (noindex) {
1576
+ route.noindex = true;
1577
+ }
1578
+ if (order != null) {
1579
+ route.order = order;
1580
+ }
1581
+ if (useSplat) {
1582
+ route.useSplat = true;
1583
+ }
1730
1584
  const mediaId = typeof item.media === "string" ? item.media : void 0;
1731
1585
  if (Array.isArray(medias) && mediaId) {
1732
- const media = item.media && medias.find((x) => x.id === mediaId);
1733
- if (media) {
1734
- route.media = media;
1586
+ const media2 = item.media && medias.find((x) => x.id === mediaId);
1587
+ if (media2) {
1588
+ route.media = media2;
1735
1589
  }
1736
1590
  }
1737
1591
  routes.push(route);
@@ -1811,8 +1665,7 @@ function getRouteHref(segments, market, locale, markets, locales) {
1811
1665
  function hasMarket(item, market) {
1812
1666
  return !item.markets || item.markets.length === 0 || item.markets.includes(market.id);
1813
1667
  }
1814
- // Annotate the CommonJS export names for ESM import in node:
1815
- 0 && (module.exports = {
1668
+ export {
1816
1669
  ImageStrategy,
1817
1670
  JsonService,
1818
1671
  Logger,
@@ -1947,4 +1800,4 @@ function hasMarket(item, market) {
1947
1800
  unknownCaseToPascalCase,
1948
1801
  uuidv4,
1949
1802
  withSchema
1950
- });
1803
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "1.10.0-next.1",
3
+ "version": "2.0.0",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -26,21 +26,20 @@
26
26
  "pluralize": "latest"
27
27
  },
28
28
  "peerDependencies": {
29
- "next": ">= 15.3.0"
29
+ "next": ">= 14.1.4"
30
30
  },
31
31
  "devDependencies": {
32
- "@websolutespa/bom-cli": "1.10.0-next.1",
33
- "@websolutespa/eslint-config": "1.10.0-next.1",
34
- "@websolutespa/test": "1.10.0-next.1",
35
- "@websolutespa/tsconfig": "1.10.0-next.1",
36
- "eslint": "^9.28.0",
32
+ "@websolutespa/bom-cli": "^2.0.0",
33
+ "@websolutespa/test": "^2.0.0",
34
+ "@websolutespa/tsconfig": "^2.0.0",
35
+ "eslint": "^8.56.0",
36
+ "eslint-config-websolute": "^2.0.0",
37
37
  "npm-run-all": "^4.1.5",
38
38
  "raw-loader": "^4.0.2",
39
39
  "ts-node": "^10.9.2",
40
- "tsup": "^8.5.0",
41
- "typescript": "5.8.2"
40
+ "tsup": "^6.7.0",
41
+ "typescript": "^5.4.5"
42
42
  },
43
- "type": "module",
44
43
  "publishConfig": {
45
44
  "access": "public"
46
45
  },