@websolutespa/bom-core 0.6.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,70 +1,76 @@
1
- # @websolutespa/bom-core
2
-
3
- ## 0.6.0
4
-
5
- ### Minor Changes
6
-
7
- - Added Logger, IPaginationResult.
8
-
9
- ## 0.5.0
10
-
11
- ### Minor Changes
12
-
13
- - Modified: JsonService, qs.
14
- - Added: asEquatable, cloneItem, typeGuards.
15
-
16
- ## 0.4.1
17
-
18
- ### Patch Changes
19
-
20
- - Added: IAnchor, babelCase.
21
- - Modified: IApplication, IPageRelation.
22
-
23
- ## 0.4.0
24
-
25
- ### Minor Changes
26
-
27
- - Updating: next 13.
28
-
29
- ## 0.3.0
30
-
31
- ### Minor Changes
32
-
33
- - Modified: HttpService.
34
-
35
- ## 0.2.1
36
-
37
- ### Patch Changes
38
-
39
- - Added: env ROOT_CATEGORY.
40
-
41
- ## 0.2.0
42
-
43
- ### Minor Changes
44
-
45
- - Modified routes, added redirects.
46
-
47
- ## 0.1.2
48
-
49
- ### Patch Changes
50
-
51
- - Modified: MockMenuService.
52
-
53
- ## 0.1.1
54
-
55
- ### Patch Changes
56
-
57
- - Modified: ILocalizable.
58
-
59
- ## 0.1.0
60
-
61
- ### Minor Changes
62
-
63
- - Added: splat routes.
64
- - Added: variants.
65
-
66
- ## 0.0.1
67
-
68
- ### Patch Changes
69
-
70
- - Added: first release.
1
+ # @websolutespa/bom-core
2
+
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - dad63747: Added defaultMarket, defaultLocale
8
+
9
+ ## 0.6.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Added Logger, IPaginationResult.
14
+
15
+ ## 0.5.0
16
+
17
+ ### Minor Changes
18
+
19
+ - Modified: JsonService, qs.
20
+ - Added: asEquatable, cloneItem, typeGuards.
21
+
22
+ ## 0.4.1
23
+
24
+ ### Patch Changes
25
+
26
+ - Added: IAnchor, babelCase.
27
+ - Modified: IApplication, IPageRelation.
28
+
29
+ ## 0.4.0
30
+
31
+ ### Minor Changes
32
+
33
+ - Updating: next 13.
34
+
35
+ ## 0.3.0
36
+
37
+ ### Minor Changes
38
+
39
+ - Modified: HttpService.
40
+
41
+ ## 0.2.1
42
+
43
+ ### Patch Changes
44
+
45
+ - Added: env ROOT_CATEGORY.
46
+
47
+ ## 0.2.0
48
+
49
+ ### Minor Changes
50
+
51
+ - Modified routes, added redirects.
52
+
53
+ ## 0.1.2
54
+
55
+ ### Patch Changes
56
+
57
+ - Modified: MockMenuService.
58
+
59
+ ## 0.1.1
60
+
61
+ ### Patch Changes
62
+
63
+ - Modified: ILocalizable.
64
+
65
+ ## 0.1.0
66
+
67
+ ### Minor Changes
68
+
69
+ - Added: splat routes.
70
+ - Added: variants.
71
+
72
+ ## 0.0.1
73
+
74
+ ### Patch Changes
75
+
76
+ - Added: first release.
package/dist/index.d.ts CHANGED
@@ -520,11 +520,13 @@ declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
520
520
  } & Pagination);
521
521
  }
522
522
 
523
+ declare const defaultLocale: string;
524
+
523
525
  declare function isLocalizedString(value: any): value is ILocalizedString;
524
- declare function localizedToString(json: ILocalizedString, locale?: string, defaultLocale?: string): string;
525
- declare function localize(value: ILocalizable, locale?: string, defaultLocale?: string): string;
526
- declare function localizeValue(value: any, locale?: string, defaultLocale?: string): any;
527
- declare function localizeItem<T = any>(item: T, locale?: string, defaultLocale?: string): T;
526
+ declare function localizedToString(json: ILocalizedString, locale: string, defaultLocale?: string): string;
527
+ declare function localize(value: ILocalizable, locale: string, defaultLocale?: string): string;
528
+ declare function localizeValue(value: any, locale: string, defaultLocale?: string): any;
529
+ declare function localizeItem<T = any>(item: T, locale: string, defaultLocale?: string): T;
528
530
 
529
531
  declare enum LoggerLevel {
530
532
  NONE = 0,
@@ -544,6 +546,8 @@ declare class Logger {
544
546
  static log(...args: unknown[]): void;
545
547
  }
546
548
 
549
+ declare const defaultMarket: string;
550
+
547
551
  declare function qsSerialize(queryParams?: QueryParams): string;
548
552
  declare function qsSerializeRaw(queryParams?: {}): string;
549
553
  declare function qsDeserialize(query?: string, deserializedParams?: {}): QueryParams;
@@ -619,4 +623,4 @@ declare function asServerProps(props: any): any;
619
623
  declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
620
624
  declare function merge(target: any, source: any): any;
621
625
 
622
- export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, IDecoratedNav, IEntity, IEquatable, ILabel, ILayout, ILocale, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IPackages, IPage, IPageRelation, IPageRelationResult, IPageResult, IPageUnresolvedRelation, IPaginationResult, IPartial, 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, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, collectRoutes, consoleWarn, 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, isNotNullString, isObject, isProduction, isRelation, isStage, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
626
+ export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, IDecoratedNav, IEntity, IEquatable, ILabel, ILayout, ILocale, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IPackages, IPage, IPageRelation, IPageRelationResult, IPageResult, IPageUnresolvedRelation, IPaginationResult, IPartial, 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, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, 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, isNotNullString, isObject, isProduction, isRelation, isStage, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
package/dist/index.js CHANGED
@@ -43,6 +43,8 @@ __export(src_exports, {
43
43
  cloneItem: () => cloneItem,
44
44
  collectRoutes: () => collectRoutes,
45
45
  consoleWarn: () => consoleWarn,
46
+ defaultLocale: () => defaultLocale,
47
+ defaultMarket: () => defaultMarket,
46
48
  eachCategorized: () => eachCategorized,
47
49
  eachMarketLocale: () => eachMarketLocale,
48
50
  enumToList: () => enumToList,
@@ -713,7 +715,18 @@ var JsonService = class {
713
715
  // ^ sort
714
716
  };
715
717
 
718
+ // src/locale/locale.ts
719
+ function getDefaultLocale() {
720
+ let defaultLocale2 = "en";
721
+ if (process && process.env.DEFAULT_LOCALE) {
722
+ defaultLocale2 = process.env.DEFAULT_LOCALE;
723
+ }
724
+ return defaultLocale2;
725
+ }
726
+ var defaultLocale = getDefaultLocale();
727
+
716
728
  // src/localized/localized.ts
729
+ var DEFAULT_LOCALE = defaultLocale;
717
730
  function isLocalizedString(value) {
718
731
  let isLocalizedString2 = false;
719
732
  if (value && !Array.isArray(value) && typeof value === "object") {
@@ -723,30 +736,30 @@ function isLocalizedString(value) {
723
736
  }
724
737
  return isLocalizedString2;
725
738
  }
726
- function localizedToString(json, locale = "en", defaultLocale = "en") {
727
- const localizedString = json[locale] || json[defaultLocale] || Object.values(json)[0];
739
+ function localizedToString(json, locale, defaultLocale2 = DEFAULT_LOCALE) {
740
+ const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
728
741
  return localizedString;
729
742
  }
730
- function localize(value, locale = "en", defaultLocale = "en") {
731
- return isLocalizedString(value) ? localizedToString(value, locale, defaultLocale) : value;
743
+ function localize(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
744
+ return isLocalizedString(value) ? localizedToString(value, locale, defaultLocale2) : value;
732
745
  }
733
- function localizeValue(value, locale = "en", defaultLocale = "en") {
746
+ function localizeValue(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
734
747
  if (value) {
735
748
  if (isLocalizedString(value)) {
736
- return localizedToString(value, locale, defaultLocale);
749
+ return localizedToString(value, locale, defaultLocale2);
737
750
  } else {
738
- return localizeItem(value, locale, defaultLocale);
751
+ return localizeItem(value, locale, defaultLocale2);
739
752
  }
740
753
  }
741
754
  }
742
- function localizeItem(item, locale = "en", defaultLocale = "en") {
755
+ function localizeItem(item, locale, defaultLocale2 = DEFAULT_LOCALE) {
743
756
  if (isArray(item)) {
744
- item = item.map((x) => localizeValue(x, locale, defaultLocale));
757
+ item = item.map((x) => localizeValue(x, locale, defaultLocale2));
745
758
  } else if (isObject(item)) {
746
759
  item = { ...item };
747
760
  const object = item;
748
761
  Object.keys(object).forEach((key) => {
749
- object[key] = localizeValue(object[key], locale, defaultLocale);
762
+ object[key] = localizeValue(object[key], locale, defaultLocale2);
750
763
  });
751
764
  }
752
765
  return item;
@@ -796,6 +809,16 @@ var Logger = class {
796
809
  };
797
810
  Logger.level_ = 5 /* ALL */;
798
811
 
812
+ // src/market/market.ts
813
+ function getDefaultMarket() {
814
+ let defaultMarket2 = "ww";
815
+ if (process && process.env.DEFAULT_MARKET) {
816
+ defaultMarket2 = process.env.DEFAULT_MARKET;
817
+ }
818
+ return defaultMarket2;
819
+ }
820
+ var defaultMarket = getDefaultMarket();
821
+
799
822
  // src/qs/qs.ts
800
823
  function qsSerializeKey(key, parentKey = "") {
801
824
  return parentKey ? `${parentKey}[${key}]` : String(key);
@@ -939,13 +962,13 @@ function collectRoutes(store, categories, markets, locales) {
939
962
  }
940
963
  });
941
964
  if (rootCategory && item.category === rootCategory.id) {
942
- const defaultLocale = locales.find((x) => x.isDefault) || locales[0];
943
- const defaultMarket = markets.find((x) => x.isDefault) || markets[0];
944
- const defaultMarketLocale = defaultMarket && defaultMarket.defaultLanguage ? defaultMarket.defaultLanguage : defaultLocale.id;
965
+ const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
966
+ const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
967
+ const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? defaultMarket2.defaultLanguage : defaultLocale2.id;
945
968
  const title = localize(item.title, defaultMarketLocale);
946
969
  const route = {
947
970
  id: "/",
948
- market: defaultMarket.id,
971
+ market: defaultMarket2.id,
949
972
  locale: defaultMarketLocale,
950
973
  category: item.category,
951
974
  page: item.id,
@@ -1064,6 +1087,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
1064
1087
  cloneItem,
1065
1088
  collectRoutes,
1066
1089
  consoleWarn,
1090
+ defaultLocale,
1091
+ defaultMarket,
1067
1092
  eachCategorized,
1068
1093
  eachMarketLocale,
1069
1094
  enumToList,
package/dist/index.mjs CHANGED
@@ -603,7 +603,18 @@ var JsonService = class {
603
603
  // ^ sort
604
604
  };
605
605
 
606
+ // src/locale/locale.ts
607
+ function getDefaultLocale() {
608
+ let defaultLocale2 = "en";
609
+ if (process && process.env.DEFAULT_LOCALE) {
610
+ defaultLocale2 = process.env.DEFAULT_LOCALE;
611
+ }
612
+ return defaultLocale2;
613
+ }
614
+ var defaultLocale = getDefaultLocale();
615
+
606
616
  // src/localized/localized.ts
617
+ var DEFAULT_LOCALE = defaultLocale;
607
618
  function isLocalizedString(value) {
608
619
  let isLocalizedString2 = false;
609
620
  if (value && !Array.isArray(value) && typeof value === "object") {
@@ -613,30 +624,30 @@ function isLocalizedString(value) {
613
624
  }
614
625
  return isLocalizedString2;
615
626
  }
616
- function localizedToString(json, locale = "en", defaultLocale = "en") {
617
- const localizedString = json[locale] || json[defaultLocale] || Object.values(json)[0];
627
+ function localizedToString(json, locale, defaultLocale2 = DEFAULT_LOCALE) {
628
+ const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
618
629
  return localizedString;
619
630
  }
620
- function localize(value, locale = "en", defaultLocale = "en") {
621
- return isLocalizedString(value) ? localizedToString(value, locale, defaultLocale) : value;
631
+ function localize(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
632
+ return isLocalizedString(value) ? localizedToString(value, locale, defaultLocale2) : value;
622
633
  }
623
- function localizeValue(value, locale = "en", defaultLocale = "en") {
634
+ function localizeValue(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
624
635
  if (value) {
625
636
  if (isLocalizedString(value)) {
626
- return localizedToString(value, locale, defaultLocale);
637
+ return localizedToString(value, locale, defaultLocale2);
627
638
  } else {
628
- return localizeItem(value, locale, defaultLocale);
639
+ return localizeItem(value, locale, defaultLocale2);
629
640
  }
630
641
  }
631
642
  }
632
- function localizeItem(item, locale = "en", defaultLocale = "en") {
643
+ function localizeItem(item, locale, defaultLocale2 = DEFAULT_LOCALE) {
633
644
  if (isArray(item)) {
634
- item = item.map((x) => localizeValue(x, locale, defaultLocale));
645
+ item = item.map((x) => localizeValue(x, locale, defaultLocale2));
635
646
  } else if (isObject(item)) {
636
647
  item = { ...item };
637
648
  const object = item;
638
649
  Object.keys(object).forEach((key) => {
639
- object[key] = localizeValue(object[key], locale, defaultLocale);
650
+ object[key] = localizeValue(object[key], locale, defaultLocale2);
640
651
  });
641
652
  }
642
653
  return item;
@@ -686,6 +697,16 @@ var Logger = class {
686
697
  };
687
698
  Logger.level_ = 5 /* ALL */;
688
699
 
700
+ // src/market/market.ts
701
+ function getDefaultMarket() {
702
+ let defaultMarket2 = "ww";
703
+ if (process && process.env.DEFAULT_MARKET) {
704
+ defaultMarket2 = process.env.DEFAULT_MARKET;
705
+ }
706
+ return defaultMarket2;
707
+ }
708
+ var defaultMarket = getDefaultMarket();
709
+
689
710
  // src/qs/qs.ts
690
711
  function qsSerializeKey(key, parentKey = "") {
691
712
  return parentKey ? `${parentKey}[${key}]` : String(key);
@@ -829,13 +850,13 @@ function collectRoutes(store, categories, markets, locales) {
829
850
  }
830
851
  });
831
852
  if (rootCategory && item.category === rootCategory.id) {
832
- const defaultLocale = locales.find((x) => x.isDefault) || locales[0];
833
- const defaultMarket = markets.find((x) => x.isDefault) || markets[0];
834
- const defaultMarketLocale = defaultMarket && defaultMarket.defaultLanguage ? defaultMarket.defaultLanguage : defaultLocale.id;
853
+ const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
854
+ const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
855
+ const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? defaultMarket2.defaultLanguage : defaultLocale2.id;
835
856
  const title = localize(item.title, defaultMarketLocale);
836
857
  const route = {
837
858
  id: "/",
838
- market: defaultMarket.id,
859
+ market: defaultMarket2.id,
839
860
  locale: defaultMarketLocale,
840
861
  category: item.category,
841
862
  page: item.id,
@@ -953,6 +974,8 @@ export {
953
974
  cloneItem,
954
975
  collectRoutes,
955
976
  consoleWarn,
977
+ defaultLocale,
978
+ defaultMarket,
956
979
  eachCategorized,
957
980
  eachMarketLocale,
958
981
  enumToList,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",