@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,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized cache utility with TTL support
|
|
3
|
+
*
|
|
4
|
+
* This is a production-ready cache implementation used across the codebase
|
|
5
|
+
* for consistent caching behavior and performance optimization.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Cache entry with expiration tracking
|
|
10
|
+
*/
|
|
11
|
+
interface CacheEntry<T> {
|
|
12
|
+
data: T;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
expiresAt: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Cache statistics
|
|
19
|
+
*/
|
|
20
|
+
export interface CacheStats {
|
|
21
|
+
size: number;
|
|
22
|
+
hits: number;
|
|
23
|
+
misses: number;
|
|
24
|
+
hitRate: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* TTL-based cache implementation
|
|
29
|
+
*
|
|
30
|
+
* Features:
|
|
31
|
+
* - Automatic expiration based on TTL
|
|
32
|
+
* - Manual cleanup of expired entries
|
|
33
|
+
* - Statistics tracking (hits, misses, hit rate)
|
|
34
|
+
* - Type-safe generic interface
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const cache = new TTLCache<string>(5 * 60 * 1000); // 5 minutes
|
|
39
|
+
*
|
|
40
|
+
* // Set with default TTL
|
|
41
|
+
* cache.set('key', 'value');
|
|
42
|
+
*
|
|
43
|
+
* // Set with custom TTL
|
|
44
|
+
* cache.set('key', 'value', 10 * 60 * 1000); // 10 minutes
|
|
45
|
+
*
|
|
46
|
+
* // Get value
|
|
47
|
+
* const value = cache.get('key');
|
|
48
|
+
*
|
|
49
|
+
* // Get statistics
|
|
50
|
+
* const stats = cache.getStats();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export class TTLCache<T> {
|
|
54
|
+
private cache = new Map<string, CacheEntry<T>>();
|
|
55
|
+
private defaultTTL: number;
|
|
56
|
+
private hits = 0;
|
|
57
|
+
private misses = 0;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create a new TTL cache
|
|
61
|
+
* @param defaultTTL Default TTL in milliseconds (default: 5 minutes)
|
|
62
|
+
*/
|
|
63
|
+
constructor(defaultTTL: number = 5 * 60 * 1000) {
|
|
64
|
+
this.defaultTTL = defaultTTL;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get a value from cache
|
|
69
|
+
* @param key Cache key
|
|
70
|
+
* @returns Cached value or null if not found or expired
|
|
71
|
+
*/
|
|
72
|
+
get(key: string): T | null {
|
|
73
|
+
const entry = this.cache.get(key);
|
|
74
|
+
if (!entry) {
|
|
75
|
+
this.misses++;
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const now = Date.now();
|
|
80
|
+
if (now > entry.expiresAt) {
|
|
81
|
+
this.cache.delete(key);
|
|
82
|
+
this.misses++;
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.hits++;
|
|
87
|
+
return entry.data;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Set a value in cache
|
|
92
|
+
* @param key Cache key
|
|
93
|
+
* @param data Data to cache
|
|
94
|
+
* @param ttl Optional TTL override (uses default if not provided)
|
|
95
|
+
*/
|
|
96
|
+
set(key: string, data: T, ttl?: number): void {
|
|
97
|
+
const now = Date.now();
|
|
98
|
+
const expiresAt = now + (ttl || this.defaultTTL);
|
|
99
|
+
this.cache.set(key, { data, timestamp: now, expiresAt });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Delete a specific cache entry
|
|
104
|
+
* @param key Cache key
|
|
105
|
+
* @returns true if entry was deleted, false if not found
|
|
106
|
+
*/
|
|
107
|
+
delete(key: string): boolean {
|
|
108
|
+
return this.cache.delete(key);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Clear all cache entries
|
|
113
|
+
*/
|
|
114
|
+
clear(): void {
|
|
115
|
+
this.cache.clear();
|
|
116
|
+
this.hits = 0;
|
|
117
|
+
this.misses = 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Check if a key exists and is not expired
|
|
122
|
+
* @param key Cache key
|
|
123
|
+
* @returns true if key exists and is valid
|
|
124
|
+
*/
|
|
125
|
+
has(key: string): boolean {
|
|
126
|
+
const entry = this.cache.get(key);
|
|
127
|
+
if (!entry) return false;
|
|
128
|
+
|
|
129
|
+
if (Date.now() > entry.expiresAt) {
|
|
130
|
+
this.cache.delete(key);
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get all valid cache keys
|
|
139
|
+
* @returns Array of valid cache keys
|
|
140
|
+
*/
|
|
141
|
+
keys(): string[] {
|
|
142
|
+
const now = Date.now();
|
|
143
|
+
const validKeys: string[] = [];
|
|
144
|
+
|
|
145
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
146
|
+
if (now <= entry.expiresAt) {
|
|
147
|
+
validKeys.push(key);
|
|
148
|
+
} else {
|
|
149
|
+
this.cache.delete(key);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return validKeys;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Clean up expired entries
|
|
158
|
+
* @returns Number of entries removed
|
|
159
|
+
*/
|
|
160
|
+
cleanup(): number {
|
|
161
|
+
const now = Date.now();
|
|
162
|
+
let removed = 0;
|
|
163
|
+
|
|
164
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
165
|
+
if (now > entry.expiresAt) {
|
|
166
|
+
this.cache.delete(key);
|
|
167
|
+
removed++;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return removed;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Get cache size (number of entries)
|
|
176
|
+
*/
|
|
177
|
+
size(): number {
|
|
178
|
+
return this.cache.size;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Get cache statistics
|
|
183
|
+
*/
|
|
184
|
+
getStats(): CacheStats {
|
|
185
|
+
const total = this.hits + this.misses;
|
|
186
|
+
return {
|
|
187
|
+
size: this.cache.size,
|
|
188
|
+
hits: this.hits,
|
|
189
|
+
misses: this.misses,
|
|
190
|
+
hitRate: total > 0 ? this.hits / total : 0,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Reset statistics (keeps cache entries)
|
|
196
|
+
*/
|
|
197
|
+
resetStats(): void {
|
|
198
|
+
this.hits = 0;
|
|
199
|
+
this.misses = 0;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Create a TTL cache instance (convenience function)
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const cache = createCache<string>(5 * 60 * 1000);
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export function createCache<T>(ttl: number = 5 * 60 * 1000): TTLCache<T> {
|
|
212
|
+
return new TTLCache<T>(ttl);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Global cache cleanup interval (runs every minute)
|
|
217
|
+
* This helps prevent memory leaks from expired cache entries
|
|
218
|
+
*/
|
|
219
|
+
let cleanupInterval: ReturnType<typeof setInterval> | null = null;
|
|
220
|
+
const activeCaches = new Set<TTLCache<any>>();
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Register a cache for automatic cleanup
|
|
224
|
+
* @param cache Cache instance to register
|
|
225
|
+
*/
|
|
226
|
+
export function registerCacheForCleanup(cache: TTLCache<any>): void {
|
|
227
|
+
activeCaches.add(cache);
|
|
228
|
+
|
|
229
|
+
// Start cleanup interval if not already running
|
|
230
|
+
if (!cleanupInterval) {
|
|
231
|
+
cleanupInterval = setInterval(() => {
|
|
232
|
+
for (const cache of activeCaches) {
|
|
233
|
+
cache.cleanup();
|
|
234
|
+
}
|
|
235
|
+
}, 60000); // Every minute
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Unregister a cache from automatic cleanup
|
|
241
|
+
* @param cache Cache instance to unregister
|
|
242
|
+
*/
|
|
243
|
+
export function unregisterCacheFromCleanup(cache: TTLCache<any>): void {
|
|
244
|
+
activeCaches.delete(cache);
|
|
245
|
+
|
|
246
|
+
// Stop cleanup interval if no caches are registered
|
|
247
|
+
if (activeCaches.size === 0 && cleanupInterval) {
|
|
248
|
+
clearInterval(cleanupInterval);
|
|
249
|
+
cleanupInterval = null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Stop all cleanup intervals (useful for testing)
|
|
255
|
+
* This will clear the interval and unregister all caches
|
|
256
|
+
*/
|
|
257
|
+
export function stopAllCleanupIntervals(): void {
|
|
258
|
+
if (cleanupInterval) {
|
|
259
|
+
clearInterval(cleanupInterval);
|
|
260
|
+
cleanupInterval = null;
|
|
261
|
+
}
|
|
262
|
+
activeCaches.clear();
|
|
263
|
+
}
|
|
264
|
+
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
export interface DeviceFingerprint {
|
|
2
|
+
userAgent: string;
|
|
3
|
+
platform: string;
|
|
4
|
+
language?: string;
|
|
5
|
+
timezone?: string;
|
|
6
|
+
screen?: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
colorDepth: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface StoredDeviceInfo {
|
|
14
|
+
deviceId: string;
|
|
15
|
+
deviceName?: string;
|
|
16
|
+
fingerprint?: string;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
lastUsed: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Client-side device management utility
|
|
23
|
+
* Handles persistent device identification across app sessions
|
|
24
|
+
*/
|
|
25
|
+
export class DeviceManager {
|
|
26
|
+
private static DEVICE_KEY = 'oxy_device_info';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check if we're in React Native environment
|
|
30
|
+
*/
|
|
31
|
+
private static isReactNative(): boolean {
|
|
32
|
+
return typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get appropriate storage for the platform
|
|
37
|
+
*/
|
|
38
|
+
private static async getStorage(): Promise<{
|
|
39
|
+
getItem: (key: string) => Promise<string | null>;
|
|
40
|
+
setItem: (key: string, value: string) => Promise<void>;
|
|
41
|
+
removeItem: (key: string) => Promise<void>;
|
|
42
|
+
}> {
|
|
43
|
+
if (this.isReactNative()) {
|
|
44
|
+
try {
|
|
45
|
+
const asyncStorageModule = await import('@react-native-async-storage/async-storage');
|
|
46
|
+
const storage = (asyncStorageModule.default as unknown) as import('@react-native-async-storage/async-storage').AsyncStorageStatic;
|
|
47
|
+
return {
|
|
48
|
+
getItem: storage.getItem.bind(storage),
|
|
49
|
+
setItem: storage.setItem.bind(storage),
|
|
50
|
+
removeItem: storage.removeItem.bind(storage),
|
|
51
|
+
};
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('AsyncStorage not available in React Native:', error);
|
|
54
|
+
throw new Error('AsyncStorage is required in React Native environment');
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
// Use localStorage for web
|
|
58
|
+
return {
|
|
59
|
+
getItem: async (key: string) => localStorage.getItem(key),
|
|
60
|
+
setItem: async (key: string, value: string) => localStorage.setItem(key, value),
|
|
61
|
+
removeItem: async (key: string) => localStorage.removeItem(key)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get or create device fingerprint for current device
|
|
68
|
+
*/
|
|
69
|
+
static getDeviceFingerprint(): DeviceFingerprint {
|
|
70
|
+
const fingerprint: DeviceFingerprint = {
|
|
71
|
+
userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : 'unknown',
|
|
72
|
+
platform: typeof navigator !== 'undefined' ? navigator.platform : 'unknown',
|
|
73
|
+
language: typeof navigator !== 'undefined' ? navigator.language : undefined,
|
|
74
|
+
timezone: typeof Intl !== 'undefined' ? Intl.DateTimeFormat().resolvedOptions().timeZone : undefined,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Add screen info if available
|
|
78
|
+
if (typeof screen !== 'undefined') {
|
|
79
|
+
fingerprint.screen = {
|
|
80
|
+
width: screen.width,
|
|
81
|
+
height: screen.height,
|
|
82
|
+
colorDepth: screen.colorDepth
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return fingerprint;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get stored device info or create new one
|
|
91
|
+
*/
|
|
92
|
+
static async getDeviceInfo(): Promise<StoredDeviceInfo> {
|
|
93
|
+
try {
|
|
94
|
+
const storage = await this.getStorage();
|
|
95
|
+
const stored = await storage.getItem(this.DEVICE_KEY);
|
|
96
|
+
|
|
97
|
+
if (stored) {
|
|
98
|
+
const deviceInfo: StoredDeviceInfo = JSON.parse(stored);
|
|
99
|
+
|
|
100
|
+
// Update last used timestamp
|
|
101
|
+
deviceInfo.lastUsed = new Date().toISOString();
|
|
102
|
+
await this.saveDeviceInfo(deviceInfo);
|
|
103
|
+
|
|
104
|
+
return deviceInfo;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Create new device info
|
|
108
|
+
return await this.createNewDeviceInfo();
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error('Error getting device info:', error);
|
|
111
|
+
return await this.createNewDeviceInfo();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Create new device info and store it
|
|
117
|
+
*/
|
|
118
|
+
static async createNewDeviceInfo(): Promise<StoredDeviceInfo> {
|
|
119
|
+
const deviceInfo: StoredDeviceInfo = {
|
|
120
|
+
deviceId: this.generateDeviceId(),
|
|
121
|
+
fingerprint: JSON.stringify(this.getDeviceFingerprint()),
|
|
122
|
+
createdAt: new Date().toISOString(),
|
|
123
|
+
lastUsed: new Date().toISOString()
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
await this.saveDeviceInfo(deviceInfo);
|
|
127
|
+
return deviceInfo;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Save device info to storage
|
|
132
|
+
*/
|
|
133
|
+
static async saveDeviceInfo(deviceInfo: StoredDeviceInfo): Promise<void> {
|
|
134
|
+
try {
|
|
135
|
+
const storage = await this.getStorage();
|
|
136
|
+
await storage.setItem(this.DEVICE_KEY, JSON.stringify(deviceInfo));
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error('Error saving device info:', error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Update device name
|
|
144
|
+
*/
|
|
145
|
+
static async updateDeviceName(deviceName: string): Promise<void> {
|
|
146
|
+
try {
|
|
147
|
+
const deviceInfo = await this.getDeviceInfo();
|
|
148
|
+
deviceInfo.deviceName = deviceName;
|
|
149
|
+
await this.saveDeviceInfo(deviceInfo);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error('Error updating device name:', error);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Clear stored device info (useful for testing or reset)
|
|
157
|
+
*/
|
|
158
|
+
static async clearDeviceInfo(): Promise<void> {
|
|
159
|
+
try {
|
|
160
|
+
const storage = await this.getStorage();
|
|
161
|
+
await storage.removeItem(this.DEVICE_KEY);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error('Error clearing device info:', error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Generate a unique device ID
|
|
169
|
+
*/
|
|
170
|
+
private static generateDeviceId(): string {
|
|
171
|
+
// Use crypto.getRandomValues if available, otherwise fallback to Math.random
|
|
172
|
+
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
173
|
+
const array = new Uint8Array(32);
|
|
174
|
+
crypto.getRandomValues(array);
|
|
175
|
+
return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
176
|
+
} else {
|
|
177
|
+
// Fallback for environments without crypto.getRandomValues
|
|
178
|
+
return 'device_' + Date.now().toString(36) + Math.random().toString(36).substr(2);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Get a user-friendly device name based on platform
|
|
184
|
+
*/
|
|
185
|
+
static getDefaultDeviceName(): string {
|
|
186
|
+
const fingerprint = this.getDeviceFingerprint();
|
|
187
|
+
const platform = (fingerprint.platform || '').toLowerCase();
|
|
188
|
+
|
|
189
|
+
if (platform.includes('win')) return 'Windows Computer';
|
|
190
|
+
if (platform.includes('mac')) return 'Mac Computer';
|
|
191
|
+
if (platform.includes('linux')) return 'Linux Computer';
|
|
192
|
+
if (platform.includes('iphone')) return 'iPhone';
|
|
193
|
+
if (platform.includes('ipad')) return 'iPad';
|
|
194
|
+
if (platform.includes('android')) return 'Android Device';
|
|
195
|
+
|
|
196
|
+
return 'Unknown Device';
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import type { ApiError } from '../models/interfaces';
|
|
2
|
+
import { logger } from './loggerUtils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Error handling utilities for consistent error processing
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Common error codes
|
|
10
|
+
*/
|
|
11
|
+
export const ErrorCodes = {
|
|
12
|
+
// Authentication errors
|
|
13
|
+
UNAUTHORIZED: 'UNAUTHORIZED',
|
|
14
|
+
FORBIDDEN: 'FORBIDDEN',
|
|
15
|
+
INVALID_TOKEN: 'INVALID_TOKEN',
|
|
16
|
+
MISSING_TOKEN: 'MISSING_TOKEN',
|
|
17
|
+
|
|
18
|
+
// Validation errors
|
|
19
|
+
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
|
20
|
+
BAD_REQUEST: 'BAD_REQUEST',
|
|
21
|
+
MISSING_PARAMETER: 'MISSING_PARAMETER',
|
|
22
|
+
INVALID_FORMAT: 'INVALID_FORMAT',
|
|
23
|
+
|
|
24
|
+
// Resource errors
|
|
25
|
+
NOT_FOUND: 'NOT_FOUND',
|
|
26
|
+
ALREADY_EXISTS: 'ALREADY_EXISTS',
|
|
27
|
+
CONFLICT: 'CONFLICT',
|
|
28
|
+
|
|
29
|
+
// Server errors
|
|
30
|
+
INTERNAL_ERROR: 'INTERNAL_ERROR',
|
|
31
|
+
SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
|
|
32
|
+
TIMEOUT: 'TIMEOUT',
|
|
33
|
+
|
|
34
|
+
// Network errors
|
|
35
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
36
|
+
CONNECTION_FAILED: 'CONNECTION_FAILED'
|
|
37
|
+
} as const;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create a standardized API error
|
|
41
|
+
*/
|
|
42
|
+
export function createApiError(
|
|
43
|
+
message: string,
|
|
44
|
+
code: string = ErrorCodes.INTERNAL_ERROR,
|
|
45
|
+
status = 500,
|
|
46
|
+
details?: Record<string, unknown>
|
|
47
|
+
): ApiError {
|
|
48
|
+
return {
|
|
49
|
+
message,
|
|
50
|
+
code,
|
|
51
|
+
status,
|
|
52
|
+
details
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Handle common HTTP errors and convert to ApiError
|
|
58
|
+
*/
|
|
59
|
+
export function handleHttpError(error: unknown): ApiError {
|
|
60
|
+
// If it's already an ApiError, ensure it has a non-empty message
|
|
61
|
+
if (error && typeof error === 'object' && 'code' in error && 'status' in error) {
|
|
62
|
+
const apiError = error as ApiError;
|
|
63
|
+
// Ensure message is not empty
|
|
64
|
+
if (!apiError.message || !apiError.message.trim()) {
|
|
65
|
+
return {
|
|
66
|
+
...apiError,
|
|
67
|
+
message: apiError.message || 'An error occurred',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return apiError;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Handle AbortError (timeout or cancelled requests)
|
|
74
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
75
|
+
return createApiError(
|
|
76
|
+
'Request timeout or cancelled',
|
|
77
|
+
ErrorCodes.TIMEOUT,
|
|
78
|
+
0
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Handle TypeError (network failures, CORS, etc.)
|
|
83
|
+
if (error instanceof TypeError) {
|
|
84
|
+
// Check if it's a network-related TypeError
|
|
85
|
+
if (error.message.includes('fetch') || error.message.includes('network') || error.message.includes('Failed to fetch')) {
|
|
86
|
+
return createApiError(
|
|
87
|
+
'Network error - failed to connect to server',
|
|
88
|
+
ErrorCodes.NETWORK_ERROR,
|
|
89
|
+
0
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return createApiError(
|
|
93
|
+
error.message || 'Network error occurred',
|
|
94
|
+
ErrorCodes.NETWORK_ERROR,
|
|
95
|
+
0
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Handle fetch Response errors - check if it has response property with status
|
|
100
|
+
if (error && typeof error === 'object' && 'response' in error) {
|
|
101
|
+
const fetchError = error as {
|
|
102
|
+
response?: {
|
|
103
|
+
status: number;
|
|
104
|
+
statusText?: string;
|
|
105
|
+
};
|
|
106
|
+
status?: number;
|
|
107
|
+
message?: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const status = fetchError.response?.status || fetchError.status;
|
|
111
|
+
if (status) {
|
|
112
|
+
return createApiError(
|
|
113
|
+
fetchError.message || `HTTP ${status} error`,
|
|
114
|
+
getErrorCodeFromStatus(status),
|
|
115
|
+
status
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Handle standard errors
|
|
121
|
+
if (error instanceof Error) {
|
|
122
|
+
// Check for common error patterns
|
|
123
|
+
if (error.message.includes('timeout') || error.message.includes('aborted')) {
|
|
124
|
+
return createApiError(
|
|
125
|
+
'Request timeout',
|
|
126
|
+
ErrorCodes.TIMEOUT,
|
|
127
|
+
0
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (error.message.includes('network') || error.message.includes('fetch')) {
|
|
132
|
+
return createApiError(
|
|
133
|
+
error.message || 'Network error occurred',
|
|
134
|
+
ErrorCodes.NETWORK_ERROR,
|
|
135
|
+
0
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return createApiError(
|
|
140
|
+
error.message || 'Unknown error occurred',
|
|
141
|
+
ErrorCodes.INTERNAL_ERROR,
|
|
142
|
+
500
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Handle other errors - ensure we always return a non-empty message
|
|
147
|
+
const errorString = error ? String(error) : '';
|
|
148
|
+
const message = errorString.trim() || 'Unknown error occurred';
|
|
149
|
+
return createApiError(
|
|
150
|
+
message,
|
|
151
|
+
ErrorCodes.INTERNAL_ERROR,
|
|
152
|
+
500
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get error code from HTTP status
|
|
158
|
+
* Exported for use in other modules
|
|
159
|
+
*/
|
|
160
|
+
export function getErrorCodeFromStatus(status: number): string {
|
|
161
|
+
switch (status) {
|
|
162
|
+
case 400:
|
|
163
|
+
return ErrorCodes.BAD_REQUEST;
|
|
164
|
+
case 401:
|
|
165
|
+
return ErrorCodes.UNAUTHORIZED;
|
|
166
|
+
case 403:
|
|
167
|
+
return ErrorCodes.FORBIDDEN;
|
|
168
|
+
case 404:
|
|
169
|
+
return ErrorCodes.NOT_FOUND;
|
|
170
|
+
case 409:
|
|
171
|
+
return ErrorCodes.CONFLICT;
|
|
172
|
+
case 422:
|
|
173
|
+
return ErrorCodes.VALIDATION_ERROR;
|
|
174
|
+
case 500:
|
|
175
|
+
return ErrorCodes.INTERNAL_ERROR;
|
|
176
|
+
case 503:
|
|
177
|
+
return ErrorCodes.SERVICE_UNAVAILABLE;
|
|
178
|
+
default:
|
|
179
|
+
return ErrorCodes.INTERNAL_ERROR;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Validate required fields and throw error if missing
|
|
185
|
+
*/
|
|
186
|
+
export function validateRequiredFields(data: Record<string, unknown>, fields: string[]): void {
|
|
187
|
+
const missing = fields.filter(field => !data[field]);
|
|
188
|
+
|
|
189
|
+
if (missing.length > 0) {
|
|
190
|
+
throw createApiError(
|
|
191
|
+
`Missing required fields: ${missing.join(', ')}`,
|
|
192
|
+
ErrorCodes.MISSING_PARAMETER,
|
|
193
|
+
400
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Safe error logging with context
|
|
200
|
+
*/
|
|
201
|
+
export function logError(error: unknown, context?: string): void {
|
|
202
|
+
if (error instanceof Error) {
|
|
203
|
+
logger.error(error.message, {
|
|
204
|
+
component: context || 'errorUtils',
|
|
205
|
+
method: 'logError',
|
|
206
|
+
stack: error.stack,
|
|
207
|
+
});
|
|
208
|
+
} else {
|
|
209
|
+
logger.error(String(error), {
|
|
210
|
+
component: context || 'errorUtils',
|
|
211
|
+
method: 'logError',
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { DeviceManager } from './deviceManager';
|
|
2
|
+
export type { DeviceFingerprint, StoredDeviceInfo } from './deviceManager';
|
|
3
|
+
|
|
4
|
+
// Request utilities
|
|
5
|
+
export { RequestDeduplicator, RequestQueue, SimpleLogger } from './requestUtils';
|
|
6
|
+
|
|
7
|
+
// Cache utilities
|
|
8
|
+
export { TTLCache, createCache, registerCacheForCleanup, unregisterCacheFromCleanup } from './cache';
|
|
9
|
+
export type { CacheStats } from './cache';
|
|
10
|
+
|
|
11
|
+
// Session utilities
|
|
12
|
+
export {
|
|
13
|
+
normalizeSession,
|
|
14
|
+
sortSessions,
|
|
15
|
+
deduplicateSessions,
|
|
16
|
+
deduplicateSessionsByUserId,
|
|
17
|
+
normalizeAndSortSessions,
|
|
18
|
+
mergeSessions,
|
|
19
|
+
sessionsEqual,
|
|
20
|
+
sessionsArraysEqual
|
|
21
|
+
} from './sessionUtils';
|