@websolutespa/bom-core 1.7.2 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 1.7.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Added: getOrigin, getHost
8
+
9
+ ## 1.7.3
10
+
11
+ ### Patch Changes
12
+
13
+ - Updating: dependencies
14
+
3
15
  ## 1.7.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IncomingMessage, ServerResponse } from 'http';
1
+ import { IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http';
2
2
  import { ParsedUrlQuery } from 'querystring';
3
3
  import React from 'react';
4
4
 
@@ -149,7 +149,6 @@ type IMediaType = 'image' | 'video' | string;
149
149
  type IMedia = {
150
150
  abstract?: string;
151
151
  alt?: string;
152
- height?: number;
153
152
  media?: IMedia;
154
153
  mimeType?: string;
155
154
  src: string;
@@ -157,6 +156,7 @@ type IMedia = {
157
156
  type: IMediaType;
158
157
  url?: string;
159
158
  width?: number;
159
+ height?: number;
160
160
  };
161
161
  declare function resolveMediaType(media: IMedia): IMediaType;
162
162
 
@@ -632,6 +632,11 @@ declare function qsSerializeRaw(queryParams?: {}): string;
632
632
  declare function qsDeserialize(query?: string, deserializedParams?: {}): QueryParams;
633
633
  declare function qsDeserializeRaw(query?: string, deserializedParams?: {}): {};
634
634
 
635
+ declare function isHeaders(headers?: IncomingHttpHeaders | Headers): headers is Headers;
636
+ declare function isIncomingHttpHeaders(headers?: IncomingHttpHeaders | Headers): headers is IncomingHttpHeaders;
637
+ declare function getHost(headers?: IncomingHttpHeaders | Headers): string | null;
638
+ declare function getOrigin(headers?: IncomingHttpHeaders): string;
639
+
635
640
  declare function collectRoutes(store: IMemoryStore<ICategorized>, categories: ICategory[], markets: IMarket[], locales: ILocale[]): IRoute[];
636
641
  declare function eachMarketLocale(markets: IMarket[], locales: ILocale[], callback: (market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]) => void): void;
637
642
  declare function eachCategorized(store: IMemoryStore<ICategorized>, callback: (item: ICategorized, key: string) => void): void;
@@ -672,6 +677,25 @@ declare function collectFeatureTypes<T extends IEntity = IEntity>(items: T[], ..
672
677
 
673
678
  declare function collectOptions<T extends IEntity = IEntity>(items: T[], ...keys: string[]): Promise<Partial<Record<keyof T, IOption[]>>>;
674
679
 
680
+ /**
681
+ * Represents a primitive value that can be used in the deep merge operation.
682
+ */
683
+ type Primitive = ((...args: any[]) => any) | string | number | boolean | null;
684
+ /**
685
+ * Represents a dynamic value that can be used in the deep merge operation.
686
+ */
687
+ type Dynamic = {
688
+ [key: string]: Dynamic;
689
+ } | Dynamic[] | Primitive;
690
+ /**
691
+ * Deeply merges two objects or arrays.
692
+ *
693
+ * @param target - The target object or array to merge into.
694
+ * @param source - The source object or array to merge from.
695
+ * @returns The merged object or array.
696
+ */
697
+ declare function deepMerge<T extends Dynamic, R extends Dynamic = T>(target?: Partial<T>, source?: Partial<R>): T & R;
698
+
675
699
  type ListItem<T> = {
676
700
  [K in keyof T]: {
677
701
  readonly key: string;
@@ -709,4 +733,4 @@ declare function asServerProps(props: any): any;
709
733
  declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
710
734
  declare function merge(target: any, source: any): any;
711
735
 
712
- export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAction, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IComponent, IConfig, IConsentPreference, IContextBaseParams, IContextParams, IDecoratedNav, IEndUser, IEntity, IEquatable, IFeature, IFeatureType, ILabel, ILayout, ILegalNotice, ILetter, ILocale, ILocaleId, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuHref, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IOverrideReturnValue, IOverrideValue, IPackages, IPage, IPageRelation, IPageRelationResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPreference, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, IUndecoratedNav, Json, JsonService, LiteralUnion, Logger, LoggerLevel, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, User, UserRole, UserWithRoles, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, collectFeatureTypes, collectOptions, collectRoutes, consoleWarn, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getIsDevelopment, getIsProduction, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isCategory, isDevelopment, isEntity, isEquatable, isLocalizedString, isMenuHref, isNotNullString, isObject, isProduction, isRelation, isReservedCollectionDescription, isStage, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
736
+ export { Dynamic, FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAction, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IComponent, IConfig, IConsentPreference, IContextBaseParams, IContextParams, IDecoratedNav, IEndUser, IEntity, IEquatable, IFeature, IFeatureType, ILabel, ILayout, ILegalNotice, ILetter, ILocale, ILocaleId, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuHref, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IOverrideReturnValue, IOverrideValue, IPackages, IPage, IPageRelation, IPageRelationResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPreference, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, IUndecoratedNav, Json, JsonService, LiteralUnion, Logger, LoggerLevel, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, Primitive, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, User, UserRole, UserWithRoles, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, collectFeatureTypes, collectOptions, collectRoutes, consoleWarn, deepMerge, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getHost, getIsDevelopment, getIsProduction, getOrigin, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isCategory, isDevelopment, isEntity, isEquatable, isHeaders, isIncomingHttpHeaders, isLocalizedString, isMenuHref, isNotNullString, isObject, isProduction, isRelation, isReservedCollectionDescription, isStage, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ __export(src_exports, {
45
45
  collectOptions: () => collectOptions,
46
46
  collectRoutes: () => collectRoutes,
47
47
  consoleWarn: () => consoleWarn,
48
+ deepMerge: () => deepMerge,
48
49
  defaultLocale: () => defaultLocale,
49
50
  defaultMarket: () => defaultMarket,
50
51
  eachCategorized: () => eachCategorized,
@@ -55,8 +56,10 @@ __export(src_exports, {
55
56
  getClassNames: () => getClassNames,
56
57
  getCollectionDescription: () => getCollectionDescription,
57
58
  getEnv: () => getEnv,
59
+ getHost: () => getHost,
58
60
  getIsDevelopment: () => getIsDevelopment,
59
61
  getIsProduction: () => getIsProduction,
62
+ getOrigin: () => getOrigin,
60
63
  getParentCategoriesById: () => getParentCategoriesById,
61
64
  getRootCategory: () => getRootCategory,
62
65
  getRouteHref: () => getRouteHref,
@@ -72,6 +75,8 @@ __export(src_exports, {
72
75
  isDevelopment: () => isDevelopment,
73
76
  isEntity: () => isEntity,
74
77
  isEquatable: () => isEquatable,
78
+ isHeaders: () => isHeaders,
79
+ isIncomingHttpHeaders: () => isIncomingHttpHeaders,
75
80
  isLocalizedString: () => isLocalizedString,
76
81
  isMenuHref: () => isMenuHref,
77
82
  isNotNullString: () => isNotNullString,
@@ -447,6 +452,24 @@ async function collectOptions(items, ...keys) {
447
452
  return optionsGroup;
448
453
  }
449
454
 
455
+ // src/utils/deepMerge.ts
456
+ function deepMerge(target, source) {
457
+ const output = { ...target };
458
+ if (isObject(target) && isObject(source)) {
459
+ Object.entries(source).forEach(([k, v]) => {
460
+ if (isArray(v)) {
461
+ output[k] = v.map((x) => deepMerge(x, x));
462
+ } else if (isObject(v)) {
463
+ const targetValue = k in target ? target[k] : void 0;
464
+ output[k] = isObject(targetValue) ? deepMerge(targetValue, v) : deepMerge(v, v);
465
+ } else {
466
+ output[k] = v;
467
+ }
468
+ });
469
+ }
470
+ return output;
471
+ }
472
+
450
473
  // src/utils/enumToList.ts
451
474
  function enumToList(enumeration, separatorRegex = /_/g) {
452
475
  const array = Object.keys(enumeration);
@@ -814,7 +837,7 @@ var JsonService = class {
814
837
  // src/locale/locale.ts
815
838
  function getDefaultLocale() {
816
839
  let defaultLocale2 = "en";
817
- if (process && process.env.DEFAULT_LOCALE) {
840
+ if (typeof process !== "undefined" && process.env.DEFAULT_LOCALE) {
818
841
  defaultLocale2 = process.env.DEFAULT_LOCALE;
819
842
  }
820
843
  return defaultLocale2;
@@ -908,7 +931,7 @@ Logger.level_ = 5 /* ALL */;
908
931
  // src/market/market.ts
909
932
  function getDefaultMarket() {
910
933
  let defaultMarket2 = "ww";
911
- if (process && process.env.DEFAULT_MARKET) {
934
+ if (typeof process !== "undefined" && process.env.DEFAULT_MARKET) {
912
935
  defaultMarket2 = process.env.DEFAULT_MARKET;
913
936
  }
914
937
  return defaultMarket2;
@@ -1028,6 +1051,31 @@ function qsDeserializeRaw(query = "", deserializedParams = {}) {
1028
1051
  return deserializedParams;
1029
1052
  }
1030
1053
 
1054
+ // src/request/request.ts
1055
+ function isHeaders(headers) {
1056
+ return typeof headers === "object" && "get" in headers ? typeof headers.get === "function" : false;
1057
+ }
1058
+ function isIncomingHttpHeaders(headers) {
1059
+ return typeof headers === "object" && !("get" in headers);
1060
+ }
1061
+ function getHost(headers) {
1062
+ if (isIncomingHttpHeaders(headers)) {
1063
+ return headers["x-forwarded-host"] || headers.forwarded || headers.host || null;
1064
+ } else if (isHeaders(headers)) {
1065
+ return headers.get("X-Forwarded-Host") || headers.get("Forwarded") || headers.get("Host") || null;
1066
+ } else {
1067
+ return null;
1068
+ }
1069
+ }
1070
+ function getOrigin(headers) {
1071
+ const host = getHost(headers);
1072
+ if (host) {
1073
+ return host.indexOf("localhost") !== -1 ? "http://" + host : "https://" + host;
1074
+ } else {
1075
+ return process.env.NEXT_PUBLIC_URL || "";
1076
+ }
1077
+ }
1078
+
1031
1079
  // src/route/route.ts
1032
1080
  function collectRoutes(store, categories, markets, locales) {
1033
1081
  const routes = [];
@@ -1199,6 +1247,7 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
1199
1247
  collectOptions,
1200
1248
  collectRoutes,
1201
1249
  consoleWarn,
1250
+ deepMerge,
1202
1251
  defaultLocale,
1203
1252
  defaultMarket,
1204
1253
  eachCategorized,
@@ -1209,8 +1258,10 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
1209
1258
  getClassNames,
1210
1259
  getCollectionDescription,
1211
1260
  getEnv,
1261
+ getHost,
1212
1262
  getIsDevelopment,
1213
1263
  getIsProduction,
1264
+ getOrigin,
1214
1265
  getParentCategoriesById,
1215
1266
  getRootCategory,
1216
1267
  getRouteHref,
@@ -1226,6 +1277,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
1226
1277
  isDevelopment,
1227
1278
  isEntity,
1228
1279
  isEquatable,
1280
+ isHeaders,
1281
+ isIncomingHttpHeaders,
1229
1282
  isLocalizedString,
1230
1283
  isMenuHref,
1231
1284
  isNotNullString,
package/dist/index.mjs CHANGED
@@ -329,6 +329,24 @@ async function collectOptions(items, ...keys) {
329
329
  return optionsGroup;
330
330
  }
331
331
 
332
+ // src/utils/deepMerge.ts
333
+ function deepMerge(target, source) {
334
+ const output = { ...target };
335
+ if (isObject(target) && isObject(source)) {
336
+ Object.entries(source).forEach(([k, v]) => {
337
+ if (isArray(v)) {
338
+ output[k] = v.map((x) => deepMerge(x, x));
339
+ } else if (isObject(v)) {
340
+ const targetValue = k in target ? target[k] : void 0;
341
+ output[k] = isObject(targetValue) ? deepMerge(targetValue, v) : deepMerge(v, v);
342
+ } else {
343
+ output[k] = v;
344
+ }
345
+ });
346
+ }
347
+ return output;
348
+ }
349
+
332
350
  // src/utils/enumToList.ts
333
351
  function enumToList(enumeration, separatorRegex = /_/g) {
334
352
  const array = Object.keys(enumeration);
@@ -696,7 +714,7 @@ var JsonService = class {
696
714
  // src/locale/locale.ts
697
715
  function getDefaultLocale() {
698
716
  let defaultLocale2 = "en";
699
- if (process && process.env.DEFAULT_LOCALE) {
717
+ if (typeof process !== "undefined" && process.env.DEFAULT_LOCALE) {
700
718
  defaultLocale2 = process.env.DEFAULT_LOCALE;
701
719
  }
702
720
  return defaultLocale2;
@@ -790,7 +808,7 @@ Logger.level_ = 5 /* ALL */;
790
808
  // src/market/market.ts
791
809
  function getDefaultMarket() {
792
810
  let defaultMarket2 = "ww";
793
- if (process && process.env.DEFAULT_MARKET) {
811
+ if (typeof process !== "undefined" && process.env.DEFAULT_MARKET) {
794
812
  defaultMarket2 = process.env.DEFAULT_MARKET;
795
813
  }
796
814
  return defaultMarket2;
@@ -910,6 +928,31 @@ function qsDeserializeRaw(query = "", deserializedParams = {}) {
910
928
  return deserializedParams;
911
929
  }
912
930
 
931
+ // src/request/request.ts
932
+ function isHeaders(headers) {
933
+ return typeof headers === "object" && "get" in headers ? typeof headers.get === "function" : false;
934
+ }
935
+ function isIncomingHttpHeaders(headers) {
936
+ return typeof headers === "object" && !("get" in headers);
937
+ }
938
+ function getHost(headers) {
939
+ if (isIncomingHttpHeaders(headers)) {
940
+ return headers["x-forwarded-host"] || headers.forwarded || headers.host || null;
941
+ } else if (isHeaders(headers)) {
942
+ return headers.get("X-Forwarded-Host") || headers.get("Forwarded") || headers.get("Host") || null;
943
+ } else {
944
+ return null;
945
+ }
946
+ }
947
+ function getOrigin(headers) {
948
+ const host = getHost(headers);
949
+ if (host) {
950
+ return host.indexOf("localhost") !== -1 ? "http://" + host : "https://" + host;
951
+ } else {
952
+ return process.env.NEXT_PUBLIC_URL || "";
953
+ }
954
+ }
955
+
913
956
  // src/route/route.ts
914
957
  function collectRoutes(store, categories, markets, locales) {
915
958
  const routes = [];
@@ -1080,6 +1123,7 @@ export {
1080
1123
  collectOptions,
1081
1124
  collectRoutes,
1082
1125
  consoleWarn,
1126
+ deepMerge,
1083
1127
  defaultLocale,
1084
1128
  defaultMarket,
1085
1129
  eachCategorized,
@@ -1090,8 +1134,10 @@ export {
1090
1134
  getClassNames,
1091
1135
  getCollectionDescription,
1092
1136
  getEnv,
1137
+ getHost,
1093
1138
  getIsDevelopment,
1094
1139
  getIsProduction,
1140
+ getOrigin,
1095
1141
  getParentCategoriesById,
1096
1142
  getRootCategory,
1097
1143
  getRouteHref,
@@ -1107,6 +1153,8 @@ export {
1107
1153
  isDevelopment,
1108
1154
  isEntity,
1109
1155
  isEquatable,
1156
+ isHeaders,
1157
+ isIncomingHttpHeaders,
1110
1158
  isLocalizedString,
1111
1159
  isMenuHref,
1112
1160
  isNotNullString,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -26,19 +26,19 @@
26
26
  "pluralize": "latest"
27
27
  },
28
28
  "peerDependencies": {
29
- "next": ">= 13.4.19"
29
+ "next": ">= 14.1.4"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@websolutespa/bom-cli": "*",
33
33
  "@websolutespa/test": "*",
34
34
  "@websolutespa/tsconfig": "*",
35
- "eslint": "^8.46.0",
35
+ "eslint": "^9.0.0",
36
36
  "eslint-config-websolute": "*",
37
37
  "npm-run-all": "^4.1.5",
38
38
  "raw-loader": "^4.0.2",
39
- "ts-node": "^10.9.1",
39
+ "ts-node": "^10.9.2",
40
40
  "tsup": "^6.7.0",
41
- "typescript": "^5.1.6"
41
+ "typescript": "^5.4.5"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"