@websolutespa/bom-core 2.0.1-next.2 → 2.0.1

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/dist/index.js CHANGED
@@ -1,3 +1,172 @@
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 src_exports = {};
32
+ __export(src_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(src_exports);
169
+
1
170
  // src/utils/arrayShuffle.ts
2
171
  function arrayShuffle(items) {
3
172
  return items.map((item) => ({ item, order: Math.random() })).sort((a, b) => a.order - b.order).map(({ item }) => item);
@@ -624,7 +793,7 @@ function classNameCollectionToString(className) {
624
793
  let classNames = "";
625
794
  for (let i = 0; i < total; i++) {
626
795
  const key = keys[i];
627
- const value = className[key];
796
+ const value = className[keys[i]];
628
797
  if (!value) {
629
798
  continue;
630
799
  }
@@ -653,7 +822,7 @@ function getClassNames(...props) {
653
822
  }
654
823
 
655
824
  // src/collection/collection.ts
656
- import pluralize from "pluralize";
825
+ var import_pluralize = __toESM(require("pluralize"));
657
826
  function getCollectionDescription(text) {
658
827
  text = toValidCollectionName(text);
659
828
  const displayName = toDisplayName(text);
@@ -693,7 +862,7 @@ function toDisplayName(text) {
693
862
  return toTitleCase(text).replace(/\s/g, "");
694
863
  }
695
864
  function toPluralName(text) {
696
- const plural = pluralize.plural(text);
865
+ const plural = import_pluralize.default.plural(text);
697
866
  return plural === text ? `${plural}es` : plural;
698
867
  }
699
868
  function toTitleCase(text) {
@@ -823,24 +992,25 @@ function decryptImageResize(token) {
823
992
 
824
993
  // src/json/json.service.ts
825
994
  var JsonService = class {
826
- items;
827
995
  constructor(items) {
828
996
  this.items = items;
829
997
  }
830
998
  async getItems() {
831
999
  return this.items;
832
1000
  }
833
- whereId_(id) {
834
- return typeof id === "string" && /^[0-9]+$/.test(id) ? {
835
- in: [id, parseInt(id)]
836
- } : {
837
- equals: id
838
- };
1001
+ async findGlobal(params = {}) {
1002
+ const items = await this.getItems();
1003
+ if (items.length > 0) {
1004
+ return await this.decorateOne_(items[0], params);
1005
+ } else {
1006
+ console.log("JsonService.findGlobal.notfound", params);
1007
+ return void 0;
1008
+ }
839
1009
  }
840
1010
  async findOne(id, params = {}) {
841
1011
  let items = await this.getItems();
842
1012
  params.where = params.where || {};
843
- params.where.id = params.where.id || this.whereId_(id);
1013
+ params.where.id = params.where.id || { equals: id };
844
1014
  items = this.whereItems_(items, params.where);
845
1015
  if (items.length > 0) {
846
1016
  return await this.decorateOne_(items[0], params);
@@ -885,7 +1055,7 @@ var JsonService = class {
885
1055
  async updateOne(id, payload, params = {}) {
886
1056
  let items = await this.getItems();
887
1057
  params.where = params.where || {};
888
- params.where.id = params.where.id || this.whereId_(id);
1058
+ params.where.id = params.where.id || { equals: id };
889
1059
  const whereItems = this.whereItems_(items, params.where);
890
1060
  if (whereItems.length > 0) {
891
1061
  const index = items.indexOf(whereItems[0]);
@@ -923,7 +1093,7 @@ var JsonService = class {
923
1093
  async deleteOne(id, params = {}) {
924
1094
  let items = await this.getItems();
925
1095
  params.where = params.where || {};
926
- params.where.id = params.where.id || this.whereId_(id);
1096
+ params.where.id = params.where.id || { equals: id };
927
1097
  const whereItems = this.whereItems_(items, params.where);
928
1098
  if (whereItems.length > 0) {
929
1099
  const index = items.indexOf(whereItems[0]);
@@ -1087,7 +1257,7 @@ var JsonService = class {
1087
1257
  return false;
1088
1258
  }
1089
1259
  const [longitude, latitude, maxDistance, minDistance] = near;
1090
- const distance = longitude && latitude ? calculateDistanceInMeters_(itemLongitude, itemLatitude, longitude, latitude) : 0;
1260
+ const distance = calculateDistanceInMeters_(itemLongitude, itemLatitude, longitude, latitude);
1091
1261
  if (typeof maxDistance === "number" && typeof minDistance === "number") {
1092
1262
  return distance <= maxDistance && distance >= minDistance;
1093
1263
  } else if (typeof maxDistance === "number") {
@@ -1277,7 +1447,7 @@ function isLocalizedString(value) {
1277
1447
  return isLocalizedString2;
1278
1448
  }
1279
1449
  function localizedToString(json, locale, defaultLocale2 = DEFAULT_LOCALE) {
1280
- const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0] || "";
1450
+ const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
1281
1451
  return localizedString;
1282
1452
  }
1283
1453
  function localize(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
@@ -1316,7 +1486,6 @@ var LoggerLevel = /* @__PURE__ */ ((LoggerLevel2) => {
1316
1486
  return LoggerLevel2;
1317
1487
  })(LoggerLevel || {});
1318
1488
  var Logger = class {
1319
- static level_ = 5 /* ALL */;
1320
1489
  static setLevel(level) {
1321
1490
  this.level_ = level;
1322
1491
  }
@@ -1348,6 +1517,7 @@ var Logger = class {
1348
1517
  }
1349
1518
  }
1350
1519
  };
1520
+ Logger.level_ = 5 /* ALL */;
1351
1521
 
1352
1522
  // src/market/market.ts
1353
1523
  function getDefaultMarket() {
@@ -1505,11 +1675,15 @@ function getProto(headers) {
1505
1675
  }
1506
1676
  }
1507
1677
  function getOrigin(headers) {
1508
- const host = getHost(headers);
1509
- if (host) {
1510
- return host.indexOf("localhost") !== -1 ? "http://" + host : getProto(headers) + "://" + host;
1678
+ if (process.env.NEXT_PUBLIC_URL) {
1679
+ return process.env.NEXT_PUBLIC_URL;
1511
1680
  } else {
1512
- return process.env.NEXT_PUBLIC_URL || "";
1681
+ const host = getHost(headers);
1682
+ if (host) {
1683
+ return host.indexOf("localhost") !== -1 ? "http://" + host : getProto(headers) + "://" + host;
1684
+ } else {
1685
+ return "";
1686
+ }
1513
1687
  }
1514
1688
  }
1515
1689
 
@@ -1520,22 +1694,7 @@ var RouteStrategy = /* @__PURE__ */ ((RouteStrategy2) => {
1520
1694
  RouteStrategy2["Manual"] = "manual";
1521
1695
  return RouteStrategy2;
1522
1696
  })(RouteStrategy || {});
1523
- var ROUTE_STRATEGY = process.env.ROUTE_STRATEGY || "auto" /* Auto */;
1524
- function getPickedProps(item) {
1525
- const pickedProps = Object.fromEntries(Object.entries(item).filter(([k, v]) => [
1526
- "category",
1527
- "isDefault",
1528
- "media",
1529
- "order",
1530
- "template",
1531
- "updatedAt",
1532
- "useSplat",
1533
- // 'createdAt',
1534
- "updatedAt",
1535
- "_status"
1536
- ].includes(k)));
1537
- return pickedProps;
1538
- }
1697
+ var ROUTE_STRATEGY = process.env.ROUTE_STRATEGY || "manual" /* Manual */;
1539
1698
  function collectRoutes(store, categories, markets, locales, medias) {
1540
1699
  const routes = [];
1541
1700
  if (locales.length > 0 && markets.length > 0) {
@@ -1549,31 +1708,57 @@ function collectRoutes(store, categories, markets, locales, medias) {
1549
1708
  if (Boolean(item.isDefault) === false) {
1550
1709
  slugs.push({ slug: item.slug });
1551
1710
  }
1552
- const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
1553
- const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
1554
- const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? asEntityId(defaultMarket2.defaultLanguage) : defaultLocale2.id;
1555
1711
  const isRootCategory = rootCategory && item.category === rootCategory.id && item.isDefault;
1556
1712
  eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
1557
1713
  if (hasMarket(item, market)) {
1558
1714
  const title = localize(item.title, locale.id);
1559
1715
  const id = getRouteHref(slugs, market, locale, markets2, locales2);
1560
- const isDefaultRootCategory = isRootCategory && market.id === defaultMarket2.id && locale.id === defaultMarketLocale;
1561
- const pickedProps = getPickedProps(item);
1716
+ const {
1717
+ _status,
1718
+ category,
1719
+ isDefault,
1720
+ media,
1721
+ order,
1722
+ template,
1723
+ updatedAt,
1724
+ useSplat
1725
+ } = item;
1562
1726
  const route = {
1563
- ...pickedProps,
1564
- resolvedCategory: visibleCategory.id,
1565
- id: isDefaultRootCategory ? "/" : id,
1727
+ _status,
1728
+ category,
1729
+ // id: isDefaultRootCategory ? '/' : id,
1730
+ id,
1566
1731
  locale: locale.id,
1567
1732
  market: market.id,
1733
+ media,
1568
1734
  page: item.id,
1735
+ resolvedCategory: visibleCategory.id,
1569
1736
  schema: key,
1570
- title
1737
+ template,
1738
+ title,
1739
+ updatedAt
1571
1740
  };
1741
+ if (isDefault) {
1742
+ route.isDefault = true;
1743
+ }
1744
+ if (isRootCategory) {
1745
+ route.isRoot = true;
1746
+ }
1747
+ const noindex = (item.meta?.robots || "").includes("noindex");
1748
+ if (noindex) {
1749
+ route.noindex = true;
1750
+ }
1751
+ if (order != null) {
1752
+ route.order = order;
1753
+ }
1754
+ if (useSplat) {
1755
+ route.useSplat = true;
1756
+ }
1572
1757
  const mediaId = typeof item.media === "string" ? item.media : void 0;
1573
1758
  if (Array.isArray(medias) && mediaId) {
1574
- const media = item.media && medias.find((x) => x.id === mediaId);
1575
- if (media) {
1576
- route.media = media;
1759
+ const media2 = item.media && medias.find((x) => x.id === mediaId);
1760
+ if (media2) {
1761
+ route.media = media2;
1577
1762
  }
1578
1763
  }
1579
1764
  routes.push(route);
@@ -1653,7 +1838,8 @@ function getRouteHref(segments, market, locale, markets, locales) {
1653
1838
  function hasMarket(item, market) {
1654
1839
  return !item.markets || item.markets.length === 0 || item.markets.includes(market.id);
1655
1840
  }
1656
- export {
1841
+ // Annotate the CommonJS export names for ESM import in node:
1842
+ 0 && (module.exports = {
1657
1843
  ImageStrategy,
1658
1844
  JsonService,
1659
1845
  Logger,
@@ -1788,4 +1974,4 @@ export {
1788
1974
  unknownCaseToPascalCase,
1789
1975
  uuidv4,
1790
1976
  withSchema
1791
- };
1977
+ });