@websolutespa/bom-core 0.5.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 +76 -64
- package/dist/index.d.ts +30 -5
- package/dist/index.js +87 -14
- package/dist/index.mjs +83 -14
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,64 +1,76 @@
|
|
|
1
|
-
# @websolutespa/bom-core
|
|
2
|
-
|
|
3
|
-
## 0.
|
|
4
|
-
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
- Modified:
|
|
28
|
-
|
|
29
|
-
## 0.
|
|
30
|
-
|
|
31
|
-
###
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
## 0.
|
|
36
|
-
|
|
37
|
-
### Minor Changes
|
|
38
|
-
|
|
39
|
-
- Modified
|
|
40
|
-
|
|
41
|
-
## 0.1
|
|
42
|
-
|
|
43
|
-
### Patch Changes
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
## 0.
|
|
48
|
-
|
|
49
|
-
###
|
|
50
|
-
|
|
51
|
-
- Modified
|
|
52
|
-
|
|
53
|
-
## 0.1.
|
|
54
|
-
|
|
55
|
-
###
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
@@ -363,6 +363,9 @@ type Pagination = {
|
|
|
363
363
|
totalDocs: number;
|
|
364
364
|
totalPages: number;
|
|
365
365
|
};
|
|
366
|
+
type IPaginationResult<T> = {
|
|
367
|
+
docs: T[];
|
|
368
|
+
} & Pagination;
|
|
366
369
|
|
|
367
370
|
type Operator = 'equals' | 'contains' | 'not_equals' | 'in' | 'not_in' | 'exists' | 'greater_than' | 'greater_than_equal' | 'less_than' | 'less_than_equal' | 'like' | 'near';
|
|
368
371
|
type WhereField = {
|
|
@@ -517,11 +520,33 @@ declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
|
|
|
517
520
|
} & Pagination);
|
|
518
521
|
}
|
|
519
522
|
|
|
523
|
+
declare const defaultLocale: string;
|
|
524
|
+
|
|
520
525
|
declare function isLocalizedString(value: any): value is ILocalizedString;
|
|
521
|
-
declare function localizedToString(json: ILocalizedString, locale
|
|
522
|
-
declare function localize(value: ILocalizable, locale
|
|
523
|
-
declare function localizeValue(value: any, locale
|
|
524
|
-
declare function localizeItem<T = any>(item: T, locale
|
|
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;
|
|
530
|
+
|
|
531
|
+
declare enum LoggerLevel {
|
|
532
|
+
NONE = 0,
|
|
533
|
+
ERROR = 1,
|
|
534
|
+
WARN = 2,
|
|
535
|
+
INFO = 3,
|
|
536
|
+
LOG = 4,
|
|
537
|
+
ALL = 5
|
|
538
|
+
}
|
|
539
|
+
declare class Logger {
|
|
540
|
+
static level_: LoggerLevel;
|
|
541
|
+
static setLevel(level: LoggerLevel): void;
|
|
542
|
+
static getLevel(): LoggerLevel;
|
|
543
|
+
static error(...args: unknown[]): void;
|
|
544
|
+
static warn(...args: unknown[]): void;
|
|
545
|
+
static info(...args: unknown[]): void;
|
|
546
|
+
static log(...args: unknown[]): void;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
declare const defaultMarket: string;
|
|
525
550
|
|
|
526
551
|
declare function qsSerialize(queryParams?: QueryParams): string;
|
|
527
552
|
declare function qsSerializeRaw(queryParams?: {}): string;
|
|
@@ -598,4 +623,4 @@ declare function asServerProps(props: any): any;
|
|
|
598
623
|
declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
|
|
599
624
|
declare function merge(target: any, source: any): any;
|
|
600
625
|
|
|
601
|
-
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, 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, 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
|
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
JsonService: () => JsonService,
|
|
34
|
+
Logger: () => Logger,
|
|
35
|
+
LoggerLevel: () => LoggerLevel,
|
|
34
36
|
RedirectReason: () => RedirectReason,
|
|
35
37
|
RouteStrategy: () => RouteStrategy,
|
|
36
38
|
asCategoryId: () => asCategoryId,
|
|
@@ -41,6 +43,8 @@ __export(src_exports, {
|
|
|
41
43
|
cloneItem: () => cloneItem,
|
|
42
44
|
collectRoutes: () => collectRoutes,
|
|
43
45
|
consoleWarn: () => consoleWarn,
|
|
46
|
+
defaultLocale: () => defaultLocale,
|
|
47
|
+
defaultMarket: () => defaultMarket,
|
|
44
48
|
eachCategorized: () => eachCategorized,
|
|
45
49
|
eachMarketLocale: () => eachMarketLocale,
|
|
46
50
|
enumToList: () => enumToList,
|
|
@@ -711,7 +715,18 @@ var JsonService = class {
|
|
|
711
715
|
// ^ sort
|
|
712
716
|
};
|
|
713
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
|
+
|
|
714
728
|
// src/localized/localized.ts
|
|
729
|
+
var DEFAULT_LOCALE = defaultLocale;
|
|
715
730
|
function isLocalizedString(value) {
|
|
716
731
|
let isLocalizedString2 = false;
|
|
717
732
|
if (value && !Array.isArray(value) && typeof value === "object") {
|
|
@@ -721,35 +736,89 @@ function isLocalizedString(value) {
|
|
|
721
736
|
}
|
|
722
737
|
return isLocalizedString2;
|
|
723
738
|
}
|
|
724
|
-
function localizedToString(json, locale
|
|
725
|
-
const localizedString = json[locale] || json[
|
|
739
|
+
function localizedToString(json, locale, defaultLocale2 = DEFAULT_LOCALE) {
|
|
740
|
+
const localizedString = json[locale] || json[defaultLocale2] || Object.values(json)[0];
|
|
726
741
|
return localizedString;
|
|
727
742
|
}
|
|
728
|
-
function localize(value, locale
|
|
729
|
-
return isLocalizedString(value) ? localizedToString(value, locale,
|
|
743
|
+
function localize(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
|
|
744
|
+
return isLocalizedString(value) ? localizedToString(value, locale, defaultLocale2) : value;
|
|
730
745
|
}
|
|
731
|
-
function localizeValue(value, locale
|
|
746
|
+
function localizeValue(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
|
|
732
747
|
if (value) {
|
|
733
748
|
if (isLocalizedString(value)) {
|
|
734
|
-
return localizedToString(value, locale,
|
|
749
|
+
return localizedToString(value, locale, defaultLocale2);
|
|
735
750
|
} else {
|
|
736
|
-
return localizeItem(value, locale,
|
|
751
|
+
return localizeItem(value, locale, defaultLocale2);
|
|
737
752
|
}
|
|
738
753
|
}
|
|
739
754
|
}
|
|
740
|
-
function localizeItem(item, locale
|
|
755
|
+
function localizeItem(item, locale, defaultLocale2 = DEFAULT_LOCALE) {
|
|
741
756
|
if (isArray(item)) {
|
|
742
|
-
item = item.map((x) => localizeValue(x, locale,
|
|
757
|
+
item = item.map((x) => localizeValue(x, locale, defaultLocale2));
|
|
743
758
|
} else if (isObject(item)) {
|
|
744
759
|
item = { ...item };
|
|
745
760
|
const object = item;
|
|
746
761
|
Object.keys(object).forEach((key) => {
|
|
747
|
-
object[key] = localizeValue(object[key], locale,
|
|
762
|
+
object[key] = localizeValue(object[key], locale, defaultLocale2);
|
|
748
763
|
});
|
|
749
764
|
}
|
|
750
765
|
return item;
|
|
751
766
|
}
|
|
752
767
|
|
|
768
|
+
// src/logger/logger.ts
|
|
769
|
+
var LoggerLevel = /* @__PURE__ */ ((LoggerLevel2) => {
|
|
770
|
+
LoggerLevel2[LoggerLevel2["NONE"] = 0] = "NONE";
|
|
771
|
+
LoggerLevel2[LoggerLevel2["ERROR"] = 1] = "ERROR";
|
|
772
|
+
LoggerLevel2[LoggerLevel2["WARN"] = 2] = "WARN";
|
|
773
|
+
LoggerLevel2[LoggerLevel2["INFO"] = 3] = "INFO";
|
|
774
|
+
LoggerLevel2[LoggerLevel2["LOG"] = 4] = "LOG";
|
|
775
|
+
LoggerLevel2[LoggerLevel2["ALL"] = 5] = "ALL";
|
|
776
|
+
return LoggerLevel2;
|
|
777
|
+
})(LoggerLevel || {});
|
|
778
|
+
var Logger = class {
|
|
779
|
+
static setLevel(level) {
|
|
780
|
+
this.level_ = level;
|
|
781
|
+
}
|
|
782
|
+
static getLevel() {
|
|
783
|
+
if (isProduction) {
|
|
784
|
+
return 1 /* ERROR */;
|
|
785
|
+
} else {
|
|
786
|
+
return this.level_;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
static error(...args) {
|
|
790
|
+
if (this.getLevel() >= 1 /* ERROR */) {
|
|
791
|
+
console.error(...args);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
static warn(...args) {
|
|
795
|
+
if (this.getLevel() >= 2 /* WARN */) {
|
|
796
|
+
console.warn(...args);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
static info(...args) {
|
|
800
|
+
if (this.getLevel() >= 3 /* INFO */) {
|
|
801
|
+
console.info(...args);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
static log(...args) {
|
|
805
|
+
if (this.getLevel() >= 4 /* LOG */) {
|
|
806
|
+
console.log(...args);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
Logger.level_ = 5 /* ALL */;
|
|
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
|
+
|
|
753
822
|
// src/qs/qs.ts
|
|
754
823
|
function qsSerializeKey(key, parentKey = "") {
|
|
755
824
|
return parentKey ? `${parentKey}[${key}]` : String(key);
|
|
@@ -893,13 +962,13 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
893
962
|
}
|
|
894
963
|
});
|
|
895
964
|
if (rootCategory && item.category === rootCategory.id) {
|
|
896
|
-
const
|
|
897
|
-
const
|
|
898
|
-
const defaultMarketLocale =
|
|
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;
|
|
899
968
|
const title = localize(item.title, defaultMarketLocale);
|
|
900
969
|
const route = {
|
|
901
970
|
id: "/",
|
|
902
|
-
market:
|
|
971
|
+
market: defaultMarket2.id,
|
|
903
972
|
locale: defaultMarketLocale,
|
|
904
973
|
category: item.category,
|
|
905
974
|
page: item.id,
|
|
@@ -1006,6 +1075,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1006
1075
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1007
1076
|
0 && (module.exports = {
|
|
1008
1077
|
JsonService,
|
|
1078
|
+
Logger,
|
|
1079
|
+
LoggerLevel,
|
|
1009
1080
|
RedirectReason,
|
|
1010
1081
|
RouteStrategy,
|
|
1011
1082
|
asCategoryId,
|
|
@@ -1016,6 +1087,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1016
1087
|
cloneItem,
|
|
1017
1088
|
collectRoutes,
|
|
1018
1089
|
consoleWarn,
|
|
1090
|
+
defaultLocale,
|
|
1091
|
+
defaultMarket,
|
|
1019
1092
|
eachCategorized,
|
|
1020
1093
|
eachMarketLocale,
|
|
1021
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,35 +624,89 @@ function isLocalizedString(value) {
|
|
|
613
624
|
}
|
|
614
625
|
return isLocalizedString2;
|
|
615
626
|
}
|
|
616
|
-
function localizedToString(json, locale
|
|
617
|
-
const localizedString = json[locale] || json[
|
|
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
|
|
621
|
-
return isLocalizedString(value) ? localizedToString(value, locale,
|
|
631
|
+
function localize(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
|
|
632
|
+
return isLocalizedString(value) ? localizedToString(value, locale, defaultLocale2) : value;
|
|
622
633
|
}
|
|
623
|
-
function localizeValue(value, locale
|
|
634
|
+
function localizeValue(value, locale, defaultLocale2 = DEFAULT_LOCALE) {
|
|
624
635
|
if (value) {
|
|
625
636
|
if (isLocalizedString(value)) {
|
|
626
|
-
return localizedToString(value, locale,
|
|
637
|
+
return localizedToString(value, locale, defaultLocale2);
|
|
627
638
|
} else {
|
|
628
|
-
return localizeItem(value, locale,
|
|
639
|
+
return localizeItem(value, locale, defaultLocale2);
|
|
629
640
|
}
|
|
630
641
|
}
|
|
631
642
|
}
|
|
632
|
-
function localizeItem(item, locale
|
|
643
|
+
function localizeItem(item, locale, defaultLocale2 = DEFAULT_LOCALE) {
|
|
633
644
|
if (isArray(item)) {
|
|
634
|
-
item = item.map((x) => localizeValue(x, locale,
|
|
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,
|
|
650
|
+
object[key] = localizeValue(object[key], locale, defaultLocale2);
|
|
640
651
|
});
|
|
641
652
|
}
|
|
642
653
|
return item;
|
|
643
654
|
}
|
|
644
655
|
|
|
656
|
+
// src/logger/logger.ts
|
|
657
|
+
var LoggerLevel = /* @__PURE__ */ ((LoggerLevel2) => {
|
|
658
|
+
LoggerLevel2[LoggerLevel2["NONE"] = 0] = "NONE";
|
|
659
|
+
LoggerLevel2[LoggerLevel2["ERROR"] = 1] = "ERROR";
|
|
660
|
+
LoggerLevel2[LoggerLevel2["WARN"] = 2] = "WARN";
|
|
661
|
+
LoggerLevel2[LoggerLevel2["INFO"] = 3] = "INFO";
|
|
662
|
+
LoggerLevel2[LoggerLevel2["LOG"] = 4] = "LOG";
|
|
663
|
+
LoggerLevel2[LoggerLevel2["ALL"] = 5] = "ALL";
|
|
664
|
+
return LoggerLevel2;
|
|
665
|
+
})(LoggerLevel || {});
|
|
666
|
+
var Logger = class {
|
|
667
|
+
static setLevel(level) {
|
|
668
|
+
this.level_ = level;
|
|
669
|
+
}
|
|
670
|
+
static getLevel() {
|
|
671
|
+
if (isProduction) {
|
|
672
|
+
return 1 /* ERROR */;
|
|
673
|
+
} else {
|
|
674
|
+
return this.level_;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
static error(...args) {
|
|
678
|
+
if (this.getLevel() >= 1 /* ERROR */) {
|
|
679
|
+
console.error(...args);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
static warn(...args) {
|
|
683
|
+
if (this.getLevel() >= 2 /* WARN */) {
|
|
684
|
+
console.warn(...args);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
static info(...args) {
|
|
688
|
+
if (this.getLevel() >= 3 /* INFO */) {
|
|
689
|
+
console.info(...args);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
static log(...args) {
|
|
693
|
+
if (this.getLevel() >= 4 /* LOG */) {
|
|
694
|
+
console.log(...args);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
Logger.level_ = 5 /* ALL */;
|
|
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
|
+
|
|
645
710
|
// src/qs/qs.ts
|
|
646
711
|
function qsSerializeKey(key, parentKey = "") {
|
|
647
712
|
return parentKey ? `${parentKey}[${key}]` : String(key);
|
|
@@ -785,13 +850,13 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
785
850
|
}
|
|
786
851
|
});
|
|
787
852
|
if (rootCategory && item.category === rootCategory.id) {
|
|
788
|
-
const
|
|
789
|
-
const
|
|
790
|
-
const defaultMarketLocale =
|
|
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;
|
|
791
856
|
const title = localize(item.title, defaultMarketLocale);
|
|
792
857
|
const route = {
|
|
793
858
|
id: "/",
|
|
794
|
-
market:
|
|
859
|
+
market: defaultMarket2.id,
|
|
795
860
|
locale: defaultMarketLocale,
|
|
796
861
|
category: item.category,
|
|
797
862
|
page: item.id,
|
|
@@ -897,6 +962,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
897
962
|
})(RedirectReason || {});
|
|
898
963
|
export {
|
|
899
964
|
JsonService,
|
|
965
|
+
Logger,
|
|
966
|
+
LoggerLevel,
|
|
900
967
|
RedirectReason,
|
|
901
968
|
RouteStrategy,
|
|
902
969
|
asCategoryId,
|
|
@@ -907,6 +974,8 @@ export {
|
|
|
907
974
|
cloneItem,
|
|
908
975
|
collectRoutes,
|
|
909
976
|
consoleWarn,
|
|
977
|
+
defaultLocale,
|
|
978
|
+
defaultMarket,
|
|
910
979
|
eachCategorized,
|
|
911
980
|
eachMarketLocale,
|
|
912
981
|
enumToList,
|