@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,352 @@
|
|
|
1
|
+
import { buildSearchParams, buildPaginationParams } from '../utils/apiUtils';
|
|
2
|
+
export function OxyServicesUserMixin(Base) {
|
|
3
|
+
return class extends Base {
|
|
4
|
+
constructor(...args) {
|
|
5
|
+
super(...args);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Get profile by username
|
|
9
|
+
*/
|
|
10
|
+
async getProfileByUsername(username) {
|
|
11
|
+
try {
|
|
12
|
+
return await this.makeRequest('GET', `/api/profiles/username/${username}`, undefined, {
|
|
13
|
+
cache: true,
|
|
14
|
+
cacheTTL: 5 * 60 * 1000, // 5 minutes cache for profiles
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw this.handleError(error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Search user profiles
|
|
23
|
+
*/
|
|
24
|
+
async searchProfiles(query, pagination) {
|
|
25
|
+
try {
|
|
26
|
+
const params = { query, ...pagination };
|
|
27
|
+
const searchParams = buildSearchParams(params);
|
|
28
|
+
const paramsObj = Object.fromEntries(searchParams.entries());
|
|
29
|
+
const response = await this.makeRequest('GET', '/api/profiles/search', paramsObj, {
|
|
30
|
+
cache: true,
|
|
31
|
+
cacheTTL: 2 * 60 * 1000, // 2 minutes cache
|
|
32
|
+
});
|
|
33
|
+
// New API shape: { data: User[], pagination: {...} }
|
|
34
|
+
const isSearchProfilesResponse = (payload) => typeof payload === 'object' &&
|
|
35
|
+
payload !== null &&
|
|
36
|
+
Array.isArray(payload.data);
|
|
37
|
+
if (isSearchProfilesResponse(response)) {
|
|
38
|
+
const typedResponse = response;
|
|
39
|
+
const paginationInfo = typedResponse.pagination ?? {
|
|
40
|
+
total: typedResponse.data.length,
|
|
41
|
+
limit: pagination?.limit ?? typedResponse.data.length,
|
|
42
|
+
offset: pagination?.offset ?? 0,
|
|
43
|
+
hasMore: typedResponse.data.length === (pagination?.limit ?? typedResponse.data.length) &&
|
|
44
|
+
(pagination?.limit ?? typedResponse.data.length) > 0,
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
data: typedResponse.data,
|
|
48
|
+
pagination: paginationInfo,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Legacy API shape: returns raw User[]
|
|
52
|
+
if (Array.isArray(response)) {
|
|
53
|
+
const fallbackLimit = pagination?.limit ?? response.length;
|
|
54
|
+
const fallbackPagination = {
|
|
55
|
+
total: response.length,
|
|
56
|
+
limit: fallbackLimit,
|
|
57
|
+
offset: pagination?.offset ?? 0,
|
|
58
|
+
hasMore: fallbackLimit > 0 && response.length === fallbackLimit,
|
|
59
|
+
};
|
|
60
|
+
return { data: response, pagination: fallbackPagination };
|
|
61
|
+
}
|
|
62
|
+
// If response is unexpected, throw an error
|
|
63
|
+
throw new Error('Unexpected search response format');
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw this.handleError(error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get profile recommendations
|
|
71
|
+
*/
|
|
72
|
+
async getProfileRecommendations() {
|
|
73
|
+
return this.withAuthRetry(async () => {
|
|
74
|
+
return await this.makeRequest('GET', '/api/profiles/recommendations', undefined, { cache: true });
|
|
75
|
+
}, 'getProfileRecommendations');
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get user by ID
|
|
79
|
+
*/
|
|
80
|
+
async getUserById(userId) {
|
|
81
|
+
try {
|
|
82
|
+
return await this.makeRequest('GET', `/api/users/${userId}`, undefined, {
|
|
83
|
+
cache: true,
|
|
84
|
+
cacheTTL: 5 * 60 * 1000, // 5 minutes cache
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw this.handleError(error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get current user
|
|
93
|
+
*/
|
|
94
|
+
async getCurrentUser() {
|
|
95
|
+
return this.withAuthRetry(async () => {
|
|
96
|
+
return await this.makeRequest('GET', '/api/users/me', undefined, {
|
|
97
|
+
cache: true,
|
|
98
|
+
cacheTTL: 1 * 60 * 1000, // 1 minute cache for current user
|
|
99
|
+
});
|
|
100
|
+
}, 'getCurrentUser');
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Update user profile
|
|
104
|
+
* TanStack Query handles offline queuing automatically
|
|
105
|
+
*/
|
|
106
|
+
async updateProfile(updates) {
|
|
107
|
+
try {
|
|
108
|
+
return await this.makeRequest('PUT', '/api/users/me', updates, { cache: false });
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
const errorAny = error;
|
|
112
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
113
|
+
const status = errorAny?.status || errorAny?.response?.status;
|
|
114
|
+
// Check if it's an authentication error (401)
|
|
115
|
+
const isAuthError = status === 401 ||
|
|
116
|
+
errorMessage.includes('Authentication required') ||
|
|
117
|
+
errorMessage.includes('Invalid or missing authorization header');
|
|
118
|
+
// If authentication error and we don't have a token, this might be an offline session
|
|
119
|
+
// The caller should handle syncing the session before retrying
|
|
120
|
+
if (isAuthError && !this.hasValidToken()) {
|
|
121
|
+
// Re-throw with a specific message so the caller knows to sync
|
|
122
|
+
throw new Error('AUTH_REQUIRED_OFFLINE_SESSION: Session needs to be synced to get a token');
|
|
123
|
+
}
|
|
124
|
+
throw this.handleError(error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get privacy settings for a user
|
|
129
|
+
* @param userId - The user ID (defaults to current user)
|
|
130
|
+
*/
|
|
131
|
+
async getPrivacySettings(userId) {
|
|
132
|
+
try {
|
|
133
|
+
const id = userId || (await this.getCurrentUser()).id;
|
|
134
|
+
return await this.makeRequest('GET', `/api/privacy/${id}/privacy`, undefined, {
|
|
135
|
+
cache: true,
|
|
136
|
+
cacheTTL: 2 * 60 * 1000, // 2 minutes cache
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
throw this.handleError(error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Update privacy settings
|
|
145
|
+
* @param settings - Partial privacy settings object
|
|
146
|
+
* @param userId - The user ID (defaults to current user)
|
|
147
|
+
*/
|
|
148
|
+
async updatePrivacySettings(settings, userId) {
|
|
149
|
+
try {
|
|
150
|
+
const id = userId || (await this.getCurrentUser()).id;
|
|
151
|
+
return await this.makeRequest('PATCH', `/api/privacy/${id}/privacy`, settings, {
|
|
152
|
+
cache: false,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw this.handleError(error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Request account verification
|
|
161
|
+
*/
|
|
162
|
+
async requestAccountVerification(reason, evidence) {
|
|
163
|
+
try {
|
|
164
|
+
return await this.makeRequest('POST', '/api/users/verify/request', {
|
|
165
|
+
reason,
|
|
166
|
+
evidence,
|
|
167
|
+
}, { cache: false });
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
throw this.handleError(error);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Download account data export
|
|
175
|
+
*/
|
|
176
|
+
async downloadAccountData(format = 'json') {
|
|
177
|
+
try {
|
|
178
|
+
// Use httpService for blob responses (it handles blob responses automatically)
|
|
179
|
+
const result = await this.getClient().request({
|
|
180
|
+
method: 'GET',
|
|
181
|
+
url: `/api/users/me/data`,
|
|
182
|
+
params: { format },
|
|
183
|
+
cache: false,
|
|
184
|
+
});
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
throw this.handleError(error);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Delete account permanently
|
|
193
|
+
* @param password - User password for confirmation
|
|
194
|
+
* @param confirmText - Confirmation text (usually username)
|
|
195
|
+
*/
|
|
196
|
+
async deleteAccount(password, confirmText) {
|
|
197
|
+
try {
|
|
198
|
+
return await this.makeRequest('DELETE', '/api/users/me', {
|
|
199
|
+
password,
|
|
200
|
+
confirmText,
|
|
201
|
+
}, { cache: false });
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
throw this.handleError(error);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Follow a user
|
|
209
|
+
*/
|
|
210
|
+
async followUser(userId) {
|
|
211
|
+
try {
|
|
212
|
+
return await this.makeRequest('POST', `/api/users/${userId}/follow`, undefined, { cache: false });
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
throw this.handleError(error);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Unfollow a user
|
|
220
|
+
*/
|
|
221
|
+
async unfollowUser(userId) {
|
|
222
|
+
try {
|
|
223
|
+
return await this.makeRequest('DELETE', `/api/users/${userId}/follow`, undefined, { cache: false });
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
throw this.handleError(error);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Get follow status
|
|
231
|
+
*/
|
|
232
|
+
async getFollowStatus(userId) {
|
|
233
|
+
try {
|
|
234
|
+
return await this.makeRequest('GET', `/api/users/${userId}/follow-status`, undefined, {
|
|
235
|
+
cache: true,
|
|
236
|
+
cacheTTL: 1 * 60 * 1000, // 1 minute cache
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
throw this.handleError(error);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Get user followers
|
|
245
|
+
*/
|
|
246
|
+
async getUserFollowers(userId, pagination) {
|
|
247
|
+
try {
|
|
248
|
+
const params = buildPaginationParams(pagination || {});
|
|
249
|
+
const response = await this.makeRequest('GET', `/api/users/${userId}/followers`, params, {
|
|
250
|
+
cache: true,
|
|
251
|
+
cacheTTL: 2 * 60 * 1000, // 2 minutes cache
|
|
252
|
+
});
|
|
253
|
+
return {
|
|
254
|
+
followers: response.data || [],
|
|
255
|
+
total: response.pagination.total,
|
|
256
|
+
hasMore: response.pagination.hasMore,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
throw this.handleError(error);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Get user following
|
|
265
|
+
*/
|
|
266
|
+
async getUserFollowing(userId, pagination) {
|
|
267
|
+
try {
|
|
268
|
+
const params = buildPaginationParams(pagination || {});
|
|
269
|
+
const response = await this.makeRequest('GET', `/api/users/${userId}/following`, params, {
|
|
270
|
+
cache: true,
|
|
271
|
+
cacheTTL: 2 * 60 * 1000, // 2 minutes cache
|
|
272
|
+
});
|
|
273
|
+
return {
|
|
274
|
+
following: response.data || [],
|
|
275
|
+
total: response.pagination.total,
|
|
276
|
+
hasMore: response.pagination.hasMore,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
throw this.handleError(error);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get notifications
|
|
285
|
+
*/
|
|
286
|
+
async getNotifications() {
|
|
287
|
+
return this.withAuthRetry(async () => {
|
|
288
|
+
return await this.makeRequest('GET', '/api/notifications', undefined, {
|
|
289
|
+
cache: false, // Don't cache notifications - always get fresh data
|
|
290
|
+
});
|
|
291
|
+
}, 'getNotifications');
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Get unread notification count
|
|
295
|
+
*/
|
|
296
|
+
async getUnreadCount() {
|
|
297
|
+
try {
|
|
298
|
+
const res = await this.makeRequest('GET', '/api/notifications/unread-count', undefined, {
|
|
299
|
+
cache: false, // Don't cache unread count - always get fresh data
|
|
300
|
+
});
|
|
301
|
+
return res.count;
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
throw this.handleError(error);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Create notification
|
|
309
|
+
*/
|
|
310
|
+
async createNotification(data) {
|
|
311
|
+
try {
|
|
312
|
+
return await this.makeRequest('POST', '/api/notifications', data, { cache: false });
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
throw this.handleError(error);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Mark notification as read
|
|
320
|
+
*/
|
|
321
|
+
async markNotificationAsRead(notificationId) {
|
|
322
|
+
try {
|
|
323
|
+
await this.makeRequest('PUT', `/api/notifications/${notificationId}/read`, undefined, { cache: false });
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
throw this.handleError(error);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Mark all notifications as read
|
|
331
|
+
*/
|
|
332
|
+
async markAllNotificationsAsRead() {
|
|
333
|
+
try {
|
|
334
|
+
await this.makeRequest('PUT', '/api/notifications/read-all', undefined, { cache: false });
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
throw this.handleError(error);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Delete notification
|
|
342
|
+
*/
|
|
343
|
+
async deleteNotification(notificationId) {
|
|
344
|
+
try {
|
|
345
|
+
await this.makeRequest('DELETE', `/api/notifications/${notificationId}`, undefined, { cache: false });
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
throw this.handleError(error);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility Methods Mixin
|
|
3
|
+
*
|
|
4
|
+
* Provides utility methods including link metadata fetching
|
|
5
|
+
* and Express.js authentication middleware
|
|
6
|
+
*/
|
|
7
|
+
import { jwtDecode } from 'jwt-decode';
|
|
8
|
+
import { CACHE_TIMES } from './mixinHelpers';
|
|
9
|
+
export function OxyServicesUtilityMixin(Base) {
|
|
10
|
+
return class extends Base {
|
|
11
|
+
constructor(...args) {
|
|
12
|
+
super(...args);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Fetch link metadata
|
|
16
|
+
*/
|
|
17
|
+
async fetchLinkMetadata(url) {
|
|
18
|
+
try {
|
|
19
|
+
return await this.makeRequest('GET', '/api/link-metadata', { url }, {
|
|
20
|
+
cache: true,
|
|
21
|
+
cacheTTL: CACHE_TIMES.EXTRA_LONG,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw this.handleError(error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Simple Express.js authentication middleware
|
|
30
|
+
*
|
|
31
|
+
* Built-in authentication middleware that validates JWT tokens and adds user data to requests.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Basic usage - just add it to your routes
|
|
36
|
+
* app.use('/api/protected', oxyServices.auth());
|
|
37
|
+
*
|
|
38
|
+
* // With debug logging
|
|
39
|
+
* app.use('/api/protected', oxyServices.auth({ debug: true }));
|
|
40
|
+
*
|
|
41
|
+
* // With custom error handling
|
|
42
|
+
* app.use('/api/protected', oxyServices.auth({
|
|
43
|
+
* onError: (error) => console.error('Auth failed:', error)
|
|
44
|
+
* }));
|
|
45
|
+
*
|
|
46
|
+
* // Load full user data
|
|
47
|
+
* app.use('/api/protected', oxyServices.auth({ loadUser: true }));
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param options Optional configuration
|
|
51
|
+
* @param options.debug Enable debug logging (default: false)
|
|
52
|
+
* @param options.onError Custom error handler
|
|
53
|
+
* @param options.loadUser Load full user data (default: false for performance)
|
|
54
|
+
* @param options.session Use session-based validation (default: false)
|
|
55
|
+
* @returns Express middleware function
|
|
56
|
+
*/
|
|
57
|
+
auth(options = {}) {
|
|
58
|
+
const { debug = false, onError, loadUser = false, session = false } = options;
|
|
59
|
+
// Return a synchronous middleware function
|
|
60
|
+
return (req, res, next) => {
|
|
61
|
+
try {
|
|
62
|
+
// Extract token from Authorization header
|
|
63
|
+
const authHeader = req.headers['authorization'];
|
|
64
|
+
const token = authHeader?.startsWith('Bearer ') ? authHeader.substring(7) : null;
|
|
65
|
+
if (debug) {
|
|
66
|
+
console.log(`🔐 Auth: Processing ${req.method} ${req.path}`);
|
|
67
|
+
console.log(`🔐 Auth: Token present: ${!!token}`);
|
|
68
|
+
}
|
|
69
|
+
if (!token) {
|
|
70
|
+
const error = {
|
|
71
|
+
message: 'Access token required',
|
|
72
|
+
code: 'MISSING_TOKEN',
|
|
73
|
+
status: 401
|
|
74
|
+
};
|
|
75
|
+
if (debug)
|
|
76
|
+
console.log(`❌ Auth: Missing token`);
|
|
77
|
+
if (onError)
|
|
78
|
+
return onError(error);
|
|
79
|
+
return res.status(401).json(error);
|
|
80
|
+
}
|
|
81
|
+
// Decode and validate token
|
|
82
|
+
let decoded;
|
|
83
|
+
try {
|
|
84
|
+
decoded = jwtDecode(token);
|
|
85
|
+
if (debug) {
|
|
86
|
+
console.log(`🔐 Auth: Token decoded, User ID: ${decoded.userId || decoded.id}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (decodeError) {
|
|
90
|
+
const error = {
|
|
91
|
+
message: 'Invalid token format',
|
|
92
|
+
code: 'INVALID_TOKEN_FORMAT',
|
|
93
|
+
status: 403
|
|
94
|
+
};
|
|
95
|
+
if (debug)
|
|
96
|
+
console.log(`❌ Auth: Token decode failed`);
|
|
97
|
+
if (onError)
|
|
98
|
+
return onError(error);
|
|
99
|
+
return res.status(403).json(error);
|
|
100
|
+
}
|
|
101
|
+
const userId = decoded.userId || decoded.id;
|
|
102
|
+
if (!userId) {
|
|
103
|
+
const error = {
|
|
104
|
+
message: 'Token missing user ID',
|
|
105
|
+
code: 'INVALID_TOKEN_PAYLOAD',
|
|
106
|
+
status: 403
|
|
107
|
+
};
|
|
108
|
+
if (debug)
|
|
109
|
+
console.log(`❌ Auth: Token missing user ID`);
|
|
110
|
+
if (onError)
|
|
111
|
+
return onError(error);
|
|
112
|
+
return res.status(403).json(error);
|
|
113
|
+
}
|
|
114
|
+
// Check token expiration
|
|
115
|
+
if (decoded.exp && decoded.exp < Math.floor(Date.now() / 1000)) {
|
|
116
|
+
const error = {
|
|
117
|
+
message: 'Token expired',
|
|
118
|
+
code: 'TOKEN_EXPIRED',
|
|
119
|
+
status: 403
|
|
120
|
+
};
|
|
121
|
+
if (debug)
|
|
122
|
+
console.log(`❌ Auth: Token expired`);
|
|
123
|
+
if (onError)
|
|
124
|
+
return onError(error);
|
|
125
|
+
return res.status(403).json(error);
|
|
126
|
+
}
|
|
127
|
+
// For now, skip session validation to keep it simple
|
|
128
|
+
// Session validation can be added later if needed
|
|
129
|
+
// Set request properties immediately
|
|
130
|
+
req.userId = userId;
|
|
131
|
+
req.accessToken = token;
|
|
132
|
+
req.user = { id: userId };
|
|
133
|
+
// Automatically authenticate the OxyServices instance so all subsequent API calls are authenticated
|
|
134
|
+
this.setTokens(token);
|
|
135
|
+
if (debug) {
|
|
136
|
+
console.log(`✅ Auth: Authentication successful for user ${userId}`);
|
|
137
|
+
}
|
|
138
|
+
next();
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const apiError = this.handleError(error);
|
|
142
|
+
if (debug) {
|
|
143
|
+
// Debug logging - using console.log is acceptable here for development
|
|
144
|
+
console.log(`❌ Auth: Unexpected error:`, apiError);
|
|
145
|
+
}
|
|
146
|
+
if (onError)
|
|
147
|
+
return onError(apiError);
|
|
148
|
+
return res.status((apiError && apiError.status) || 500).json(apiError);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized mixin exports and composition helper
|
|
3
|
+
*
|
|
4
|
+
* This module provides a clean way to compose all mixins
|
|
5
|
+
* and ensures consistent ordering for better maintainability
|
|
6
|
+
*/
|
|
7
|
+
import { OxyServicesBase } from '../OxyServices.base';
|
|
8
|
+
import { OxyServicesAuthMixin } from './OxyServices.auth';
|
|
9
|
+
import { OxyServicesFedCMMixin } from './OxyServices.fedcm';
|
|
10
|
+
import { OxyServicesPopupAuthMixin } from './OxyServices.popup';
|
|
11
|
+
import { OxyServicesRedirectAuthMixin } from './OxyServices.redirect';
|
|
12
|
+
import { OxyServicesUserMixin } from './OxyServices.user';
|
|
13
|
+
import { OxyServicesPrivacyMixin } from './OxyServices.privacy';
|
|
14
|
+
import { OxyServicesLanguageMixin } from './OxyServices.language';
|
|
15
|
+
import { OxyServicesPaymentMixin } from './OxyServices.payment';
|
|
16
|
+
import { OxyServicesKarmaMixin } from './OxyServices.karma';
|
|
17
|
+
import { OxyServicesAssetsMixin } from './OxyServices.assets';
|
|
18
|
+
import { OxyServicesDeveloperMixin } from './OxyServices.developer';
|
|
19
|
+
import { OxyServicesLocationMixin } from './OxyServices.location';
|
|
20
|
+
import { OxyServicesAnalyticsMixin } from './OxyServices.analytics';
|
|
21
|
+
import { OxyServicesDevicesMixin } from './OxyServices.devices';
|
|
22
|
+
import { OxyServicesSecurityMixin } from './OxyServices.security';
|
|
23
|
+
import { OxyServicesUtilityMixin } from './OxyServices.utility';
|
|
24
|
+
import { OxyServicesFeaturesMixin } from './OxyServices.features';
|
|
25
|
+
/**
|
|
26
|
+
* Mixin pipeline - applied in order from first to last.
|
|
27
|
+
*
|
|
28
|
+
* Order matters for dependencies:
|
|
29
|
+
* 1. Base auth mixin first (required by all others)
|
|
30
|
+
* 2. Cross-domain auth mixins (FedCM, Popup, Redirect)
|
|
31
|
+
* 3. User mixin (requires auth)
|
|
32
|
+
* 4. Feature mixins (can depend on user)
|
|
33
|
+
* 5. Utility mixin last (augments all)
|
|
34
|
+
*
|
|
35
|
+
* To add a new mixin: insert it at the appropriate position in this array.
|
|
36
|
+
*/
|
|
37
|
+
const MIXIN_PIPELINE = [
|
|
38
|
+
// Base authentication
|
|
39
|
+
OxyServicesAuthMixin,
|
|
40
|
+
// Cross-domain authentication (web-only)
|
|
41
|
+
// - FedCM: Modern browser-native identity federation (Google-style)
|
|
42
|
+
// - Popup: OAuth2-style popup authentication
|
|
43
|
+
// - Redirect: Traditional redirect-based authentication
|
|
44
|
+
OxyServicesFedCMMixin,
|
|
45
|
+
OxyServicesPopupAuthMixin,
|
|
46
|
+
OxyServicesRedirectAuthMixin,
|
|
47
|
+
// User management (requires auth)
|
|
48
|
+
OxyServicesUserMixin,
|
|
49
|
+
OxyServicesPrivacyMixin,
|
|
50
|
+
// Feature mixins
|
|
51
|
+
OxyServicesLanguageMixin,
|
|
52
|
+
OxyServicesPaymentMixin,
|
|
53
|
+
OxyServicesKarmaMixin,
|
|
54
|
+
OxyServicesAssetsMixin,
|
|
55
|
+
OxyServicesDeveloperMixin,
|
|
56
|
+
OxyServicesLocationMixin,
|
|
57
|
+
OxyServicesAnalyticsMixin,
|
|
58
|
+
OxyServicesDevicesMixin,
|
|
59
|
+
OxyServicesSecurityMixin,
|
|
60
|
+
OxyServicesFeaturesMixin,
|
|
61
|
+
// Utility (last, can use all above)
|
|
62
|
+
OxyServicesUtilityMixin,
|
|
63
|
+
];
|
|
64
|
+
/**
|
|
65
|
+
* Composes all OxyServices mixins using a pipeline pattern.
|
|
66
|
+
*
|
|
67
|
+
* This is equivalent to the nested calls but more readable and maintainable.
|
|
68
|
+
* Adding a new mixin: just add it to MIXIN_PIPELINE at the appropriate position.
|
|
69
|
+
*
|
|
70
|
+
* @returns The fully composed OxyServices class with all mixins applied
|
|
71
|
+
*/
|
|
72
|
+
export function composeOxyServices() {
|
|
73
|
+
return MIXIN_PIPELINE.reduce((Base, mixin) => mixin(Base), OxyServicesBase);
|
|
74
|
+
}
|
|
75
|
+
// Export the pipeline for testing/debugging
|
|
76
|
+
export { MIXIN_PIPELINE };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for mixin classes
|
|
3
|
+
* Provides common patterns to reduce code duplication
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Wraps an async method with standard error handling
|
|
7
|
+
* Reduces boilerplate in mixin methods
|
|
8
|
+
*/
|
|
9
|
+
export async function withErrorHandling(operation, handleError) {
|
|
10
|
+
try {
|
|
11
|
+
return await operation();
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
throw handleError(error);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a standard API request method with error handling
|
|
19
|
+
* Reduces duplication across mixin methods
|
|
20
|
+
*/
|
|
21
|
+
export function createApiMethod(makeRequest, handleError, method, url, options = {}) {
|
|
22
|
+
return async (...args) => {
|
|
23
|
+
const urlString = typeof url === 'function' ? url(...args) : url;
|
|
24
|
+
const requestData = options.transformData ? options.transformData(args) : args[0];
|
|
25
|
+
const requestOptions = {
|
|
26
|
+
cache: options.cache ?? true,
|
|
27
|
+
cacheTTL: options.cacheTTL,
|
|
28
|
+
retry: options.retry ?? true,
|
|
29
|
+
};
|
|
30
|
+
try {
|
|
31
|
+
const response = await makeRequest(method, urlString, requestData, requestOptions);
|
|
32
|
+
return options.transformResponse ? options.transformResponse(response) : response;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw handleError(error);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Cache time constants (in milliseconds)
|
|
41
|
+
*/
|
|
42
|
+
export const CACHE_TIMES = {
|
|
43
|
+
SHORT: 1 * 60 * 1000, // 1 minute
|
|
44
|
+
MEDIUM: 2 * 60 * 1000, // 2 minutes
|
|
45
|
+
LONG: 5 * 60 * 1000, // 5 minutes
|
|
46
|
+
VERY_LONG: 10 * 60 * 1000, // 10 minutes
|
|
47
|
+
EXTRA_LONG: 30 * 60 * 1000, // 30 minutes
|
|
48
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security event severity mapping (single source of truth)
|
|
3
|
+
* Maps each event type to its default severity level
|
|
4
|
+
*/
|
|
5
|
+
export const SECURITY_EVENT_SEVERITY_MAP = {
|
|
6
|
+
'sign_in': 'low',
|
|
7
|
+
'sign_out': 'low',
|
|
8
|
+
'profile_updated': 'low',
|
|
9
|
+
'email_changed': 'medium',
|
|
10
|
+
'device_added': 'medium',
|
|
11
|
+
'device_removed': 'medium',
|
|
12
|
+
'security_settings_changed': 'medium',
|
|
13
|
+
'account_recovery': 'high',
|
|
14
|
+
'private_key_exported': 'high',
|
|
15
|
+
'backup_created': 'high',
|
|
16
|
+
'suspicious_activity': 'critical',
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OxyServices Shared Module
|
|
3
|
+
*
|
|
4
|
+
* Platform-agnostic utilities and helpers that work everywhere:
|
|
5
|
+
* - Browser (Web, Expo Web)
|
|
6
|
+
* - React Native (iOS, Android)
|
|
7
|
+
* - Node.js (Backend)
|
|
8
|
+
*
|
|
9
|
+
* This module contains NO React Native or browser-specific dependencies.
|
|
10
|
+
*
|
|
11
|
+
* @module shared
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { darkenColor, normalizeTheme, withRetry } from '@oxyhq/services/shared';
|
|
16
|
+
*
|
|
17
|
+
* const darkBlue = darkenColor('#0066FF', 0.3);
|
|
18
|
+
* const theme = normalizeTheme(userPreference);
|
|
19
|
+
* const data = await withRetry(() => fetchData(), { maxRetries: 3 });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
// Color utilities
|
|
23
|
+
export { darkenColor, lightenColor, hexToRgb, rgbToHex, withOpacity, isLightColor, getContrastTextColor, } from './utils/colorUtils';
|
|
24
|
+
// Theme utilities
|
|
25
|
+
export { normalizeTheme, normalizeColorScheme, getOppositeTheme, systemPrefersDarkMode, getSystemColorScheme, } from './utils/themeUtils';
|
|
26
|
+
// Error utilities
|
|
27
|
+
export { HttpStatus, getErrorStatus, getErrorMessage, isAlreadyRegisteredError, isUnauthorizedError, isForbiddenError, isNotFoundError, isRateLimitError, isServerError, isNetworkError, isRetryableError, } from './utils/errorUtils';
|
|
28
|
+
// Network utilities
|
|
29
|
+
export { DEFAULT_CIRCUIT_BREAKER_CONFIG, createCircuitBreakerState, calculateBackoffInterval, recordFailure, recordSuccess, shouldAllowRequest, delay, withRetry, } from './utils/networkUtils';
|
|
30
|
+
// Debug utilities
|
|
31
|
+
export { isDev, debugLog, debugWarn, debugError, createDebugLogger, } from './utils/debugUtils';
|