@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,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language Methods Mixin
|
|
3
|
+
*/
|
|
4
|
+
import { normalizeLanguageCode, getLanguageMetadata, getLanguageName, getNativeLanguageName } from '../utils/languageUtils';
|
|
5
|
+
import type { LanguageMetadata } from '../utils/languageUtils';
|
|
6
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
7
|
+
|
|
8
|
+
export function OxyServicesLanguageMixin<T extends typeof OxyServicesBase>(Base: T) {
|
|
9
|
+
return class extends Base {
|
|
10
|
+
constructor(...args: any[]) {
|
|
11
|
+
super(...(args as [any]));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get appropriate storage for the platform (similar to DeviceManager)
|
|
15
|
+
*/
|
|
16
|
+
public async getStorage(): Promise<{
|
|
17
|
+
getItem: (key: string) => Promise<string | null>;
|
|
18
|
+
setItem: (key: string, value: string) => Promise<void>;
|
|
19
|
+
removeItem: (key: string) => Promise<void>;
|
|
20
|
+
}> {
|
|
21
|
+
const isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
|
|
22
|
+
|
|
23
|
+
if (isReactNative) {
|
|
24
|
+
try {
|
|
25
|
+
const asyncStorageModule = await import('@react-native-async-storage/async-storage');
|
|
26
|
+
const storage = (asyncStorageModule.default as unknown) as import('@react-native-async-storage/async-storage').AsyncStorageStatic;
|
|
27
|
+
return {
|
|
28
|
+
getItem: storage.getItem.bind(storage),
|
|
29
|
+
setItem: storage.setItem.bind(storage),
|
|
30
|
+
removeItem: storage.removeItem.bind(storage),
|
|
31
|
+
};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error('AsyncStorage not available in React Native:', error);
|
|
34
|
+
throw new Error('AsyncStorage is required in React Native environment');
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
// Use localStorage for web
|
|
38
|
+
return {
|
|
39
|
+
getItem: async (key: string) => {
|
|
40
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
41
|
+
return localStorage.getItem(key);
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
},
|
|
45
|
+
setItem: async (key: string, value: string) => {
|
|
46
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
47
|
+
localStorage.setItem(key, value);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
removeItem: async (key: string) => {
|
|
51
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
52
|
+
localStorage.removeItem(key);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get the current language from storage or user profile
|
|
61
|
+
* @param storageKeyPrefix - Optional prefix for storage key (default: 'oxy_session')
|
|
62
|
+
* @returns The current language code (e.g., 'en-US') or null if not set
|
|
63
|
+
*/
|
|
64
|
+
async getCurrentLanguage(storageKeyPrefix: string = 'oxy_session'): Promise<string | null> {
|
|
65
|
+
try {
|
|
66
|
+
// First try to get from user profile if authenticated
|
|
67
|
+
try {
|
|
68
|
+
const user = await (this as any).getCurrentUser();
|
|
69
|
+
const userLanguage = (user as Record<string, unknown>)?.language as string | undefined;
|
|
70
|
+
if (userLanguage) {
|
|
71
|
+
return normalizeLanguageCode(userLanguage) || userLanguage;
|
|
72
|
+
}
|
|
73
|
+
} catch (e) {
|
|
74
|
+
// User not authenticated or error, continue to storage
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Fall back to storage
|
|
78
|
+
const storage = await this.getStorage();
|
|
79
|
+
const storageKey = `${storageKeyPrefix}_language`;
|
|
80
|
+
const storedLanguage = await storage.getItem(storageKey);
|
|
81
|
+
if (storedLanguage) {
|
|
82
|
+
return normalizeLanguageCode(storedLanguage) || storedLanguage;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return null;
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (__DEV__) {
|
|
88
|
+
console.warn('Failed to get current language:', error);
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get the current language with metadata (name, nativeName, etc.)
|
|
96
|
+
* @param storageKeyPrefix - Optional prefix for storage key (default: 'oxy_session')
|
|
97
|
+
* @returns Language metadata object or null if not set
|
|
98
|
+
*/
|
|
99
|
+
async getCurrentLanguageMetadata(storageKeyPrefix: string = 'oxy_session'): Promise<LanguageMetadata | null> {
|
|
100
|
+
const languageCode = await this.getCurrentLanguage(storageKeyPrefix);
|
|
101
|
+
return getLanguageMetadata(languageCode);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get the current language name (e.g., 'English')
|
|
106
|
+
* @param storageKeyPrefix - Optional prefix for storage key (default: 'oxy_session')
|
|
107
|
+
* @returns Language name or null if not set
|
|
108
|
+
*/
|
|
109
|
+
async getCurrentLanguageName(storageKeyPrefix: string = 'oxy_session'): Promise<string | null> {
|
|
110
|
+
const languageCode = await this.getCurrentLanguage(storageKeyPrefix);
|
|
111
|
+
if (!languageCode) return null;
|
|
112
|
+
return getLanguageName(languageCode);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get the current native language name (e.g., 'Español')
|
|
117
|
+
* @param storageKeyPrefix - Optional prefix for storage key (default: 'oxy_session')
|
|
118
|
+
* @returns Native language name or null if not set
|
|
119
|
+
*/
|
|
120
|
+
async getCurrentNativeLanguageName(storageKeyPrefix: string = 'oxy_session'): Promise<string | null> {
|
|
121
|
+
const languageCode = await this.getCurrentLanguage(storageKeyPrefix);
|
|
122
|
+
if (!languageCode) return null;
|
|
123
|
+
return getNativeLanguageName(languageCode);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Location Methods Mixin
|
|
3
|
+
*/
|
|
4
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
5
|
+
|
|
6
|
+
export function OxyServicesLocationMixin<T extends typeof OxyServicesBase>(Base: T) {
|
|
7
|
+
return class extends Base {
|
|
8
|
+
constructor(...args: any[]) {
|
|
9
|
+
super(...(args as [any]));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Update user location
|
|
14
|
+
* @param latitude - Latitude coordinate
|
|
15
|
+
* @param longitude - Longitude coordinate
|
|
16
|
+
* @returns Location update result
|
|
17
|
+
*/
|
|
18
|
+
async updateLocation(latitude: number, longitude: number): Promise<any> {
|
|
19
|
+
try {
|
|
20
|
+
return await this.makeRequest('POST', '/api/location', {
|
|
21
|
+
latitude,
|
|
22
|
+
longitude
|
|
23
|
+
}, { cache: false });
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw this.handleError(error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get nearby users
|
|
31
|
+
* @param radius - Optional search radius in meters
|
|
32
|
+
* @returns Array of nearby users
|
|
33
|
+
*/
|
|
34
|
+
async getNearbyUsers(radius?: number): Promise<any[]> {
|
|
35
|
+
try {
|
|
36
|
+
const params: any = radius ? { radius } : undefined;
|
|
37
|
+
return await this.makeRequest('GET', '/api/location/nearby', params, {
|
|
38
|
+
cache: false, // Don't cache location data - always get fresh data
|
|
39
|
+
});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw this.handleError(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment Methods Mixin
|
|
3
|
+
*
|
|
4
|
+
* Provides methods for payment processing and management
|
|
5
|
+
*/
|
|
6
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
7
|
+
import { CACHE_TIMES } from './mixinHelpers';
|
|
8
|
+
|
|
9
|
+
export function OxyServicesPaymentMixin<T extends typeof OxyServicesBase>(Base: T) {
|
|
10
|
+
return class extends Base {
|
|
11
|
+
constructor(...args: any[]) {
|
|
12
|
+
super(...(args as [any]));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create a payment
|
|
17
|
+
* @param data - Payment data
|
|
18
|
+
* @returns Created payment object
|
|
19
|
+
*/
|
|
20
|
+
async createPayment(data: any): Promise<any> {
|
|
21
|
+
try {
|
|
22
|
+
return await this.makeRequest('POST', '/api/payments', data, { cache: false });
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throw this.handleError(error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get payment by ID
|
|
30
|
+
* @param paymentId - The payment ID
|
|
31
|
+
* @returns Payment object
|
|
32
|
+
*/
|
|
33
|
+
async getPayment(paymentId: string): Promise<any> {
|
|
34
|
+
try {
|
|
35
|
+
return await this.makeRequest('GET', `/api/payments/${paymentId}`, undefined, {
|
|
36
|
+
cache: true,
|
|
37
|
+
cacheTTL: CACHE_TIMES.LONG,
|
|
38
|
+
});
|
|
39
|
+
} catch (error) {
|
|
40
|
+
throw this.handleError(error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get user payments
|
|
46
|
+
* @returns Array of user payments
|
|
47
|
+
*/
|
|
48
|
+
async getUserPayments(): Promise<any[]> {
|
|
49
|
+
try {
|
|
50
|
+
return await this.makeRequest('GET', '/api/payments/user', undefined, {
|
|
51
|
+
cache: false, // Don't cache user payments - always get fresh data
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw this.handleError(error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get user subscription
|
|
60
|
+
* @param userId - The user ID
|
|
61
|
+
* @returns Subscription object
|
|
62
|
+
*/
|
|
63
|
+
async getSubscription(userId: string): Promise<any> {
|
|
64
|
+
try {
|
|
65
|
+
return await this.makeRequest('GET', `/api/subscription/${userId}`, undefined, {
|
|
66
|
+
cache: true,
|
|
67
|
+
cacheTTL: CACHE_TIMES.MEDIUM,
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
throw this.handleError(error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get current user's subscription
|
|
76
|
+
* @returns Subscription object
|
|
77
|
+
*/
|
|
78
|
+
async getCurrentUserSubscription(): Promise<any> {
|
|
79
|
+
try {
|
|
80
|
+
const userId = this.getCurrentUserId();
|
|
81
|
+
if (!userId) {
|
|
82
|
+
throw new Error('User not authenticated');
|
|
83
|
+
}
|
|
84
|
+
return await this.getSubscription(userId);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw this.handleError(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get user wallet
|
|
92
|
+
* @param userId - The user ID
|
|
93
|
+
* @returns Wallet object with balance
|
|
94
|
+
*/
|
|
95
|
+
async getWallet(userId: string): Promise<any> {
|
|
96
|
+
try {
|
|
97
|
+
return await this.makeRequest('GET', `/api/wallet/${userId}`, undefined, {
|
|
98
|
+
cache: true,
|
|
99
|
+
cacheTTL: CACHE_TIMES.SHORT, // Cache wallet for short time as balance changes frequently
|
|
100
|
+
});
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw this.handleError(error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get current user's wallet
|
|
108
|
+
* @returns Wallet object with balance
|
|
109
|
+
*/
|
|
110
|
+
async getCurrentUserWallet(): Promise<any> {
|
|
111
|
+
try {
|
|
112
|
+
const userId = this.getCurrentUserId();
|
|
113
|
+
if (!userId) {
|
|
114
|
+
throw new Error('User not authenticated');
|
|
115
|
+
}
|
|
116
|
+
return await this.getWallet(userId);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw this.handleError(error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get wallet transaction history
|
|
124
|
+
* @param userId - The user ID
|
|
125
|
+
* @param options - Pagination options
|
|
126
|
+
* @returns Transaction history
|
|
127
|
+
*/
|
|
128
|
+
async getWalletTransactions(userId: string, options?: { limit?: number; offset?: number }): Promise<any> {
|
|
129
|
+
try {
|
|
130
|
+
const params = new URLSearchParams();
|
|
131
|
+
if (options?.limit) params.append('limit', options.limit.toString());
|
|
132
|
+
if (options?.offset) params.append('offset', options.offset.toString());
|
|
133
|
+
|
|
134
|
+
const queryString = params.toString();
|
|
135
|
+
const url = `/api/wallet/transactions/${userId}${queryString ? `?${queryString}` : ''}`;
|
|
136
|
+
|
|
137
|
+
return await this.makeRequest('GET', url, undefined, {
|
|
138
|
+
cache: false, // Don't cache transactions - always get fresh data
|
|
139
|
+
});
|
|
140
|
+
} catch (error) {
|
|
141
|
+
throw this.handleError(error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get current user's wallet transaction history
|
|
147
|
+
* @param options - Pagination options
|
|
148
|
+
* @returns Transaction history
|
|
149
|
+
*/
|
|
150
|
+
async getCurrentUserWalletTransactions(options?: { limit?: number; offset?: number }): Promise<any> {
|
|
151
|
+
try {
|
|
152
|
+
const userId = this.getCurrentUserId();
|
|
153
|
+
if (!userId) {
|
|
154
|
+
throw new Error('User not authenticated');
|
|
155
|
+
}
|
|
156
|
+
return await this.getWalletTransactions(userId, options);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
throw this.handleError(error);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|