@oxyhq/services 5.13.15 → 5.13.17
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 +10 -0
- package/lib/commonjs/core/OxyServices.base.js +271 -0
- package/lib/commonjs/core/OxyServices.base.js.map +1 -0
- package/lib/commonjs/core/OxyServices.errors.js +26 -0
- package/lib/commonjs/core/OxyServices.errors.js.map +1 -0
- package/lib/commonjs/core/OxyServices.js +58 -2168
- package/lib/commonjs/core/OxyServices.js.map +1 -1
- package/lib/commonjs/core/mixins/OxyServices.analytics.js +60 -0
- package/lib/commonjs/core/mixins/OxyServices.analytics.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.assets.js +424 -0
- package/lib/commonjs/core/mixins/OxyServices.assets.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.auth.js +303 -0
- package/lib/commonjs/core/mixins/OxyServices.auth.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.developer.js +115 -0
- package/lib/commonjs/core/mixins/OxyServices.developer.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.devices.js +119 -0
- package/lib/commonjs/core/mixins/OxyServices.devices.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.karma.js +117 -0
- package/lib/commonjs/core/mixins/OxyServices.karma.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.language.js +124 -0
- package/lib/commonjs/core/mixins/OxyServices.language.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.location.js +55 -0
- package/lib/commonjs/core/mixins/OxyServices.location.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.payment.js +66 -0
- package/lib/commonjs/core/mixins/OxyServices.payment.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.privacy.js +174 -0
- package/lib/commonjs/core/mixins/OxyServices.privacy.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.totp.js +53 -0
- package/lib/commonjs/core/mixins/OxyServices.totp.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.user.js +388 -0
- package/lib/commonjs/core/mixins/OxyServices.user.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.utility.js +161 -0
- package/lib/commonjs/core/mixins/OxyServices.utility.js.map +1 -0
- package/lib/commonjs/core/mixins/index.js +39 -0
- package/lib/commonjs/core/mixins/index.js.map +1 -0
- package/lib/commonjs/core/mixins/mixinHelpers.js +62 -0
- package/lib/commonjs/core/mixins/mixinHelpers.js.map +1 -0
- package/lib/commonjs/ui/context/OxyContext.js +27 -2
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/module/core/OxyServices.base.js +265 -0
- package/lib/module/core/OxyServices.base.js.map +1 -0
- package/lib/module/core/OxyServices.errors.js +20 -0
- package/lib/module/core/OxyServices.errors.js.map +1 -0
- package/lib/module/core/OxyServices.js +43 -2164
- package/lib/module/core/OxyServices.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.analytics.js +56 -0
- package/lib/module/core/mixins/OxyServices.analytics.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.assets.js +420 -0
- package/lib/module/core/mixins/OxyServices.assets.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.auth.js +299 -0
- package/lib/module/core/mixins/OxyServices.auth.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.developer.js +111 -0
- package/lib/module/core/mixins/OxyServices.developer.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.devices.js +115 -0
- package/lib/module/core/mixins/OxyServices.devices.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.karma.js +113 -0
- package/lib/module/core/mixins/OxyServices.karma.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.language.js +120 -0
- package/lib/module/core/mixins/OxyServices.language.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.location.js +51 -0
- package/lib/module/core/mixins/OxyServices.location.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.payment.js +62 -0
- package/lib/module/core/mixins/OxyServices.payment.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.privacy.js +170 -0
- package/lib/module/core/mixins/OxyServices.privacy.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.totp.js +49 -0
- package/lib/module/core/mixins/OxyServices.totp.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.user.js +384 -0
- package/lib/module/core/mixins/OxyServices.user.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.utility.js +156 -0
- package/lib/module/core/mixins/OxyServices.utility.js.map +1 -0
- package/lib/module/core/mixins/index.js +36 -0
- package/lib/module/core/mixins/index.js.map +1 -0
- package/lib/module/core/mixins/mixinHelpers.js +56 -0
- package/lib/module/core/mixins/mixinHelpers.js.map +1 -0
- package/lib/module/ui/context/OxyContext.js +27 -2
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/typescript/core/OxyServices.base.d.ts +123 -0
- package/lib/typescript/core/OxyServices.base.d.ts.map +1 -0
- package/lib/typescript/core/OxyServices.d.ts +970 -746
- package/lib/typescript/core/OxyServices.d.ts.map +1 -1
- package/lib/typescript/core/OxyServices.errors.d.ts +12 -0
- package/lib/typescript/core/OxyServices.errors.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.analytics.d.ts +70 -0
- package/lib/typescript/core/mixins/OxyServices.analytics.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.assets.d.ts +166 -0
- package/lib/typescript/core/mixins/OxyServices.assets.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts +168 -0
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.developer.d.ts +103 -0
- package/lib/typescript/core/mixins/OxyServices.developer.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.devices.d.ts +93 -0
- package/lib/typescript/core/mixins/OxyServices.devices.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.karma.d.ts +89 -0
- package/lib/typescript/core/mixins/OxyServices.karma.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.language.d.ts +85 -0
- package/lib/typescript/core/mixins/OxyServices.language.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.location.d.ts +68 -0
- package/lib/typescript/core/mixins/OxyServices.location.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.payment.d.ts +74 -0
- package/lib/typescript/core/mixins/OxyServices.payment.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.privacy.d.ts +126 -0
- package/lib/typescript/core/mixins/OxyServices.privacy.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.totp.d.ts +69 -0
- package/lib/typescript/core/mixins/OxyServices.totp.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.user.d.ts +189 -0
- package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.utility.d.ts +97 -0
- package/lib/typescript/core/mixins/OxyServices.utility.d.ts.map +1 -0
- package/lib/typescript/core/mixins/index.d.ts +899 -0
- package/lib/typescript/core/mixins/index.d.ts.map +1 -0
- package/lib/typescript/core/mixins/mixinHelpers.d.ts +32 -0
- package/lib/typescript/core/mixins/mixinHelpers.d.ts.map +1 -0
- package/lib/typescript/models/interfaces.d.ts +10 -0
- package/lib/typescript/models/interfaces.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts +2 -0
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/OxyServices.base.ts +311 -0
- package/src/core/OxyServices.errors.ts +26 -0
- package/src/core/OxyServices.ts +43 -2199
- package/src/core/mixins/OxyServices.analytics.ts +53 -0
- package/src/core/mixins/OxyServices.assets.ts +410 -0
- package/src/core/mixins/OxyServices.auth.ts +275 -0
- package/src/core/mixins/OxyServices.developer.ts +114 -0
- package/src/core/mixins/OxyServices.devices.ts +103 -0
- package/src/core/mixins/OxyServices.karma.ts +111 -0
- package/src/core/mixins/OxyServices.language.ts +127 -0
- package/src/core/mixins/OxyServices.location.ts +46 -0
- package/src/core/mixins/OxyServices.payment.ts +59 -0
- package/src/core/mixins/OxyServices.privacy.ts +182 -0
- package/src/core/mixins/OxyServices.totp.ts +36 -0
- package/src/core/mixins/OxyServices.user.ts +384 -0
- package/src/core/mixins/OxyServices.utility.ts +187 -0
- package/src/core/mixins/index.ts +58 -0
- package/src/core/mixins/mixinHelpers.ts +69 -0
- package/src/models/interfaces.ts +12 -0
- package/src/ui/context/OxyContext.tsx +36 -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,59 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Privacy Methods Mixin (Blocked & Restricted Users)
|
|
3
|
+
*/
|
|
4
|
+
import type { BlockedUser, RestrictedUser } from '../../models/interfaces';
|
|
5
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
6
|
+
|
|
7
|
+
export function OxyServicesPrivacyMixin<T extends typeof OxyServicesBase>(Base: T) {
|
|
8
|
+
return class extends Base {
|
|
9
|
+
constructor(...args: any[]) {
|
|
10
|
+
super(...(args as [any]));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Extract user ID from blocked/restricted user object
|
|
14
|
+
*/
|
|
15
|
+
public extractUserId(userIdField: string | { _id: string; username?: string; avatar?: string }): string {
|
|
16
|
+
return typeof userIdField === 'string' ? userIdField : userIdField._id;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check if a user is in a list (blocked or restricted)
|
|
21
|
+
*/
|
|
22
|
+
public async isUserInList<T extends BlockedUser | RestrictedUser>(
|
|
23
|
+
userId: string,
|
|
24
|
+
getUserList: () => Promise<T[]>,
|
|
25
|
+
getIdField: (item: T) => string | { _id: string; username?: string; avatar?: string }
|
|
26
|
+
): Promise<boolean> {
|
|
27
|
+
try {
|
|
28
|
+
if (!userId) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const users = await getUserList();
|
|
32
|
+
return users.some(item => {
|
|
33
|
+
const itemId = this.extractUserId(getIdField(item));
|
|
34
|
+
return itemId === userId;
|
|
35
|
+
});
|
|
36
|
+
} catch (error) {
|
|
37
|
+
// If there's an error, assume not in list to avoid breaking functionality
|
|
38
|
+
if (__DEV__) {
|
|
39
|
+
console.warn('Error checking user list:', error);
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// BLOCKED USERS METHODS
|
|
47
|
+
// ============================================================================
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get list of blocked users
|
|
51
|
+
* @returns Array of blocked users
|
|
52
|
+
*/
|
|
53
|
+
async getBlockedUsers(): Promise<BlockedUser[]> {
|
|
54
|
+
try {
|
|
55
|
+
return await this.makeRequest<BlockedUser[]>('GET', '/api/privacy/blocked', undefined, {
|
|
56
|
+
cache: true,
|
|
57
|
+
cacheTTL: 1 * 60 * 1000, // 1 minute cache
|
|
58
|
+
});
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw this.handleError(error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Block a user
|
|
66
|
+
* @param userId - The user ID to block
|
|
67
|
+
* @returns Success message
|
|
68
|
+
*/
|
|
69
|
+
async blockUser(userId: string): Promise<{ message: string }> {
|
|
70
|
+
try {
|
|
71
|
+
if (!userId) {
|
|
72
|
+
throw new Error('User ID is required');
|
|
73
|
+
}
|
|
74
|
+
return await this.makeRequest<{ message: string }>('POST', `/api/privacy/blocked/${userId}`, undefined, {
|
|
75
|
+
cache: false,
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
throw this.handleError(error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Unblock a user
|
|
84
|
+
* @param userId - The user ID to unblock
|
|
85
|
+
* @returns Success message
|
|
86
|
+
*/
|
|
87
|
+
async unblockUser(userId: string): Promise<{ message: string }> {
|
|
88
|
+
try {
|
|
89
|
+
if (!userId) {
|
|
90
|
+
throw new Error('User ID is required');
|
|
91
|
+
}
|
|
92
|
+
return await this.makeRequest<{ message: string }>('DELETE', `/api/privacy/blocked/${userId}`, undefined, {
|
|
93
|
+
cache: false,
|
|
94
|
+
});
|
|
95
|
+
} catch (error) {
|
|
96
|
+
throw this.handleError(error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Check if a user is blocked
|
|
102
|
+
* @param userId - The user ID to check
|
|
103
|
+
* @returns True if the user is blocked, false otherwise
|
|
104
|
+
*/
|
|
105
|
+
async isUserBlocked(userId: string): Promise<boolean> {
|
|
106
|
+
return this.isUserInList(
|
|
107
|
+
userId,
|
|
108
|
+
() => this.getBlockedUsers(),
|
|
109
|
+
(block) => block.blockedId
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ============================================================================
|
|
114
|
+
// RESTRICTED USERS METHODS
|
|
115
|
+
// ============================================================================
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get list of restricted users
|
|
119
|
+
* @returns Array of restricted users
|
|
120
|
+
*/
|
|
121
|
+
async getRestrictedUsers(): Promise<RestrictedUser[]> {
|
|
122
|
+
try {
|
|
123
|
+
return await this.makeRequest<RestrictedUser[]>('GET', '/api/privacy/restricted', undefined, {
|
|
124
|
+
cache: true,
|
|
125
|
+
cacheTTL: 1 * 60 * 1000, // 1 minute cache
|
|
126
|
+
});
|
|
127
|
+
} catch (error) {
|
|
128
|
+
throw this.handleError(error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Restrict a user (limit their interactions without fully blocking)
|
|
134
|
+
* @param userId - The user ID to restrict
|
|
135
|
+
* @returns Success message
|
|
136
|
+
*/
|
|
137
|
+
async restrictUser(userId: string): Promise<{ message: string }> {
|
|
138
|
+
try {
|
|
139
|
+
if (!userId) {
|
|
140
|
+
throw new Error('User ID is required');
|
|
141
|
+
}
|
|
142
|
+
return await this.makeRequest<{ message: string }>('POST', `/api/privacy/restricted/${userId}`, undefined, {
|
|
143
|
+
cache: false,
|
|
144
|
+
});
|
|
145
|
+
} catch (error) {
|
|
146
|
+
throw this.handleError(error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Unrestrict a user
|
|
152
|
+
* @param userId - The user ID to unrestrict
|
|
153
|
+
* @returns Success message
|
|
154
|
+
*/
|
|
155
|
+
async unrestrictUser(userId: string): Promise<{ message: string }> {
|
|
156
|
+
try {
|
|
157
|
+
if (!userId) {
|
|
158
|
+
throw new Error('User ID is required');
|
|
159
|
+
}
|
|
160
|
+
return await this.makeRequest<{ message: string }>('DELETE', `/api/privacy/restricted/${userId}`, undefined, {
|
|
161
|
+
cache: false,
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
throw this.handleError(error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Check if a user is restricted
|
|
170
|
+
* @param userId - The user ID to check
|
|
171
|
+
* @returns True if the user is restricted, false otherwise
|
|
172
|
+
*/
|
|
173
|
+
async isUserRestricted(userId: string): Promise<boolean> {
|
|
174
|
+
return this.isUserInList(
|
|
175
|
+
userId,
|
|
176
|
+
() => this.getRestrictedUsers(),
|
|
177
|
+
(restrict) => restrict.restrictedId
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOTP Enrollment Methods Mixin
|
|
3
|
+
*/
|
|
4
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
5
|
+
|
|
6
|
+
export function OxyServicesTotpMixin<T extends typeof OxyServicesBase>(Base: T) {
|
|
7
|
+
return class extends Base {
|
|
8
|
+
constructor(...args: any[]) {
|
|
9
|
+
super(...(args as [any]));
|
|
10
|
+
}
|
|
11
|
+
async startTotpEnrollment(sessionId: string): Promise<{ secret: string; otpauthUrl: string; issuer: string; label: string }> {
|
|
12
|
+
try {
|
|
13
|
+
return await this.makeRequest('POST', '/api/auth/totp/enroll/start', { sessionId }, { cache: false });
|
|
14
|
+
} catch (error) {
|
|
15
|
+
throw this.handleError(error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async verifyTotpEnrollment(sessionId: string, code: string): Promise<{ enabled: boolean; backupCodes?: string[]; recoveryKey?: string }> {
|
|
20
|
+
try {
|
|
21
|
+
return await this.makeRequest('POST', '/api/auth/totp/enroll/verify', { sessionId, code }, { cache: false });
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw this.handleError(error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async disableTotp(sessionId: string, code: string): Promise<{ disabled: boolean }> {
|
|
28
|
+
try {
|
|
29
|
+
return await this.makeRequest('POST', '/api/auth/totp/disable', { sessionId, code }, { cache: false });
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw this.handleError(error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|