@oxyhq/core 1.0.0
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/README.md +50 -0
- package/dist/cjs/AuthManager.js +361 -0
- package/dist/cjs/CrossDomainAuth.js +258 -0
- package/dist/cjs/HttpService.js +618 -0
- package/dist/cjs/OxyServices.base.js +263 -0
- package/dist/cjs/OxyServices.errors.js +22 -0
- package/dist/cjs/OxyServices.js +63 -0
- package/dist/cjs/constants/version.js +16 -0
- package/dist/cjs/crypto/index.js +20 -0
- package/dist/cjs/crypto/keyManager.js +887 -0
- package/dist/cjs/crypto/polyfill.js +64 -0
- package/dist/cjs/crypto/recoveryPhrase.js +169 -0
- package/dist/cjs/crypto/signatureService.js +296 -0
- package/dist/cjs/i18n/index.js +73 -0
- package/dist/cjs/i18n/locales/ar-SA.json +120 -0
- package/dist/cjs/i18n/locales/ca-ES.json +120 -0
- package/dist/cjs/i18n/locales/de-DE.json +120 -0
- package/dist/cjs/i18n/locales/en-US.json +956 -0
- package/dist/cjs/i18n/locales/es-ES.json +944 -0
- package/dist/cjs/i18n/locales/fr-FR.json +120 -0
- package/dist/cjs/i18n/locales/it-IT.json +120 -0
- package/dist/cjs/i18n/locales/ja-JP.json +119 -0
- package/dist/cjs/i18n/locales/ko-KR.json +120 -0
- package/dist/cjs/i18n/locales/locales/ar-SA.json +120 -0
- package/dist/cjs/i18n/locales/locales/ca-ES.json +120 -0
- package/dist/cjs/i18n/locales/locales/de-DE.json +120 -0
- package/dist/cjs/i18n/locales/locales/en-US.json +956 -0
- package/dist/cjs/i18n/locales/locales/es-ES.json +944 -0
- package/dist/cjs/i18n/locales/locales/fr-FR.json +120 -0
- package/dist/cjs/i18n/locales/locales/it-IT.json +120 -0
- package/dist/cjs/i18n/locales/locales/ja-JP.json +119 -0
- package/dist/cjs/i18n/locales/locales/ko-KR.json +120 -0
- package/dist/cjs/i18n/locales/locales/pt-PT.json +120 -0
- package/dist/cjs/i18n/locales/locales/zh-CN.json +120 -0
- package/dist/cjs/i18n/locales/pt-PT.json +120 -0
- package/dist/cjs/i18n/locales/zh-CN.json +120 -0
- package/dist/cjs/index.js +153 -0
- package/dist/cjs/mixins/OxyServices.analytics.js +49 -0
- package/dist/cjs/mixins/OxyServices.assets.js +380 -0
- package/dist/cjs/mixins/OxyServices.auth.js +259 -0
- package/dist/cjs/mixins/OxyServices.developer.js +97 -0
- package/dist/cjs/mixins/OxyServices.devices.js +116 -0
- package/dist/cjs/mixins/OxyServices.features.js +309 -0
- package/dist/cjs/mixins/OxyServices.fedcm.js +435 -0
- package/dist/cjs/mixins/OxyServices.karma.js +108 -0
- package/dist/cjs/mixins/OxyServices.language.js +154 -0
- package/dist/cjs/mixins/OxyServices.location.js +43 -0
- package/dist/cjs/mixins/OxyServices.payment.js +158 -0
- package/dist/cjs/mixins/OxyServices.popup.js +371 -0
- package/dist/cjs/mixins/OxyServices.privacy.js +162 -0
- package/dist/cjs/mixins/OxyServices.redirect.js +345 -0
- package/dist/cjs/mixins/OxyServices.security.js +81 -0
- package/dist/cjs/mixins/OxyServices.user.js +355 -0
- package/dist/cjs/mixins/OxyServices.utility.js +156 -0
- package/dist/cjs/mixins/index.js +79 -0
- package/dist/cjs/mixins/mixinHelpers.js +53 -0
- package/dist/cjs/models/interfaces.js +20 -0
- package/dist/cjs/models/session.js +2 -0
- package/dist/cjs/shared/index.js +70 -0
- package/dist/cjs/shared/utils/colorUtils.js +153 -0
- package/dist/cjs/shared/utils/debugUtils.js +73 -0
- package/dist/cjs/shared/utils/errorUtils.js +183 -0
- package/dist/cjs/shared/utils/index.js +49 -0
- package/dist/cjs/shared/utils/networkUtils.js +183 -0
- package/dist/cjs/shared/utils/themeUtils.js +106 -0
- package/dist/cjs/utils/apiUtils.js +61 -0
- package/dist/cjs/utils/asyncUtils.js +194 -0
- package/dist/cjs/utils/cache.js +226 -0
- package/dist/cjs/utils/deviceManager.js +205 -0
- package/dist/cjs/utils/errorUtils.js +154 -0
- package/dist/cjs/utils/index.js +26 -0
- package/dist/cjs/utils/languageUtils.js +165 -0
- package/dist/cjs/utils/loggerUtils.js +126 -0
- package/dist/cjs/utils/platform.js +144 -0
- package/dist/cjs/utils/requestUtils.js +209 -0
- package/dist/cjs/utils/sessionUtils.js +181 -0
- package/dist/cjs/utils/validationUtils.js +173 -0
- package/dist/esm/AuthManager.js +356 -0
- package/dist/esm/CrossDomainAuth.js +253 -0
- package/dist/esm/HttpService.js +614 -0
- package/dist/esm/OxyServices.base.js +259 -0
- package/dist/esm/OxyServices.errors.js +17 -0
- package/dist/esm/OxyServices.js +59 -0
- package/dist/esm/constants/version.js +13 -0
- package/dist/esm/crypto/index.js +13 -0
- package/dist/esm/crypto/keyManager.js +850 -0
- package/dist/esm/crypto/polyfill.js +61 -0
- package/dist/esm/crypto/recoveryPhrase.js +132 -0
- package/dist/esm/crypto/signatureService.js +259 -0
- package/dist/esm/i18n/index.js +69 -0
- package/dist/esm/i18n/locales/ar-SA.json +120 -0
- package/dist/esm/i18n/locales/ca-ES.json +120 -0
- package/dist/esm/i18n/locales/de-DE.json +120 -0
- package/dist/esm/i18n/locales/en-US.json +956 -0
- package/dist/esm/i18n/locales/es-ES.json +944 -0
- package/dist/esm/i18n/locales/fr-FR.json +120 -0
- package/dist/esm/i18n/locales/it-IT.json +120 -0
- package/dist/esm/i18n/locales/ja-JP.json +119 -0
- package/dist/esm/i18n/locales/ko-KR.json +120 -0
- package/dist/esm/i18n/locales/locales/ar-SA.json +120 -0
- package/dist/esm/i18n/locales/locales/ca-ES.json +120 -0
- package/dist/esm/i18n/locales/locales/de-DE.json +120 -0
- package/dist/esm/i18n/locales/locales/en-US.json +956 -0
- package/dist/esm/i18n/locales/locales/es-ES.json +944 -0
- package/dist/esm/i18n/locales/locales/fr-FR.json +120 -0
- package/dist/esm/i18n/locales/locales/it-IT.json +120 -0
- package/dist/esm/i18n/locales/locales/ja-JP.json +119 -0
- package/dist/esm/i18n/locales/locales/ko-KR.json +120 -0
- package/dist/esm/i18n/locales/locales/pt-PT.json +120 -0
- package/dist/esm/i18n/locales/locales/zh-CN.json +120 -0
- package/dist/esm/i18n/locales/pt-PT.json +120 -0
- package/dist/esm/i18n/locales/zh-CN.json +120 -0
- package/dist/esm/index.js +55 -0
- package/dist/esm/mixins/OxyServices.analytics.js +46 -0
- package/dist/esm/mixins/OxyServices.assets.js +377 -0
- package/dist/esm/mixins/OxyServices.auth.js +256 -0
- package/dist/esm/mixins/OxyServices.developer.js +94 -0
- package/dist/esm/mixins/OxyServices.devices.js +113 -0
- package/dist/esm/mixins/OxyServices.features.js +306 -0
- package/dist/esm/mixins/OxyServices.fedcm.js +433 -0
- package/dist/esm/mixins/OxyServices.karma.js +105 -0
- package/dist/esm/mixins/OxyServices.language.js +118 -0
- package/dist/esm/mixins/OxyServices.location.js +40 -0
- package/dist/esm/mixins/OxyServices.payment.js +155 -0
- package/dist/esm/mixins/OxyServices.popup.js +369 -0
- package/dist/esm/mixins/OxyServices.privacy.js +159 -0
- package/dist/esm/mixins/OxyServices.redirect.js +343 -0
- package/dist/esm/mixins/OxyServices.security.js +78 -0
- package/dist/esm/mixins/OxyServices.user.js +352 -0
- package/dist/esm/mixins/OxyServices.utility.js +153 -0
- package/dist/esm/mixins/index.js +76 -0
- package/dist/esm/mixins/mixinHelpers.js +48 -0
- package/dist/esm/models/interfaces.js +17 -0
- package/dist/esm/models/session.js +1 -0
- package/dist/esm/shared/index.js +31 -0
- package/dist/esm/shared/utils/colorUtils.js +143 -0
- package/dist/esm/shared/utils/debugUtils.js +65 -0
- package/dist/esm/shared/utils/errorUtils.js +170 -0
- package/dist/esm/shared/utils/index.js +15 -0
- package/dist/esm/shared/utils/networkUtils.js +173 -0
- package/dist/esm/shared/utils/themeUtils.js +98 -0
- package/dist/esm/utils/apiUtils.js +55 -0
- package/dist/esm/utils/asyncUtils.js +179 -0
- package/dist/esm/utils/cache.js +218 -0
- package/dist/esm/utils/deviceManager.js +168 -0
- package/dist/esm/utils/errorUtils.js +146 -0
- package/dist/esm/utils/index.js +7 -0
- package/dist/esm/utils/languageUtils.js +158 -0
- package/dist/esm/utils/loggerUtils.js +115 -0
- package/dist/esm/utils/platform.js +102 -0
- package/dist/esm/utils/requestUtils.js +203 -0
- package/dist/esm/utils/sessionUtils.js +171 -0
- package/dist/esm/utils/validationUtils.js +153 -0
- package/dist/types/AuthManager.d.ts +143 -0
- package/dist/types/CrossDomainAuth.d.ts +160 -0
- package/dist/types/HttpService.d.ts +163 -0
- package/dist/types/OxyServices.base.d.ts +126 -0
- package/dist/types/OxyServices.d.ts +81 -0
- package/dist/types/OxyServices.errors.d.ts +11 -0
- package/dist/types/constants/version.d.ts +13 -0
- package/dist/types/crypto/index.d.ts +11 -0
- package/dist/types/crypto/keyManager.d.ts +189 -0
- package/dist/types/crypto/polyfill.d.ts +11 -0
- package/dist/types/crypto/recoveryPhrase.d.ts +58 -0
- package/dist/types/crypto/signatureService.d.ts +86 -0
- package/dist/types/i18n/index.d.ts +3 -0
- package/dist/types/index.d.ts +50 -0
- package/dist/types/mixins/OxyServices.analytics.d.ts +66 -0
- package/dist/types/mixins/OxyServices.assets.d.ts +135 -0
- package/dist/types/mixins/OxyServices.auth.d.ts +186 -0
- package/dist/types/mixins/OxyServices.developer.d.ts +99 -0
- package/dist/types/mixins/OxyServices.devices.d.ts +96 -0
- package/dist/types/mixins/OxyServices.features.d.ts +228 -0
- package/dist/types/mixins/OxyServices.fedcm.d.ts +200 -0
- package/dist/types/mixins/OxyServices.karma.d.ts +85 -0
- package/dist/types/mixins/OxyServices.language.d.ts +81 -0
- package/dist/types/mixins/OxyServices.location.d.ts +64 -0
- package/dist/types/mixins/OxyServices.payment.d.ts +111 -0
- package/dist/types/mixins/OxyServices.popup.d.ts +205 -0
- package/dist/types/mixins/OxyServices.privacy.d.ts +122 -0
- package/dist/types/mixins/OxyServices.redirect.d.ts +245 -0
- package/dist/types/mixins/OxyServices.security.d.ts +78 -0
- package/dist/types/mixins/OxyServices.user.d.ts +182 -0
- package/dist/types/mixins/OxyServices.utility.d.ts +93 -0
- package/dist/types/mixins/index.d.ts +30 -0
- package/dist/types/mixins/mixinHelpers.d.ts +31 -0
- package/dist/types/models/interfaces.d.ts +415 -0
- package/dist/types/models/session.d.ts +27 -0
- package/dist/types/shared/index.d.ts +28 -0
- package/dist/types/shared/utils/colorUtils.d.ts +104 -0
- package/dist/types/shared/utils/debugUtils.d.ts +48 -0
- package/dist/types/shared/utils/errorUtils.d.ts +97 -0
- package/dist/types/shared/utils/index.d.ts +13 -0
- package/dist/types/shared/utils/networkUtils.d.ts +139 -0
- package/dist/types/shared/utils/themeUtils.d.ts +90 -0
- package/dist/types/utils/apiUtils.d.ts +53 -0
- package/dist/types/utils/asyncUtils.d.ts +58 -0
- package/dist/types/utils/cache.d.ts +127 -0
- package/dist/types/utils/deviceManager.d.ts +65 -0
- package/dist/types/utils/errorUtils.d.ts +46 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/languageUtils.d.ts +37 -0
- package/dist/types/utils/loggerUtils.d.ts +48 -0
- package/dist/types/utils/platform.d.ts +40 -0
- package/dist/types/utils/requestUtils.d.ts +123 -0
- package/dist/types/utils/sessionUtils.d.ts +54 -0
- package/dist/types/utils/validationUtils.d.ts +85 -0
- package/package.json +84 -0
- package/src/AuthManager.ts +436 -0
- package/src/CrossDomainAuth.ts +307 -0
- package/src/HttpService.ts +752 -0
- package/src/OxyServices.base.ts +334 -0
- package/src/OxyServices.errors.ts +26 -0
- package/src/OxyServices.ts +129 -0
- package/src/constants/version.ts +15 -0
- package/src/crypto/index.ts +25 -0
- package/src/crypto/keyManager.ts +962 -0
- package/src/crypto/polyfill.ts +70 -0
- package/src/crypto/recoveryPhrase.ts +166 -0
- package/src/crypto/signatureService.ts +323 -0
- package/src/i18n/index.ts +75 -0
- package/src/i18n/locales/ar-SA.json +120 -0
- package/src/i18n/locales/ca-ES.json +120 -0
- package/src/i18n/locales/de-DE.json +120 -0
- package/src/i18n/locales/en-US.json +956 -0
- package/src/i18n/locales/es-ES.json +944 -0
- package/src/i18n/locales/fr-FR.json +120 -0
- package/src/i18n/locales/it-IT.json +120 -0
- package/src/i18n/locales/ja-JP.json +119 -0
- package/src/i18n/locales/ko-KR.json +120 -0
- package/src/i18n/locales/pt-PT.json +120 -0
- package/src/i18n/locales/zh-CN.json +120 -0
- package/src/index.ts +153 -0
- package/src/mixins/OxyServices.analytics.ts +53 -0
- package/src/mixins/OxyServices.assets.ts +412 -0
- package/src/mixins/OxyServices.auth.ts +358 -0
- package/src/mixins/OxyServices.developer.ts +114 -0
- package/src/mixins/OxyServices.devices.ts +119 -0
- package/src/mixins/OxyServices.features.ts +428 -0
- package/src/mixins/OxyServices.fedcm.ts +494 -0
- package/src/mixins/OxyServices.karma.ts +111 -0
- package/src/mixins/OxyServices.language.ts +127 -0
- package/src/mixins/OxyServices.location.ts +46 -0
- package/src/mixins/OxyServices.payment.ts +163 -0
- package/src/mixins/OxyServices.popup.ts +443 -0
- package/src/mixins/OxyServices.privacy.ts +182 -0
- package/src/mixins/OxyServices.redirect.ts +397 -0
- package/src/mixins/OxyServices.security.ts +103 -0
- package/src/mixins/OxyServices.user.ts +392 -0
- package/src/mixins/OxyServices.utility.ts +191 -0
- package/src/mixins/index.ts +91 -0
- package/src/mixins/mixinHelpers.ts +69 -0
- package/src/models/interfaces.ts +511 -0
- package/src/models/session.ts +30 -0
- package/src/shared/index.ts +82 -0
- package/src/shared/utils/colorUtils.ts +155 -0
- package/src/shared/utils/debugUtils.ts +73 -0
- package/src/shared/utils/errorUtils.ts +181 -0
- package/src/shared/utils/index.ts +59 -0
- package/src/shared/utils/networkUtils.ts +248 -0
- package/src/shared/utils/themeUtils.ts +115 -0
- package/src/types/bip39.d.ts +32 -0
- package/src/types/buffer.d.ts +97 -0
- package/src/types/color.d.ts +20 -0
- package/src/types/elliptic.d.ts +62 -0
- package/src/utils/apiUtils.ts +88 -0
- package/src/utils/asyncUtils.ts +252 -0
- package/src/utils/cache.ts +264 -0
- package/src/utils/deviceManager.ts +198 -0
- package/src/utils/errorUtils.ts +216 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/languageUtils.ts +174 -0
- package/src/utils/loggerUtils.ts +153 -0
- package/src/utils/platform.ts +117 -0
- package/src/utils/requestUtils.ts +237 -0
- package/src/utils/sessionUtils.ts +206 -0
- package/src/utils/validationUtils.ts +174 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language utilities for OxyServices
|
|
3
|
+
* Provides access to supported languages and language metadata
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface LanguageMetadata {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
nativeName: string;
|
|
10
|
+
flag: string;
|
|
11
|
+
icon: string;
|
|
12
|
+
color: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Supported languages with their metadata
|
|
16
|
+
export const SUPPORTED_LANGUAGES: LanguageMetadata[] = [
|
|
17
|
+
{
|
|
18
|
+
id: 'en-US',
|
|
19
|
+
name: 'English',
|
|
20
|
+
nativeName: 'English',
|
|
21
|
+
flag: '🇺🇸',
|
|
22
|
+
icon: 'translate',
|
|
23
|
+
color: '#007AFF',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 'es-ES',
|
|
27
|
+
name: 'Spanish',
|
|
28
|
+
nativeName: 'Español',
|
|
29
|
+
flag: '🇪🇸',
|
|
30
|
+
icon: 'translate',
|
|
31
|
+
color: '#FF3B30',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'ca-ES',
|
|
35
|
+
name: 'Catalan',
|
|
36
|
+
nativeName: 'Català',
|
|
37
|
+
flag: '🇪🇸',
|
|
38
|
+
icon: 'translate',
|
|
39
|
+
color: '#0CA678',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'fr-FR',
|
|
43
|
+
name: 'French',
|
|
44
|
+
nativeName: 'Français',
|
|
45
|
+
flag: '🇫🇷',
|
|
46
|
+
icon: 'translate',
|
|
47
|
+
color: '#5856D6',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'de-DE',
|
|
51
|
+
name: 'German',
|
|
52
|
+
nativeName: 'Deutsch',
|
|
53
|
+
flag: '🇩🇪',
|
|
54
|
+
icon: 'translate',
|
|
55
|
+
color: '#FF9500',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'it-IT',
|
|
59
|
+
name: 'Italian',
|
|
60
|
+
nativeName: 'Italiano',
|
|
61
|
+
flag: '🇮🇹',
|
|
62
|
+
icon: 'translate',
|
|
63
|
+
color: '#34C759',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'pt-PT',
|
|
67
|
+
name: 'Portuguese',
|
|
68
|
+
nativeName: 'Português',
|
|
69
|
+
flag: '🇵🇹',
|
|
70
|
+
icon: 'translate',
|
|
71
|
+
color: '#AF52DE',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'ja-JP',
|
|
75
|
+
name: 'Japanese',
|
|
76
|
+
nativeName: '日本語',
|
|
77
|
+
flag: '🇯🇵',
|
|
78
|
+
icon: 'translate',
|
|
79
|
+
color: '#FF2D92',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: 'ko-KR',
|
|
83
|
+
name: 'Korean',
|
|
84
|
+
nativeName: '한국어',
|
|
85
|
+
flag: '🇰🇷',
|
|
86
|
+
icon: 'translate',
|
|
87
|
+
color: '#32D74B',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: 'zh-CN',
|
|
91
|
+
name: 'Chinese',
|
|
92
|
+
nativeName: '中文',
|
|
93
|
+
flag: '🇨🇳',
|
|
94
|
+
icon: 'translate',
|
|
95
|
+
color: '#FF9F0A',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: 'ar-SA',
|
|
99
|
+
name: 'Arabic',
|
|
100
|
+
nativeName: 'العربية',
|
|
101
|
+
flag: '🇸🇦',
|
|
102
|
+
icon: 'translate',
|
|
103
|
+
color: '#30B0C7',
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
const FALLBACK_LANGUAGE = 'en-US';
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get language metadata by language code
|
|
111
|
+
* @param languageCode - BCP-47 language code (e.g., 'en-US', 'es-ES')
|
|
112
|
+
* @returns Language metadata or null if not found
|
|
113
|
+
*/
|
|
114
|
+
export function getLanguageMetadata(languageCode: string | null | undefined): LanguageMetadata | null {
|
|
115
|
+
if (!languageCode) return null;
|
|
116
|
+
|
|
117
|
+
// Direct match
|
|
118
|
+
const exactMatch = SUPPORTED_LANGUAGES.find(lang => lang.id === languageCode);
|
|
119
|
+
if (exactMatch) return exactMatch;
|
|
120
|
+
|
|
121
|
+
// Try to match base language code (e.g., 'en' matches 'en-US')
|
|
122
|
+
const baseCode = languageCode.split('-')[0];
|
|
123
|
+
const baseMatch = SUPPORTED_LANGUAGES.find(lang => lang.id.startsWith(baseCode + '-'));
|
|
124
|
+
if (baseMatch) return baseMatch;
|
|
125
|
+
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Get language name by language code
|
|
131
|
+
* @param languageCode - BCP-47 language code (e.g., 'en-US', 'es-ES')
|
|
132
|
+
* @returns Language name (e.g., 'English') or the code if not found
|
|
133
|
+
*/
|
|
134
|
+
export function getLanguageName(languageCode: string | null | undefined): string {
|
|
135
|
+
const metadata = getLanguageMetadata(languageCode);
|
|
136
|
+
return metadata?.name || languageCode || FALLBACK_LANGUAGE;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Get native language name by language code
|
|
141
|
+
* @param languageCode - BCP-47 language code (e.g., 'en-US', 'es-ES')
|
|
142
|
+
* @returns Native language name (e.g., 'Español') or the code if not found
|
|
143
|
+
*/
|
|
144
|
+
export function getNativeLanguageName(languageCode: string | null | undefined): string {
|
|
145
|
+
const metadata = getLanguageMetadata(languageCode);
|
|
146
|
+
return metadata?.nativeName || languageCode || FALLBACK_LANGUAGE;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Normalize language code to BCP-47 format
|
|
151
|
+
* @param lang - Language code (may be short like 'en' or full like 'en-US')
|
|
152
|
+
* @returns Normalized BCP-47 language code
|
|
153
|
+
*/
|
|
154
|
+
export function normalizeLanguageCode(lang?: string | null): string {
|
|
155
|
+
if (!lang) return FALLBACK_LANGUAGE;
|
|
156
|
+
if (lang.includes('-')) return lang;
|
|
157
|
+
|
|
158
|
+
const map: Record<string, string> = {
|
|
159
|
+
en: 'en-US',
|
|
160
|
+
es: 'es-ES',
|
|
161
|
+
ca: 'ca-ES',
|
|
162
|
+
fr: 'fr-FR',
|
|
163
|
+
de: 'de-DE',
|
|
164
|
+
it: 'it-IT',
|
|
165
|
+
pt: 'pt-PT',
|
|
166
|
+
ja: 'ja-JP',
|
|
167
|
+
ko: 'ko-KR',
|
|
168
|
+
zh: 'zh-CN',
|
|
169
|
+
ar: 'ar-SA',
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return map[lang] || lang;
|
|
173
|
+
}
|
|
174
|
+
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized logging utilities for consistent logging across the application
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export enum LogLevel {
|
|
6
|
+
DEBUG = 0,
|
|
7
|
+
INFO = 1,
|
|
8
|
+
WARN = 2,
|
|
9
|
+
ERROR = 3,
|
|
10
|
+
NONE = 4
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface LogContext {
|
|
14
|
+
component?: string;
|
|
15
|
+
method?: string;
|
|
16
|
+
userId?: string;
|
|
17
|
+
sessionId?: string;
|
|
18
|
+
requestId?: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class Logger {
|
|
23
|
+
private level: LogLevel = LogLevel.INFO;
|
|
24
|
+
private isDevelopment: boolean = process.env.NODE_ENV === 'development';
|
|
25
|
+
|
|
26
|
+
setLevel(level: LogLevel): void {
|
|
27
|
+
this.level = level;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private shouldLog(level: LogLevel): boolean {
|
|
31
|
+
return level >= this.level;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private formatMessage(level: string, message: string, context?: LogContext): string {
|
|
35
|
+
const timestamp = new Date().toISOString();
|
|
36
|
+
const contextStr = context ? ` [${Object.entries(context).map(([k, v]) => `${k}:${v}`).join(', ')}]` : '';
|
|
37
|
+
return `[${timestamp}] ${level}${contextStr}: ${message}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
debug(message: string, context?: LogContext, ...args: unknown[]): void {
|
|
41
|
+
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
42
|
+
const formattedMessage = this.formatMessage('DEBUG', message, context);
|
|
43
|
+
if (this.isDevelopment) {
|
|
44
|
+
console.log(formattedMessage, ...args);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
info(message: string, context?: LogContext, ...args: unknown[]): void {
|
|
50
|
+
if (this.shouldLog(LogLevel.INFO)) {
|
|
51
|
+
const formattedMessage = this.formatMessage('INFO', message, context);
|
|
52
|
+
console.log(formattedMessage, ...args);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
warn(message: string, context?: LogContext, ...args: unknown[]): void {
|
|
57
|
+
if (this.shouldLog(LogLevel.WARN)) {
|
|
58
|
+
const formattedMessage = this.formatMessage('WARN', message, context);
|
|
59
|
+
console.warn(formattedMessage, ...args);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
error(message: string, error?: Error | unknown, context?: LogContext, ...args: unknown[]): void {
|
|
64
|
+
if (this.shouldLog(LogLevel.ERROR)) {
|
|
65
|
+
const formattedMessage = this.formatMessage('ERROR', message, context);
|
|
66
|
+
if (error) {
|
|
67
|
+
console.error(formattedMessage, error, ...args);
|
|
68
|
+
} else {
|
|
69
|
+
console.error(formattedMessage, ...args);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Specialized logging methods for common patterns
|
|
75
|
+
auth(message: string, context?: LogContext, ...args: unknown[]): void {
|
|
76
|
+
this.info(`🔐 ${message}`, { ...context, category: 'auth' }, ...args);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
api(message: string, context?: LogContext, ...args: unknown[]): void {
|
|
80
|
+
this.info(`🌐 ${message}`, { ...context, category: 'api' }, ...args);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
session(message: string, context?: LogContext, ...args: unknown[]): void {
|
|
84
|
+
this.info(`📱 ${message}`, { ...context, category: 'session' }, ...args);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
user(message: string, context?: LogContext, ...args: unknown[]): void {
|
|
88
|
+
this.info(`👤 ${message}`, { ...context, category: 'user' }, ...args);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
device(message: string, context?: LogContext, ...args: unknown[]): void {
|
|
92
|
+
this.info(`📱 ${message}`, { ...context, category: 'device' }, ...args);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
payment(message: string, context?: LogContext, ...args: unknown[]): void {
|
|
96
|
+
this.info(`💳 ${message}`, { ...context, category: 'payment' }, ...args);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Performance logging
|
|
100
|
+
performance(operation: string, duration: number, context?: LogContext): void {
|
|
101
|
+
const level = duration > 1000 ? LogLevel.WARN : LogLevel.INFO;
|
|
102
|
+
const message = `⏱️ ${operation} completed in ${duration}ms`;
|
|
103
|
+
if (level === LogLevel.WARN) {
|
|
104
|
+
this.warn(message, { ...context, category: 'performance', duration });
|
|
105
|
+
} else {
|
|
106
|
+
this.info(message, { ...context, category: 'performance', duration });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Error logging with stack trace
|
|
111
|
+
errorWithStack(message: string, error: Error, context?: LogContext): void {
|
|
112
|
+
this.error(message, error, { ...context, stack: error.stack });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Group related log messages
|
|
116
|
+
group(label: string, fn: () => void): void {
|
|
117
|
+
if (this.isDevelopment && this.shouldLog(LogLevel.DEBUG)) {
|
|
118
|
+
console.group(label);
|
|
119
|
+
fn();
|
|
120
|
+
console.groupEnd();
|
|
121
|
+
} else {
|
|
122
|
+
fn();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Create singleton instance
|
|
128
|
+
export const logger = new Logger();
|
|
129
|
+
|
|
130
|
+
// Convenience functions for common logging patterns
|
|
131
|
+
export const logAuth = (message: string, context?: LogContext, ...args: unknown[]) =>
|
|
132
|
+
logger.auth(message, context, ...args);
|
|
133
|
+
|
|
134
|
+
export const logApi = (message: string, context?: LogContext, ...args: unknown[]) =>
|
|
135
|
+
logger.api(message, context, ...args);
|
|
136
|
+
|
|
137
|
+
export const logSession = (message: string, context?: LogContext, ...args: unknown[]) =>
|
|
138
|
+
logger.session(message, context, ...args);
|
|
139
|
+
|
|
140
|
+
export const logUser = (message: string, context?: LogContext, ...args: unknown[]) =>
|
|
141
|
+
logger.user(message, context, ...args);
|
|
142
|
+
|
|
143
|
+
export const logDevice = (message: string, context?: LogContext, ...args: unknown[]) =>
|
|
144
|
+
logger.device(message, context, ...args);
|
|
145
|
+
|
|
146
|
+
export const logPayment = (message: string, context?: LogContext, ...args: unknown[]) =>
|
|
147
|
+
logger.payment(message, context, ...args);
|
|
148
|
+
|
|
149
|
+
export const logError = (message: string, error?: Error | unknown, context?: LogContext, ...args: unknown[]) =>
|
|
150
|
+
logger.error(message, error, context, ...args);
|
|
151
|
+
|
|
152
|
+
export const logPerformance = (operation: string, duration: number, context?: LogContext) =>
|
|
153
|
+
logger.performance(operation, duration, context);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform Detection Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides platform detection WITHOUT importing from 'react-native'.
|
|
5
|
+
* This allows core modules to be used in web/Node.js environments
|
|
6
|
+
* without bundlers failing on react-native imports.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type PlatformOS = 'ios' | 'android' | 'web' | 'windows' | 'macos' | 'unknown';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Detect the current platform without importing react-native
|
|
13
|
+
*
|
|
14
|
+
* Detection order:
|
|
15
|
+
* 1. Check for React Native's Platform object on globalThis (set by RN runtime)
|
|
16
|
+
* 2. Check for Node.js environment
|
|
17
|
+
* 3. Check for browser environment
|
|
18
|
+
* 4. Fall back to 'unknown'
|
|
19
|
+
*/
|
|
20
|
+
function detectPlatform(): PlatformOS {
|
|
21
|
+
// Check if React Native Platform is available globally (set by RN runtime)
|
|
22
|
+
// This avoids static imports while still detecting RN environment
|
|
23
|
+
const rnPlatform = (globalThis as any).__REACT_NATIVE_PLATFORM__;
|
|
24
|
+
if (rnPlatform) {
|
|
25
|
+
return rnPlatform as PlatformOS;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Check navigator.product for React Native
|
|
29
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
30
|
+
// We're in React Native but Platform wasn't set globally
|
|
31
|
+
// Try to get OS from userAgent or default to 'unknown'
|
|
32
|
+
return 'unknown';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Check for Node.js environment
|
|
36
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
37
|
+
return 'web'; // Treat Node.js as 'web' for compatibility (no native features)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Check for browser/web environment
|
|
41
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
42
|
+
return 'web';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return 'unknown';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Cache the platform detection result
|
|
49
|
+
let cachedPlatform: PlatformOS | null = null;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get the current platform OS
|
|
53
|
+
* Safe to call from any environment (web, Node.js, React Native)
|
|
54
|
+
*/
|
|
55
|
+
export function getPlatformOS(): PlatformOS {
|
|
56
|
+
if (cachedPlatform === null) {
|
|
57
|
+
cachedPlatform = detectPlatform();
|
|
58
|
+
}
|
|
59
|
+
return cachedPlatform;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Check if running on web platform (browser or Node.js)
|
|
64
|
+
*/
|
|
65
|
+
export function isWeb(): boolean {
|
|
66
|
+
return getPlatformOS() === 'web';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Check if running in a native app (iOS or Android)
|
|
71
|
+
*/
|
|
72
|
+
export function isNative(): boolean {
|
|
73
|
+
const os = getPlatformOS();
|
|
74
|
+
return os === 'ios' || os === 'android';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Check if running on iOS
|
|
79
|
+
*/
|
|
80
|
+
export function isIOS(): boolean {
|
|
81
|
+
return getPlatformOS() === 'ios';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Check if running on Android
|
|
86
|
+
*/
|
|
87
|
+
export function isAndroid(): boolean {
|
|
88
|
+
return getPlatformOS() === 'android';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Set the platform OS explicitly
|
|
93
|
+
* Called by React Native entry point to register the platform
|
|
94
|
+
* This allows lazy detection in environments where react-native is available
|
|
95
|
+
*/
|
|
96
|
+
export function setPlatformOS(os: PlatformOS): void {
|
|
97
|
+
cachedPlatform = os;
|
|
98
|
+
(globalThis as any).__REACT_NATIVE_PLATFORM__ = os;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Try to initialize platform from react-native if available
|
|
103
|
+
* This is called lazily when needed, avoiding top-level imports
|
|
104
|
+
*/
|
|
105
|
+
export async function initPlatformFromReactNative(): Promise<void> {
|
|
106
|
+
if (cachedPlatform !== null && cachedPlatform !== 'unknown') {
|
|
107
|
+
return; // Already initialized
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
// Dynamic import to avoid bundler issues
|
|
112
|
+
const { Platform } = await import('react-native');
|
|
113
|
+
setPlatformOS(Platform.OS as PlatformOS);
|
|
114
|
+
} catch {
|
|
115
|
+
// react-native not available, use detected platform
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request utilities for HTTP clients
|
|
3
|
+
*
|
|
4
|
+
* Provides reusable components for request deduplication, queuing, and logging
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Request deduplication - prevents duplicate concurrent requests
|
|
9
|
+
*
|
|
10
|
+
* When multiple requests with the same key are made simultaneously,
|
|
11
|
+
* only one request is executed and all callers receive the same result.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const deduplicator = new RequestDeduplicator();
|
|
16
|
+
*
|
|
17
|
+
* // Multiple calls with same key will share the same promise
|
|
18
|
+
* const promise1 = deduplicator.deduplicate('user-123', () => fetchUser('123'));
|
|
19
|
+
* const promise2 = deduplicator.deduplicate('user-123', () => fetchUser('123'));
|
|
20
|
+
* // promise1 === promise2, only one API call is made
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class RequestDeduplicator {
|
|
24
|
+
private pendingRequests = new Map<string, Promise<any>>();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Deduplicate a request by key
|
|
28
|
+
* @param key Unique key for the request
|
|
29
|
+
* @param requestFn Function that returns a promise
|
|
30
|
+
* @returns Promise that will be shared if key already exists
|
|
31
|
+
*/
|
|
32
|
+
async deduplicate<T>(
|
|
33
|
+
key: string,
|
|
34
|
+
requestFn: () => Promise<T>
|
|
35
|
+
): Promise<T> {
|
|
36
|
+
const existing = this.pendingRequests.get(key);
|
|
37
|
+
if (existing) {
|
|
38
|
+
return existing;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const promise = requestFn()
|
|
42
|
+
.finally(() => {
|
|
43
|
+
this.pendingRequests.delete(key);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.pendingRequests.set(key, promise);
|
|
47
|
+
return promise;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Clear all pending requests
|
|
52
|
+
*/
|
|
53
|
+
clear(): void {
|
|
54
|
+
this.pendingRequests.clear();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get number of pending requests
|
|
59
|
+
*/
|
|
60
|
+
size(): number {
|
|
61
|
+
return this.pendingRequests.size;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Request queue with concurrency control
|
|
67
|
+
*
|
|
68
|
+
* Limits the number of concurrent requests and queues excess requests.
|
|
69
|
+
* Useful for rate limiting and preventing request flooding.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const queue = new RequestQueue(5, 100); // Max 5 concurrent, queue up to 100
|
|
74
|
+
*
|
|
75
|
+
* // All requests will be queued and processed with max 5 concurrent
|
|
76
|
+
* await queue.enqueue(() => fetchUser('1'));
|
|
77
|
+
* await queue.enqueue(() => fetchUser('2'));
|
|
78
|
+
* // ...
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export class RequestQueue {
|
|
82
|
+
private queue: Array<() => Promise<any>> = [];
|
|
83
|
+
private running = 0;
|
|
84
|
+
private maxConcurrent: number;
|
|
85
|
+
private maxQueueSize: number;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Create a new request queue
|
|
89
|
+
* @param maxConcurrent Maximum number of concurrent requests (default: 10)
|
|
90
|
+
* @param maxQueueSize Maximum queue size (default: 100)
|
|
91
|
+
*/
|
|
92
|
+
constructor(maxConcurrent: number = 10, maxQueueSize: number = 100) {
|
|
93
|
+
this.maxConcurrent = maxConcurrent;
|
|
94
|
+
this.maxQueueSize = maxQueueSize;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Enqueue a request
|
|
99
|
+
* @param requestFn Function that returns a promise
|
|
100
|
+
* @returns Promise that resolves when request completes
|
|
101
|
+
*/
|
|
102
|
+
async enqueue<T>(requestFn: () => Promise<T>): Promise<T> {
|
|
103
|
+
if (this.queue.length >= this.maxQueueSize) {
|
|
104
|
+
throw new Error('Request queue is full');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return new Promise<T>((resolve, reject) => {
|
|
108
|
+
this.queue.push(async () => {
|
|
109
|
+
try {
|
|
110
|
+
const result = await requestFn();
|
|
111
|
+
resolve(result);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
reject(error);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
this.process();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Process queued requests
|
|
123
|
+
*/
|
|
124
|
+
private async process(): Promise<void> {
|
|
125
|
+
if (this.running >= this.maxConcurrent || this.queue.length === 0) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.running++;
|
|
130
|
+
const requestFn = this.queue.shift();
|
|
131
|
+
if (requestFn) {
|
|
132
|
+
try {
|
|
133
|
+
await requestFn();
|
|
134
|
+
} finally {
|
|
135
|
+
this.running--;
|
|
136
|
+
this.process();
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
this.running--;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Clear all queued requests
|
|
145
|
+
*/
|
|
146
|
+
clear(): void {
|
|
147
|
+
this.queue = [];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get queue size
|
|
152
|
+
*/
|
|
153
|
+
size(): number {
|
|
154
|
+
return this.queue.length;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Get number of currently running requests
|
|
159
|
+
*/
|
|
160
|
+
runningCount(): number {
|
|
161
|
+
return this.running;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Log level type for SimpleLogger */
|
|
166
|
+
export type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Simple logger with level support
|
|
170
|
+
*
|
|
171
|
+
* Lightweight logger for HTTP clients and utilities.
|
|
172
|
+
* For more advanced logging, use loggerUtils.ts
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const logger = new SimpleLogger(true, 'debug');
|
|
177
|
+
* logger.debug('Debug message');
|
|
178
|
+
* logger.info('Info message');
|
|
179
|
+
* logger.error('Error message');
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export class SimpleLogger {
|
|
183
|
+
private enabled: boolean;
|
|
184
|
+
private level: LogLevel;
|
|
185
|
+
private prefix: string;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Create a new simple logger
|
|
189
|
+
* @param enabled Whether logging is enabled
|
|
190
|
+
* @param level Minimum log level
|
|
191
|
+
* @param prefix Prefix for log messages (default: '')
|
|
192
|
+
*/
|
|
193
|
+
constructor(
|
|
194
|
+
enabled: boolean = false,
|
|
195
|
+
level: LogLevel = 'error',
|
|
196
|
+
prefix: string = ''
|
|
197
|
+
) {
|
|
198
|
+
this.enabled = enabled;
|
|
199
|
+
this.level = level;
|
|
200
|
+
this.prefix = prefix;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private shouldLog(level: LogLevel): boolean {
|
|
204
|
+
if (!this.enabled || this.level === 'none') return false;
|
|
205
|
+
const levels: LogLevel[] = ['none', 'error', 'warn', 'info', 'debug'];
|
|
206
|
+
return levels.indexOf(level) <= levels.indexOf(this.level);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private formatMessage(...args: any[]): any[] {
|
|
210
|
+
return this.prefix ? [`[${this.prefix}]`, ...args] : args;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
error(...args: any[]): void {
|
|
214
|
+
if (this.shouldLog('error')) {
|
|
215
|
+
console.error(...this.formatMessage(...args));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
warn(...args: any[]): void {
|
|
220
|
+
if (this.shouldLog('warn')) {
|
|
221
|
+
console.warn(...this.formatMessage(...args));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
info(...args: any[]): void {
|
|
226
|
+
if (this.shouldLog('info')) {
|
|
227
|
+
console.info(...this.formatMessage(...args));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
debug(...args: any[]): void {
|
|
232
|
+
if (this.shouldLog('debug')) {
|
|
233
|
+
console.log(...this.formatMessage(...args));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|