@websolutespa/bom-core 0.6.0 → 0.6.2

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
+ ## 0.6.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: IMedia.
8
+
9
+ ## 0.6.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Added: defaultMarket, defaultLocale
14
+
3
15
  ## 0.6.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -84,16 +84,18 @@ type ITitledEntity = IEntity & {
84
84
 
85
85
  type IMediaType = 'image' | 'video' | string;
86
86
  type IMedia = {
87
- src: string;
88
- type: IMediaType;
89
- alt?: string;
90
- title?: string;
91
87
  abstract?: string;
92
- width?: number;
88
+ alt?: string;
93
89
  height?: number;
94
- url?: string;
95
90
  media?: IMedia;
91
+ mimeType?: string;
92
+ src: string;
93
+ title?: string;
94
+ type: IMediaType;
95
+ url?: string;
96
+ width?: number;
96
97
  };
98
+ declare function resolveMediaType(media: IMedia): IMediaType;
97
99
 
98
100
  type ICategory = IEntity & {
99
101
  category?: IEquatable | ICategory;
@@ -520,11 +522,13 @@ declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
520
522
  } & Pagination);
521
523
  }
522
524
 
525
+ declare const defaultLocale: string;
526
+
523
527
  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;
528
+ declare function localizedToString(json: ILocalizedString, locale: string, defaultLocale?: string): string;
529
+ declare function localize(value: ILocalizable, locale: string, defaultLocale?: string): string;
530
+ declare function localizeValue(value: any, locale: string, defaultLocale?: string): any;
531
+ declare function localizeItem<T = any>(item: T, locale: string, defaultLocale?: string): T;
528
532
 
529
533
  declare enum LoggerLevel {
530
534
  NONE = 0,
@@ -544,6 +548,8 @@ declare class Logger {
544
548
  static log(...args: unknown[]): void;
545
549
  }
546
550
 
551
+ declare const defaultMarket: string;
552
+
547
553
  declare function qsSerialize(queryParams?: QueryParams): string;
548
554
  declare function qsSerializeRaw(queryParams?: {}): string;
549
555
  declare function qsDeserialize(query?: string, deserializedParams?: {}): QueryParams;
@@ -619,4 +625,4 @@ declare function asServerProps(props: any): any;
619
625
  declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
620
626
  declare function merge(target: any, source: any): any;
621
627
 
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 };
628
+ 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, resolveMediaType, 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,
@@ -92,6 +94,7 @@ __export(src_exports, {
92
94
  qsDeserializeRaw: () => qsDeserializeRaw,
93
95
  qsSerialize: () => qsSerialize,
94
96
  qsSerializeRaw: () => qsSerializeRaw,
97
+ resolveMediaType: () => resolveMediaType,
95
98
  textToSlug: () => textToSlug,
96
99
  toCamelCase: () => toCamelCase,
97
100
  toCharCase: () => toCharCase,
@@ -713,7 +716,18 @@ var JsonService = class {
713
716
  // ^ sort
714
717
  };
715
718
 
719
+ // src/locale/locale.ts
720
+ function getDefaultLocale() {
721
+ let defaultLocale2 = "en";
722
+ if (process && process.env.DEFAULT_LOCALE) {
723
+ defaultLocale2 = process.env.DEFAULT_LOCALE;
724
+ }
725
+ return defaultLocale2;
726
+ }
727
+ var defaultLocale = getDefaultLocale();
728
+
716
729
  // src/localized/localized.ts
730
+ var DEFAULT_LOCALE = defaultLocale;
717
731
  function isLocalizedString(value) {
718
732
  let isLocalizedString2 = false;
719
733
  if (value && !Array.isArray(value) && typeof value === "object") {
@@ -723,30 +737,30 @@ function isLocalizedString(value) {
723
737
  }
724
738
  return isLocalizedString2;
725
739
  }
726
- function localizedToString(json, locale = "en", defaultLocale = "en") {
727
- const localizedString = json[locale] || json[defaultLocale] || Object.values(json)[0];
740
+ function localizedToString(json, locale, defaultLocale2 = DEFAULT_LOCALE) {
741
+ const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
728
742
  return localizedString;
729
743
  }
730
- function localize(value, locale = "en", defaultLocale = "en") {
731
- return isLocalizedString(value) ? localizedToString(value, locale, defaultLocale) : value;
744
+ function localize(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
745
+ return isLocalizedString(value) ? localizedToString(value, locale, defaultLocale2) : value;
732
746
  }
733
- function localizeValue(value, locale = "en", defaultLocale = "en") {
747
+ function localizeValue(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
734
748
  if (value) {
735
749
  if (isLocalizedString(value)) {
736
- return localizedToString(value, locale, defaultLocale);
750
+ return localizedToString(value, locale, defaultLocale2);
737
751
  } else {
738
- return localizeItem(value, locale, defaultLocale);
752
+ return localizeItem(value, locale, defaultLocale2);
739
753
  }
740
754
  }
741
755
  }
742
- function localizeItem(item, locale = "en", defaultLocale = "en") {
756
+ function localizeItem(item, locale, defaultLocale2 = DEFAULT_LOCALE) {
743
757
  if (isArray(item)) {
744
- item = item.map((x) => localizeValue(x, locale, defaultLocale));
758
+ item = item.map((x) => localizeValue(x, locale, defaultLocale2));
745
759
  } else if (isObject(item)) {
746
760
  item = { ...item };
747
761
  const object = item;
748
762
  Object.keys(object).forEach((key) => {
749
- object[key] = localizeValue(object[key], locale, defaultLocale);
763
+ object[key] = localizeValue(object[key], locale, defaultLocale2);
750
764
  });
751
765
  }
752
766
  return item;
@@ -796,6 +810,16 @@ var Logger = class {
796
810
  };
797
811
  Logger.level_ = 5 /* ALL */;
798
812
 
813
+ // src/market/market.ts
814
+ function getDefaultMarket() {
815
+ let defaultMarket2 = "ww";
816
+ if (process && process.env.DEFAULT_MARKET) {
817
+ defaultMarket2 = process.env.DEFAULT_MARKET;
818
+ }
819
+ return defaultMarket2;
820
+ }
821
+ var defaultMarket = getDefaultMarket();
822
+
799
823
  // src/qs/qs.ts
800
824
  function qsSerializeKey(key, parentKey = "") {
801
825
  return parentKey ? `${parentKey}[${key}]` : String(key);
@@ -939,13 +963,13 @@ function collectRoutes(store, categories, markets, locales) {
939
963
  }
940
964
  });
941
965
  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;
966
+ const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
967
+ const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
968
+ const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? defaultMarket2.defaultLanguage : defaultLocale2.id;
945
969
  const title = localize(item.title, defaultMarketLocale);
946
970
  const route = {
947
971
  id: "/",
948
- market: defaultMarket.id,
972
+ market: defaultMarket2.id,
949
973
  locale: defaultMarketLocale,
950
974
  category: item.category,
951
975
  page: item.id,
@@ -1031,6 +1055,11 @@ function textToSlug(title) {
1031
1055
  return title.toString().normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, "-").replace(/&/g, "-and-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
1032
1056
  }
1033
1057
 
1058
+ // src/types/media.ts
1059
+ function resolveMediaType(media) {
1060
+ return media.type || (media.mimeType ? media.mimeType.split("/")[0] : "image");
1061
+ }
1062
+
1034
1063
  // src/types/querable.ts
1035
1064
  function toFindParams(idOrParams) {
1036
1065
  if (typeof idOrParams === "number" || typeof idOrParams === "string") {
@@ -1064,6 +1093,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
1064
1093
  cloneItem,
1065
1094
  collectRoutes,
1066
1095
  consoleWarn,
1096
+ defaultLocale,
1097
+ defaultMarket,
1067
1098
  eachCategorized,
1068
1099
  eachMarketLocale,
1069
1100
  enumToList,
@@ -1113,6 +1144,7 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
1113
1144
  qsDeserializeRaw,
1114
1145
  qsSerialize,
1115
1146
  qsSerializeRaw,
1147
+ resolveMediaType,
1116
1148
  textToSlug,
1117
1149
  toCamelCase,
1118
1150
  toCharCase,
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,
@@ -921,6 +942,11 @@ function textToSlug(title) {
921
942
  return title.toString().normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, "-").replace(/&/g, "-and-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
922
943
  }
923
944
 
945
+ // src/types/media.ts
946
+ function resolveMediaType(media) {
947
+ return media.type || (media.mimeType ? media.mimeType.split("/")[0] : "image");
948
+ }
949
+
924
950
  // src/types/querable.ts
925
951
  function toFindParams(idOrParams) {
926
952
  if (typeof idOrParams === "number" || typeof idOrParams === "string") {
@@ -953,6 +979,8 @@ export {
953
979
  cloneItem,
954
980
  collectRoutes,
955
981
  consoleWarn,
982
+ defaultLocale,
983
+ defaultMarket,
956
984
  eachCategorized,
957
985
  eachMarketLocale,
958
986
  enumToList,
@@ -1002,6 +1030,7 @@ export {
1002
1030
  qsDeserializeRaw,
1003
1031
  qsSerialize,
1004
1032
  qsSerializeRaw,
1033
+ resolveMediaType,
1005
1034
  textToSlug,
1006
1035
  toCamelCase,
1007
1036
  toCharCase,
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.2",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",