@oxyhq/services 5.13.12 → 5.13.16
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 -2009
- 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 +406 -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 +389 -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/index.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +26 -47
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js +239 -1
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/commonjs/utils/apiUtils.js +0 -14
- package/lib/commonjs/utils/apiUtils.js.map +1 -1
- package/lib/commonjs/utils/asyncUtils.js +0 -20
- package/lib/commonjs/utils/asyncUtils.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 -2005
- 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 +402 -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 +385 -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/index.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +26 -47
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/navigation/types.js.map +1 -1
- package/lib/module/ui/screens/PrivacySettingsScreen.js +241 -3
- package/lib/module/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/module/utils/apiUtils.js +0 -13
- package/lib/module/utils/apiUtils.js.map +1 -1
- package/lib/module/utils/asyncUtils.js +0 -20
- package/lib/module/utils/asyncUtils.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 +969 -682
- 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 +159 -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 +898 -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/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/interfaces.d.ts +36 -0
- package/lib/typescript/models/interfaces.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts +2 -6
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/ui/navigation/types.d.ts +0 -1
- package/lib/typescript/ui/navigation/types.d.ts.map +1 -1
- package/lib/typescript/ui/screens/PrivacySettingsScreen.d.ts.map +1 -1
- package/lib/typescript/utils/apiUtils.d.ts +0 -7
- package/lib/typescript/utils/apiUtils.d.ts.map +1 -1
- package/lib/typescript/utils/asyncUtils.d.ts +0 -11
- package/lib/typescript/utils/asyncUtils.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 -2026
- package/src/core/mixins/OxyServices.analytics.ts +53 -0
- package/src/core/mixins/OxyServices.assets.ts +390 -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 +380 -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/index.ts +4 -0
- package/src/models/interfaces.ts +40 -0
- package/src/ui/context/OxyContext.tsx +35 -53
- package/src/ui/navigation/types.ts +0 -1
- package/src/ui/screens/PrivacySettingsScreen.tsx +240 -2
- package/src/utils/apiUtils.ts +0 -14
- package/src/utils/asyncUtils.ts +0 -20
- package/lib/commonjs/ui/screens/internal/SignInPasswordStep.js +0 -192
- package/lib/commonjs/ui/screens/internal/SignInPasswordStep.js.map +0 -1
- package/lib/commonjs/ui/screens/internal/SignInUsernameStep.js +0 -142
- package/lib/commonjs/ui/screens/internal/SignInUsernameStep.js.map +0 -1
- package/lib/commonjs/ui/screens/internal/SignUpIdentityStep.js +0 -113
- package/lib/commonjs/ui/screens/internal/SignUpIdentityStep.js.map +0 -1
- package/lib/commonjs/ui/screens/internal/SignUpSecurityStep.js +0 -132
- package/lib/commonjs/ui/screens/internal/SignUpSecurityStep.js.map +0 -1
- package/lib/commonjs/ui/screens/internal/SignUpSummaryStep.js +0 -83
- package/lib/commonjs/ui/screens/internal/SignUpSummaryStep.js.map +0 -1
- package/lib/commonjs/ui/screens/internal/SignUpWelcomeStep.js +0 -58
- package/lib/commonjs/ui/screens/internal/SignUpWelcomeStep.js.map +0 -1
- package/lib/module/ui/screens/internal/SignInPasswordStep.js +0 -186
- package/lib/module/ui/screens/internal/SignInPasswordStep.js.map +0 -1
- package/lib/module/ui/screens/internal/SignInUsernameStep.js +0 -136
- package/lib/module/ui/screens/internal/SignInUsernameStep.js.map +0 -1
- package/lib/module/ui/screens/internal/SignUpIdentityStep.js +0 -108
- package/lib/module/ui/screens/internal/SignUpIdentityStep.js.map +0 -1
- package/lib/module/ui/screens/internal/SignUpSecurityStep.js +0 -127
- package/lib/module/ui/screens/internal/SignUpSecurityStep.js.map +0 -1
- package/lib/module/ui/screens/internal/SignUpSummaryStep.js +0 -78
- package/lib/module/ui/screens/internal/SignUpSummaryStep.js.map +0 -1
- package/lib/module/ui/screens/internal/SignUpWelcomeStep.js +0 -53
- package/lib/module/ui/screens/internal/SignUpWelcomeStep.js.map +0 -1
- package/lib/typescript/ui/screens/internal/SignInPasswordStep.d.ts +0 -28
- package/lib/typescript/ui/screens/internal/SignInPasswordStep.d.ts.map +0 -1
- package/lib/typescript/ui/screens/internal/SignInUsernameStep.d.ts +0 -25
- package/lib/typescript/ui/screens/internal/SignInUsernameStep.d.ts.map +0 -1
- package/lib/typescript/ui/screens/internal/SignUpIdentityStep.d.ts +0 -20
- package/lib/typescript/ui/screens/internal/SignUpIdentityStep.d.ts.map +0 -1
- package/lib/typescript/ui/screens/internal/SignUpSecurityStep.d.ts +0 -24
- package/lib/typescript/ui/screens/internal/SignUpSecurityStep.d.ts.map +0 -1
- package/lib/typescript/ui/screens/internal/SignUpSummaryStep.d.ts +0 -15
- package/lib/typescript/ui/screens/internal/SignUpSummaryStep.d.ts.map +0 -1
- package/lib/typescript/ui/screens/internal/SignUpWelcomeStep.d.ts +0 -13
- package/lib/typescript/ui/screens/internal/SignUpWelcomeStep.d.ts.map +0 -1
- package/src/ui/screens/internal/SignInPasswordStep.tsx +0 -184
- package/src/ui/screens/internal/SignInUsernameStep.tsx +0 -145
- package/src/ui/screens/internal/SignUpIdentityStep.tsx +0 -112
- package/src/ui/screens/internal/SignUpSecurityStep.tsx +0 -132
- package/src/ui/screens/internal/SignUpSummaryStep.tsx +0 -66
- package/src/ui/screens/internal/SignUpWelcomeStep.tsx +0 -52
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Management Methods Mixin
|
|
3
|
+
*/
|
|
4
|
+
import type { User, Notification, SearchProfilesResponse, PaginationInfo } from '../../models/interfaces';
|
|
5
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
6
|
+
import { buildSearchParams, buildPaginationParams, type PaginationParams } from '../../utils/apiUtils';
|
|
7
|
+
|
|
8
|
+
export function OxyServicesUserMixin<T extends typeof OxyServicesBase>(Base: T) {
|
|
9
|
+
return class extends Base {
|
|
10
|
+
constructor(...args: any[]) {
|
|
11
|
+
super(...(args as [any]));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get profile by username
|
|
15
|
+
*/
|
|
16
|
+
async getProfileByUsername(username: string): Promise<User> {
|
|
17
|
+
try {
|
|
18
|
+
return await this.makeRequest<User>('GET', `/api/profiles/username/${username}`, undefined, {
|
|
19
|
+
cache: true,
|
|
20
|
+
cacheTTL: 5 * 60 * 1000, // 5 minutes cache for profiles
|
|
21
|
+
});
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw this.handleError(error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Search user profiles
|
|
29
|
+
*/
|
|
30
|
+
async searchProfiles(query: string, pagination?: PaginationParams): Promise<SearchProfilesResponse> {
|
|
31
|
+
try {
|
|
32
|
+
const params = { query, ...pagination };
|
|
33
|
+
const searchParams = buildSearchParams(params);
|
|
34
|
+
const paramsObj: Record<string, string> = {};
|
|
35
|
+
searchParams.forEach((value, key) => {
|
|
36
|
+
paramsObj[key] = value;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const response = await this.makeRequest<SearchProfilesResponse | User[]>(
|
|
40
|
+
'GET',
|
|
41
|
+
'/api/profiles/search',
|
|
42
|
+
paramsObj,
|
|
43
|
+
{
|
|
44
|
+
cache: true,
|
|
45
|
+
cacheTTL: 2 * 60 * 1000, // 2 minutes cache
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// New API shape: { data: User[], pagination: {...} }
|
|
50
|
+
if ((response as SearchProfilesResponse)?.data && Array.isArray((response as SearchProfilesResponse).data)) {
|
|
51
|
+
const typedResponse = response as SearchProfilesResponse;
|
|
52
|
+
const paginationInfo: PaginationInfo = typedResponse.pagination ?? {
|
|
53
|
+
total: typedResponse.data.length,
|
|
54
|
+
limit: pagination?.limit ?? typedResponse.data.length,
|
|
55
|
+
offset: pagination?.offset ?? 0,
|
|
56
|
+
hasMore: false,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
data: typedResponse.data,
|
|
61
|
+
pagination: paginationInfo,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Legacy API shape: returns raw User[]
|
|
66
|
+
if (Array.isArray(response)) {
|
|
67
|
+
const fallbackPagination: PaginationInfo = {
|
|
68
|
+
total: response.length,
|
|
69
|
+
limit: pagination?.limit ?? response.length,
|
|
70
|
+
offset: pagination?.offset ?? 0,
|
|
71
|
+
hasMore: false,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return { data: response, pagination: fallbackPagination } as SearchProfilesResponse;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// If response is unexpected, throw an error
|
|
78
|
+
throw new Error('Unexpected search response format');
|
|
79
|
+
} catch (error) {
|
|
80
|
+
throw this.handleError(error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get profile recommendations
|
|
86
|
+
*/
|
|
87
|
+
async getProfileRecommendations(): Promise<Array<{
|
|
88
|
+
id: string;
|
|
89
|
+
username: string;
|
|
90
|
+
name?: { first?: string; last?: string; full?: string };
|
|
91
|
+
description?: string;
|
|
92
|
+
_count?: { followers: number; following: number };
|
|
93
|
+
[key: string]: any;
|
|
94
|
+
}>> {
|
|
95
|
+
return this.withAuthRetry(async () => {
|
|
96
|
+
return await this.makeRequest('GET', '/api/profiles/recommendations', undefined, { cache: true });
|
|
97
|
+
}, 'getProfileRecommendations');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get user by ID
|
|
102
|
+
*/
|
|
103
|
+
async getUserById(userId: string): Promise<User> {
|
|
104
|
+
try {
|
|
105
|
+
return await this.makeRequest<User>('GET', `/api/users/${userId}`, undefined, {
|
|
106
|
+
cache: true,
|
|
107
|
+
cacheTTL: 5 * 60 * 1000, // 5 minutes cache
|
|
108
|
+
});
|
|
109
|
+
} catch (error) {
|
|
110
|
+
throw this.handleError(error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get current user
|
|
116
|
+
*/
|
|
117
|
+
async getCurrentUser(): Promise<User> {
|
|
118
|
+
return this.withAuthRetry(async () => {
|
|
119
|
+
return await this.makeRequest<User>('GET', '/api/users/me', undefined, {
|
|
120
|
+
cache: true,
|
|
121
|
+
cacheTTL: 1 * 60 * 1000, // 1 minute cache for current user
|
|
122
|
+
});
|
|
123
|
+
}, 'getCurrentUser');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Update user profile
|
|
128
|
+
*/
|
|
129
|
+
async updateProfile(updates: Record<string, any>): Promise<User> {
|
|
130
|
+
try {
|
|
131
|
+
return await this.makeRequest<User>('PUT', '/api/users/me', updates, { cache: false });
|
|
132
|
+
} catch (error) {
|
|
133
|
+
throw this.handleError(error);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get privacy settings for a user
|
|
139
|
+
* @param userId - The user ID (defaults to current user)
|
|
140
|
+
*/
|
|
141
|
+
async getPrivacySettings(userId?: string): Promise<any> {
|
|
142
|
+
try {
|
|
143
|
+
const id = userId || (await this.getCurrentUser()).id;
|
|
144
|
+
return await this.makeRequest<any>('GET', `/api/privacy/${id}/privacy`, undefined, {
|
|
145
|
+
cache: true,
|
|
146
|
+
cacheTTL: 2 * 60 * 1000, // 2 minutes cache
|
|
147
|
+
});
|
|
148
|
+
} catch (error) {
|
|
149
|
+
throw this.handleError(error);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Update privacy settings
|
|
155
|
+
* @param settings - Partial privacy settings object
|
|
156
|
+
* @param userId - The user ID (defaults to current user)
|
|
157
|
+
*/
|
|
158
|
+
async updatePrivacySettings(settings: Record<string, any>, userId?: string): Promise<any> {
|
|
159
|
+
try {
|
|
160
|
+
const id = userId || (await this.getCurrentUser()).id;
|
|
161
|
+
return await this.makeRequest<any>('PATCH', `/api/privacy/${id}/privacy`, settings, {
|
|
162
|
+
cache: false,
|
|
163
|
+
});
|
|
164
|
+
} catch (error) {
|
|
165
|
+
throw this.handleError(error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Request account verification
|
|
171
|
+
*/
|
|
172
|
+
async requestAccountVerification(reason: string, evidence?: string): Promise<{ message: string; requestId: string }> {
|
|
173
|
+
try {
|
|
174
|
+
return await this.makeRequest<{ message: string; requestId: string }>('POST', '/api/users/verify/request', {
|
|
175
|
+
reason,
|
|
176
|
+
evidence,
|
|
177
|
+
}, { cache: false });
|
|
178
|
+
} catch (error) {
|
|
179
|
+
throw this.handleError(error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Download account data export
|
|
185
|
+
*/
|
|
186
|
+
async downloadAccountData(format: 'json' | 'csv' = 'json'): Promise<Blob> {
|
|
187
|
+
try {
|
|
188
|
+
// Use axios instance directly for blob responses since RequestManager doesn't handle blobs
|
|
189
|
+
const axiosInstance = this.getClient().getAxiosInstance();
|
|
190
|
+
|
|
191
|
+
const response = await axiosInstance.get(`/api/users/me/data?format=${format}`, {
|
|
192
|
+
responseType: 'blob',
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return response.data as Blob;
|
|
196
|
+
} catch (error) {
|
|
197
|
+
throw this.handleError(error);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Delete account permanently
|
|
203
|
+
* @param password - User password for confirmation
|
|
204
|
+
* @param confirmText - Confirmation text (usually username)
|
|
205
|
+
*/
|
|
206
|
+
async deleteAccount(password: string, confirmText: string): Promise<{ message: string }> {
|
|
207
|
+
try {
|
|
208
|
+
return await this.makeRequest<{ message: string }>('DELETE', '/api/users/me', {
|
|
209
|
+
password,
|
|
210
|
+
confirmText,
|
|
211
|
+
}, { cache: false });
|
|
212
|
+
} catch (error) {
|
|
213
|
+
throw this.handleError(error);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Update user by ID (admin function)
|
|
219
|
+
*/
|
|
220
|
+
async updateUser(userId: string, updates: Record<string, any>): Promise<User> {
|
|
221
|
+
try {
|
|
222
|
+
return await this.makeRequest<User>('PUT', `/api/users/${userId}`, updates, { cache: false });
|
|
223
|
+
} catch (error) {
|
|
224
|
+
throw this.handleError(error);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Follow a user
|
|
230
|
+
*/
|
|
231
|
+
async followUser(userId: string): Promise<{ success: boolean; message: string }> {
|
|
232
|
+
try {
|
|
233
|
+
return await this.makeRequest('POST', `/api/users/${userId}/follow`, undefined, { cache: false });
|
|
234
|
+
} catch (error) {
|
|
235
|
+
throw this.handleError(error);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Unfollow a user
|
|
241
|
+
*/
|
|
242
|
+
async unfollowUser(userId: string): Promise<{ success: boolean; message: string }> {
|
|
243
|
+
try {
|
|
244
|
+
return await this.makeRequest('DELETE', `/api/users/${userId}/follow`, undefined, { cache: false });
|
|
245
|
+
} catch (error) {
|
|
246
|
+
throw this.handleError(error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Get follow status
|
|
252
|
+
*/
|
|
253
|
+
async getFollowStatus(userId: string): Promise<{ isFollowing: boolean }> {
|
|
254
|
+
try {
|
|
255
|
+
return await this.makeRequest('GET', `/api/users/${userId}/follow-status`, undefined, {
|
|
256
|
+
cache: true,
|
|
257
|
+
cacheTTL: 1 * 60 * 1000, // 1 minute cache
|
|
258
|
+
});
|
|
259
|
+
} catch (error) {
|
|
260
|
+
throw this.handleError(error);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Get user followers
|
|
266
|
+
*/
|
|
267
|
+
async getUserFollowers(
|
|
268
|
+
userId: string,
|
|
269
|
+
pagination?: PaginationParams
|
|
270
|
+
): Promise<{ followers: User[]; total: number; hasMore: boolean }> {
|
|
271
|
+
try {
|
|
272
|
+
const params = buildPaginationParams(pagination || {});
|
|
273
|
+
const response = await this.makeRequest<{ data: User[]; pagination: { total: number; hasMore: boolean } }>('GET', `/api/users/${userId}/followers`, params, {
|
|
274
|
+
cache: true,
|
|
275
|
+
cacheTTL: 2 * 60 * 1000, // 2 minutes cache
|
|
276
|
+
});
|
|
277
|
+
return {
|
|
278
|
+
followers: response.data || [],
|
|
279
|
+
total: response.pagination.total,
|
|
280
|
+
hasMore: response.pagination.hasMore,
|
|
281
|
+
};
|
|
282
|
+
} catch (error) {
|
|
283
|
+
throw this.handleError(error);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Get user following
|
|
289
|
+
*/
|
|
290
|
+
async getUserFollowing(
|
|
291
|
+
userId: string,
|
|
292
|
+
pagination?: PaginationParams
|
|
293
|
+
): Promise<{ following: User[]; total: number; hasMore: boolean }> {
|
|
294
|
+
try {
|
|
295
|
+
const params = buildPaginationParams(pagination || {});
|
|
296
|
+
const response = await this.makeRequest<{ data: User[]; pagination: { total: number; hasMore: boolean } }>('GET', `/api/users/${userId}/following`, params, {
|
|
297
|
+
cache: true,
|
|
298
|
+
cacheTTL: 2 * 60 * 1000, // 2 minutes cache
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
following: response.data || [],
|
|
302
|
+
total: response.pagination.total,
|
|
303
|
+
hasMore: response.pagination.hasMore,
|
|
304
|
+
};
|
|
305
|
+
} catch (error) {
|
|
306
|
+
throw this.handleError(error);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Get notifications
|
|
312
|
+
*/
|
|
313
|
+
async getNotifications(): Promise<Notification[]> {
|
|
314
|
+
return this.withAuthRetry(async () => {
|
|
315
|
+
return await this.makeRequest<Notification[]>('GET', '/api/notifications', undefined, {
|
|
316
|
+
cache: false, // Don't cache notifications - always get fresh data
|
|
317
|
+
});
|
|
318
|
+
}, 'getNotifications');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Get unread notification count
|
|
323
|
+
*/
|
|
324
|
+
async getUnreadCount(): Promise<number> {
|
|
325
|
+
try {
|
|
326
|
+
const res = await this.makeRequest<{ count: number }>('GET', '/api/notifications/unread-count', undefined, {
|
|
327
|
+
cache: false, // Don't cache unread count - always get fresh data
|
|
328
|
+
});
|
|
329
|
+
return res.count;
|
|
330
|
+
} catch (error) {
|
|
331
|
+
throw this.handleError(error);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Create notification
|
|
337
|
+
*/
|
|
338
|
+
async createNotification(data: Partial<Notification>): Promise<Notification> {
|
|
339
|
+
try {
|
|
340
|
+
return await this.makeRequest<Notification>('POST', '/api/notifications', data, { cache: false });
|
|
341
|
+
} catch (error) {
|
|
342
|
+
throw this.handleError(error);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Mark notification as read
|
|
348
|
+
*/
|
|
349
|
+
async markNotificationAsRead(notificationId: string): Promise<void> {
|
|
350
|
+
try {
|
|
351
|
+
await this.makeRequest('PUT', `/api/notifications/${notificationId}/read`, undefined, { cache: false });
|
|
352
|
+
} catch (error) {
|
|
353
|
+
throw this.handleError(error);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Mark all notifications as read
|
|
359
|
+
*/
|
|
360
|
+
async markAllNotificationsAsRead(): Promise<void> {
|
|
361
|
+
try {
|
|
362
|
+
await this.makeRequest('PUT', '/api/notifications/read-all', undefined, { cache: false });
|
|
363
|
+
} catch (error) {
|
|
364
|
+
throw this.handleError(error);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Delete notification
|
|
370
|
+
*/
|
|
371
|
+
async deleteNotification(notificationId: string): Promise<void> {
|
|
372
|
+
try {
|
|
373
|
+
await this.makeRequest('DELETE', `/api/notifications/${notificationId}`, undefined, { cache: false });
|
|
374
|
+
} catch (error) {
|
|
375
|
+
throw this.handleError(error);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
@@ -0,0 +1,187 @@
|
|
|
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 type { ApiError, User } from '../../models/interfaces';
|
|
9
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
10
|
+
import { CACHE_TIMES } from './mixinHelpers';
|
|
11
|
+
|
|
12
|
+
interface JwtPayload {
|
|
13
|
+
exp?: number;
|
|
14
|
+
userId?: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function OxyServicesUtilityMixin<T extends typeof OxyServicesBase>(Base: T) {
|
|
21
|
+
return class extends Base {
|
|
22
|
+
constructor(...args: any[]) {
|
|
23
|
+
super(...(args as [any]));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fetch link metadata
|
|
27
|
+
*/
|
|
28
|
+
async fetchLinkMetadata(url: string): Promise<{
|
|
29
|
+
url: string;
|
|
30
|
+
title: string;
|
|
31
|
+
description: string;
|
|
32
|
+
image?: string;
|
|
33
|
+
}> {
|
|
34
|
+
try {
|
|
35
|
+
return await this.makeRequest<{
|
|
36
|
+
url: string;
|
|
37
|
+
title: string;
|
|
38
|
+
description: string;
|
|
39
|
+
image?: string;
|
|
40
|
+
}>('GET', '/api/link-metadata', { url }, {
|
|
41
|
+
cache: true,
|
|
42
|
+
cacheTTL: CACHE_TIMES.EXTRA_LONG,
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw this.handleError(error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Simple Express.js authentication middleware
|
|
51
|
+
*
|
|
52
|
+
* Built-in authentication middleware that validates JWT tokens and adds user data to requests.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Basic usage - just add it to your routes
|
|
57
|
+
* app.use('/api/protected', oxyServices.auth());
|
|
58
|
+
*
|
|
59
|
+
* // With debug logging
|
|
60
|
+
* app.use('/api/protected', oxyServices.auth({ debug: true }));
|
|
61
|
+
*
|
|
62
|
+
* // With custom error handling
|
|
63
|
+
* app.use('/api/protected', oxyServices.auth({
|
|
64
|
+
* onError: (error) => console.error('Auth failed:', error)
|
|
65
|
+
* }));
|
|
66
|
+
*
|
|
67
|
+
* // Load full user data
|
|
68
|
+
* app.use('/api/protected', oxyServices.auth({ loadUser: true }));
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @param options Optional configuration
|
|
72
|
+
* @param options.debug Enable debug logging (default: false)
|
|
73
|
+
* @param options.onError Custom error handler
|
|
74
|
+
* @param options.loadUser Load full user data (default: false for performance)
|
|
75
|
+
* @param options.session Use session-based validation (default: false)
|
|
76
|
+
* @returns Express middleware function
|
|
77
|
+
*/
|
|
78
|
+
auth(options: {
|
|
79
|
+
debug?: boolean;
|
|
80
|
+
onError?: (error: ApiError) => any;
|
|
81
|
+
loadUser?: boolean;
|
|
82
|
+
session?: boolean;
|
|
83
|
+
} = {}) {
|
|
84
|
+
const { debug = false, onError, loadUser = false, session = false } = options;
|
|
85
|
+
|
|
86
|
+
// Return a synchronous middleware function
|
|
87
|
+
return (req: any, res: any, next: any) => {
|
|
88
|
+
try {
|
|
89
|
+
// Extract token from Authorization header
|
|
90
|
+
const authHeader = req.headers['authorization'];
|
|
91
|
+
const token = authHeader?.startsWith('Bearer ') ? authHeader.substring(7) : null;
|
|
92
|
+
|
|
93
|
+
if (debug) {
|
|
94
|
+
console.log(`🔐 Auth: Processing ${req.method} ${req.path}`);
|
|
95
|
+
console.log(`🔐 Auth: Token present: ${!!token}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!token) {
|
|
99
|
+
const error = {
|
|
100
|
+
message: 'Access token required',
|
|
101
|
+
code: 'MISSING_TOKEN',
|
|
102
|
+
status: 401
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
if (debug) console.log(`❌ Auth: Missing token`);
|
|
106
|
+
|
|
107
|
+
if (onError) return onError(error);
|
|
108
|
+
return res.status(401).json(error);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Decode and validate token
|
|
112
|
+
let decoded: JwtPayload;
|
|
113
|
+
try {
|
|
114
|
+
decoded = jwtDecode<JwtPayload>(token);
|
|
115
|
+
|
|
116
|
+
if (debug) {
|
|
117
|
+
console.log(`🔐 Auth: Token decoded, User ID: ${decoded.userId || decoded.id}`);
|
|
118
|
+
}
|
|
119
|
+
} catch (decodeError) {
|
|
120
|
+
const error = {
|
|
121
|
+
message: 'Invalid token format',
|
|
122
|
+
code: 'INVALID_TOKEN_FORMAT',
|
|
123
|
+
status: 403
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
if (debug) console.log(`❌ Auth: Token decode failed`);
|
|
127
|
+
|
|
128
|
+
if (onError) return onError(error);
|
|
129
|
+
return res.status(403).json(error);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const userId = decoded.userId || decoded.id;
|
|
133
|
+
if (!userId) {
|
|
134
|
+
const error = {
|
|
135
|
+
message: 'Token missing user ID',
|
|
136
|
+
code: 'INVALID_TOKEN_PAYLOAD',
|
|
137
|
+
status: 403
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
if (debug) console.log(`❌ Auth: Token missing user ID`);
|
|
141
|
+
|
|
142
|
+
if (onError) return onError(error);
|
|
143
|
+
return res.status(403).json(error);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Check token expiration
|
|
147
|
+
if (decoded.exp && decoded.exp < Math.floor(Date.now() / 1000)) {
|
|
148
|
+
const error = {
|
|
149
|
+
message: 'Token expired',
|
|
150
|
+
code: 'TOKEN_EXPIRED',
|
|
151
|
+
status: 403
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
if (debug) console.log(`❌ Auth: Token expired`);
|
|
155
|
+
|
|
156
|
+
if (onError) return onError(error);
|
|
157
|
+
return res.status(403).json(error);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// For now, skip session validation to keep it simple
|
|
161
|
+
// Session validation can be added later if needed
|
|
162
|
+
|
|
163
|
+
// Set request properties immediately
|
|
164
|
+
req.userId = userId;
|
|
165
|
+
req.accessToken = token;
|
|
166
|
+
req.user = { id: userId } as User;
|
|
167
|
+
|
|
168
|
+
if (debug) {
|
|
169
|
+
console.log(`✅ Auth: Authentication successful for user ${userId}`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
next();
|
|
173
|
+
} catch (error) {
|
|
174
|
+
const apiError = this.handleError(error) as any;
|
|
175
|
+
|
|
176
|
+
if (debug) {
|
|
177
|
+
console.log(`❌ Auth: Unexpected error:`, apiError);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (onError) return onError(apiError);
|
|
181
|
+
return res.status((apiError && apiError.status) || 500).json(apiError);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
|
|
8
|
+
import { OxyServicesBase } from '../OxyServices.base';
|
|
9
|
+
import { OxyServicesAuthMixin } from './OxyServices.auth';
|
|
10
|
+
import { OxyServicesUserMixin } from './OxyServices.user';
|
|
11
|
+
import { OxyServicesTotpMixin } from './OxyServices.totp';
|
|
12
|
+
import { OxyServicesPrivacyMixin } from './OxyServices.privacy';
|
|
13
|
+
import { OxyServicesLanguageMixin } from './OxyServices.language';
|
|
14
|
+
import { OxyServicesPaymentMixin } from './OxyServices.payment';
|
|
15
|
+
import { OxyServicesKarmaMixin } from './OxyServices.karma';
|
|
16
|
+
import { OxyServicesAssetsMixin } from './OxyServices.assets';
|
|
17
|
+
import { OxyServicesDeveloperMixin } from './OxyServices.developer';
|
|
18
|
+
import { OxyServicesLocationMixin } from './OxyServices.location';
|
|
19
|
+
import { OxyServicesAnalyticsMixin } from './OxyServices.analytics';
|
|
20
|
+
import { OxyServicesDevicesMixin } from './OxyServices.devices';
|
|
21
|
+
import { OxyServicesUtilityMixin } from './OxyServices.utility';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Composes all OxyServices mixins in the correct order
|
|
25
|
+
*
|
|
26
|
+
* Order matters for mixins - dependencies should be applied first.
|
|
27
|
+
* This function ensures consistent composition across the codebase.
|
|
28
|
+
*
|
|
29
|
+
* @returns The fully composed OxyServices class with all mixins applied
|
|
30
|
+
*/
|
|
31
|
+
export function composeOxyServices() {
|
|
32
|
+
return OxyServicesUtilityMixin(
|
|
33
|
+
OxyServicesDevicesMixin(
|
|
34
|
+
OxyServicesAnalyticsMixin(
|
|
35
|
+
OxyServicesLocationMixin(
|
|
36
|
+
OxyServicesDeveloperMixin(
|
|
37
|
+
OxyServicesAssetsMixin(
|
|
38
|
+
OxyServicesKarmaMixin(
|
|
39
|
+
OxyServicesPaymentMixin(
|
|
40
|
+
OxyServicesLanguageMixin(
|
|
41
|
+
OxyServicesPrivacyMixin(
|
|
42
|
+
OxyServicesTotpMixin(
|
|
43
|
+
OxyServicesUserMixin(
|
|
44
|
+
OxyServicesAuthMixin(OxyServicesBase)
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for mixin classes
|
|
3
|
+
* Provides common patterns to reduce code duplication
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wraps an async method with standard error handling
|
|
10
|
+
* Reduces boilerplate in mixin methods
|
|
11
|
+
*/
|
|
12
|
+
export async function withErrorHandling<T>(
|
|
13
|
+
operation: () => Promise<T>,
|
|
14
|
+
handleError: (error: any) => Error
|
|
15
|
+
): Promise<T> {
|
|
16
|
+
try {
|
|
17
|
+
return await operation();
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw handleError(error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a standard API request method with error handling
|
|
25
|
+
* Reduces duplication across mixin methods
|
|
26
|
+
*/
|
|
27
|
+
export function createApiMethod<T>(
|
|
28
|
+
makeRequest: OxyServicesBase['makeRequest'],
|
|
29
|
+
handleError: OxyServicesBase['handleError'],
|
|
30
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
|
|
31
|
+
url: string | ((...args: any[]) => string),
|
|
32
|
+
options: {
|
|
33
|
+
cache?: boolean;
|
|
34
|
+
cacheTTL?: number;
|
|
35
|
+
retry?: boolean;
|
|
36
|
+
transformData?: (data: any) => any;
|
|
37
|
+
transformResponse?: (response: any) => T;
|
|
38
|
+
} = {}
|
|
39
|
+
) {
|
|
40
|
+
return async (...args: any[]): Promise<T> => {
|
|
41
|
+
const urlString = typeof url === 'function' ? url(...args) : url;
|
|
42
|
+
const requestData = options.transformData ? options.transformData(args) : args[0];
|
|
43
|
+
|
|
44
|
+
const requestOptions = {
|
|
45
|
+
cache: options.cache ?? true,
|
|
46
|
+
cacheTTL: options.cacheTTL,
|
|
47
|
+
retry: options.retry ?? true,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const response = await makeRequest<T>(method, urlString, requestData, requestOptions);
|
|
52
|
+
return options.transformResponse ? options.transformResponse(response) : response;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw handleError(error);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Cache time constants (in milliseconds)
|
|
61
|
+
*/
|
|
62
|
+
export const CACHE_TIMES = {
|
|
63
|
+
SHORT: 1 * 60 * 1000, // 1 minute
|
|
64
|
+
MEDIUM: 2 * 60 * 1000, // 2 minutes
|
|
65
|
+
LONG: 5 * 60 * 1000, // 5 minutes
|
|
66
|
+
VERY_LONG: 10 * 60 * 1000, // 10 minutes
|
|
67
|
+
EXTRA_LONG: 30 * 60 * 1000, // 30 minutes
|
|
68
|
+
} as const;
|
|
69
|
+
|
package/src/index.ts
CHANGED