@oxyhq/services 0.1.17 → 5.1.7

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.
Files changed (183) hide show
  1. package/README.md +17 -138
  2. package/UI_COMPONENTS.md +142 -0
  3. package/lib/commonjs/assets/OxyLogo.svg +1 -0
  4. package/lib/commonjs/assets/assets/OxyLogo.svg +1 -0
  5. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
  6. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
  7. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
  8. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
  9. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
  10. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
  11. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
  12. package/lib/commonjs/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
  13. package/lib/commonjs/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
  14. package/lib/commonjs/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
  15. package/lib/commonjs/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
  16. package/lib/commonjs/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
  17. package/lib/commonjs/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
  18. package/lib/commonjs/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
  19. package/lib/commonjs/core/index.js +783 -0
  20. package/lib/commonjs/core/index.js.map +1 -0
  21. package/lib/commonjs/index.js +128 -0
  22. package/lib/commonjs/index.js.map +1 -0
  23. package/lib/commonjs/models/interfaces.js +2 -0
  24. package/lib/commonjs/models/interfaces.js.map +1 -0
  25. package/lib/commonjs/package.json +1 -0
  26. package/lib/commonjs/ui/components/FontLoader.js +181 -0
  27. package/lib/commonjs/ui/components/FontLoader.js.map +1 -0
  28. package/lib/commonjs/ui/components/OxyLogo.js +56 -0
  29. package/lib/commonjs/ui/components/OxyLogo.js.map +1 -0
  30. package/lib/commonjs/ui/components/OxyProvider.js +464 -0
  31. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -0
  32. package/lib/commonjs/ui/components/OxySignInButton.js +178 -0
  33. package/lib/commonjs/ui/components/OxySignInButton.js.map +1 -0
  34. package/lib/commonjs/ui/components/bottomSheet/index.js +37 -0
  35. package/lib/commonjs/ui/components/bottomSheet/index.js.map +1 -0
  36. package/lib/commonjs/ui/context/OxyContext.js +296 -0
  37. package/lib/commonjs/ui/context/OxyContext.js.map +1 -0
  38. package/lib/commonjs/ui/index.js +136 -0
  39. package/lib/commonjs/ui/index.js.map +1 -0
  40. package/lib/commonjs/ui/navigation/OxyRouter.js +140 -0
  41. package/lib/commonjs/ui/navigation/OxyRouter.js.map +1 -0
  42. package/lib/commonjs/ui/navigation/types.js +6 -0
  43. package/lib/commonjs/ui/navigation/types.js.map +1 -0
  44. package/lib/commonjs/ui/screens/AccountCenterScreen.js +280 -0
  45. package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -0
  46. package/lib/commonjs/ui/screens/AccountOverviewScreen.js +578 -0
  47. package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -0
  48. package/lib/commonjs/ui/screens/SignInScreen.js +230 -0
  49. package/lib/commonjs/ui/screens/SignInScreen.js.map +1 -0
  50. package/lib/commonjs/ui/screens/SignUpScreen.js +673 -0
  51. package/lib/commonjs/ui/screens/SignUpScreen.js.map +1 -0
  52. package/lib/commonjs/ui/styles/FONTS.md +126 -0
  53. package/lib/commonjs/ui/styles/fonts.js +84 -0
  54. package/lib/commonjs/ui/styles/fonts.js.map +1 -0
  55. package/lib/commonjs/ui/styles/index.js +28 -0
  56. package/lib/commonjs/ui/styles/index.js.map +1 -0
  57. package/lib/commonjs/ui/styles/theme.js +122 -0
  58. package/lib/commonjs/ui/styles/theme.js.map +1 -0
  59. package/lib/module/assets/OxyLogo.svg +1 -0
  60. package/lib/module/assets/assets/OxyLogo.svg +1 -0
  61. package/lib/module/assets/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
  62. package/lib/module/assets/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
  63. package/lib/module/assets/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
  64. package/lib/module/assets/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
  65. package/lib/module/assets/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
  66. package/lib/module/assets/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
  67. package/lib/module/assets/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
  68. package/lib/module/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
  69. package/lib/module/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
  70. package/lib/module/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
  71. package/lib/module/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
  72. package/lib/module/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
  73. package/lib/module/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
  74. package/lib/module/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
  75. package/lib/module/core/index.js +777 -0
  76. package/lib/module/core/index.js.map +1 -0
  77. package/lib/module/index.js +29 -0
  78. package/lib/module/index.js.map +1 -0
  79. package/lib/module/models/interfaces.js +2 -0
  80. package/lib/module/models/interfaces.js.map +1 -0
  81. package/lib/module/package.json +1 -0
  82. package/lib/module/ui/components/FontLoader.js +176 -0
  83. package/lib/module/ui/components/FontLoader.js.map +1 -0
  84. package/lib/module/ui/components/OxyLogo.js +49 -0
  85. package/lib/module/ui/components/OxyLogo.js.map +1 -0
  86. package/lib/module/ui/components/OxyProvider.js +458 -0
  87. package/lib/module/ui/components/OxyProvider.js.map +1 -0
  88. package/lib/module/ui/components/OxySignInButton.js +172 -0
  89. package/lib/module/ui/components/OxySignInButton.js.map +1 -0
  90. package/lib/module/ui/components/bottomSheet/index.js +8 -0
  91. package/lib/module/ui/components/bottomSheet/index.js.map +1 -0
  92. package/lib/module/ui/context/OxyContext.js +291 -0
  93. package/lib/module/ui/context/OxyContext.js.map +1 -0
  94. package/lib/module/ui/index.js +25 -0
  95. package/lib/module/ui/index.js.map +1 -0
  96. package/lib/module/ui/navigation/OxyRouter.js +133 -0
  97. package/lib/module/ui/navigation/OxyRouter.js.map +1 -0
  98. package/lib/module/ui/navigation/types.js +4 -0
  99. package/lib/module/ui/navigation/types.js.map +1 -0
  100. package/lib/module/ui/screens/AccountCenterScreen.js +275 -0
  101. package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -0
  102. package/lib/module/ui/screens/AccountOverviewScreen.js +573 -0
  103. package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -0
  104. package/lib/module/ui/screens/SignInScreen.js +224 -0
  105. package/lib/module/ui/screens/SignInScreen.js.map +1 -0
  106. package/lib/module/ui/screens/SignUpScreen.js +668 -0
  107. package/lib/module/ui/screens/SignUpScreen.js.map +1 -0
  108. package/lib/module/ui/styles/FONTS.md +126 -0
  109. package/lib/module/ui/styles/fonts.js +81 -0
  110. package/lib/module/ui/styles/fonts.js.map +1 -0
  111. package/lib/module/ui/styles/index.js +5 -0
  112. package/lib/module/ui/styles/index.js.map +1 -0
  113. package/lib/module/ui/styles/theme.js +115 -0
  114. package/lib/module/ui/styles/theme.js.map +1 -0
  115. package/lib/typescript/core/index.d.ts +304 -0
  116. package/lib/typescript/core/index.d.ts.map +1 -0
  117. package/lib/typescript/index.d.ts +11 -0
  118. package/lib/typescript/index.d.ts.map +1 -0
  119. package/lib/typescript/models/interfaces.d.ts +98 -0
  120. package/lib/typescript/models/interfaces.d.ts.map +1 -0
  121. package/lib/typescript/ui/components/FontLoader.d.ts +15 -0
  122. package/lib/typescript/ui/components/FontLoader.d.ts.map +1 -0
  123. package/lib/typescript/ui/components/OxyLogo.d.ts +29 -0
  124. package/lib/typescript/ui/components/OxyLogo.d.ts.map +1 -0
  125. package/lib/typescript/ui/components/OxyProvider.d.ts +12 -0
  126. package/lib/typescript/ui/components/OxyProvider.d.ts.map +1 -0
  127. package/lib/typescript/ui/components/OxySignInButton.d.ts +65 -0
  128. package/lib/typescript/ui/components/OxySignInButton.d.ts.map +1 -0
  129. package/lib/typescript/ui/components/bottomSheet/index.d.ts +3 -0
  130. package/lib/typescript/ui/components/bottomSheet/index.d.ts.map +1 -0
  131. package/lib/typescript/ui/context/OxyContext.d.ts +26 -0
  132. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -0
  133. package/lib/typescript/ui/index.d.ts +15 -0
  134. package/lib/typescript/ui/index.d.ts.map +1 -0
  135. package/lib/typescript/ui/navigation/OxyRouter.d.ts +5 -0
  136. package/lib/typescript/ui/navigation/OxyRouter.d.ts.map +1 -0
  137. package/lib/typescript/ui/navigation/types.d.ts +107 -0
  138. package/lib/typescript/ui/navigation/types.d.ts.map +1 -0
  139. package/lib/typescript/ui/screens/AccountCenterScreen.d.ts +5 -0
  140. package/lib/typescript/ui/screens/AccountCenterScreen.d.ts.map +1 -0
  141. package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts +5 -0
  142. package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts.map +1 -0
  143. package/lib/typescript/ui/screens/SignInScreen.d.ts +5 -0
  144. package/lib/typescript/ui/screens/SignInScreen.d.ts.map +1 -0
  145. package/lib/typescript/ui/screens/SignUpScreen.d.ts +5 -0
  146. package/lib/typescript/ui/screens/SignUpScreen.d.ts.map +1 -0
  147. package/lib/typescript/ui/styles/fonts.d.ts +21 -0
  148. package/lib/typescript/ui/styles/fonts.d.ts.map +1 -0
  149. package/lib/typescript/ui/styles/index.d.ts +3 -0
  150. package/lib/typescript/ui/styles/index.d.ts.map +1 -0
  151. package/lib/typescript/ui/styles/theme.d.ts +69 -0
  152. package/lib/typescript/ui/styles/theme.d.ts.map +1 -0
  153. package/package.json +95 -51
  154. package/src/assets/OxyLogo.svg +1 -0
  155. package/src/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
  156. package/src/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
  157. package/src/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
  158. package/src/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
  159. package/src/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
  160. package/src/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
  161. package/src/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
  162. package/src/core/index.ts +768 -0
  163. package/src/index.ts +46 -0
  164. package/src/models/interfaces.ts +128 -0
  165. package/src/ui/components/FontLoader.tsx +180 -0
  166. package/src/ui/components/OxyLogo.tsx +73 -0
  167. package/src/ui/components/OxyProvider.tsx +490 -0
  168. package/src/ui/components/OxySignInButton.tsx +207 -0
  169. package/src/ui/components/bottomSheet/index.tsx +12 -0
  170. package/src/ui/context/OxyContext.tsx +344 -0
  171. package/src/ui/index.ts +27 -0
  172. package/src/ui/navigation/OxyRouter.tsx +137 -0
  173. package/src/ui/navigation/types.ts +124 -0
  174. package/src/ui/screens/AccountCenterScreen.tsx +240 -0
  175. package/src/ui/screens/AccountOverviewScreen.tsx +519 -0
  176. package/src/ui/screens/SignInScreen.tsx +210 -0
  177. package/src/ui/screens/SignUpScreen.tsx +607 -0
  178. package/src/ui/styles/FONTS.md +126 -0
  179. package/src/ui/styles/fonts.ts +77 -0
  180. package/src/ui/styles/index.ts +2 -0
  181. package/src/ui/styles/theme.ts +142 -0
  182. package/dist/index.d.ts +0 -152
  183. package/dist/index.js +0 -1
@@ -0,0 +1,777 @@
1
+ "use strict";
2
+
3
+ import axios from 'axios';
4
+ import { jwtDecode } from 'jwt-decode';
5
+ /**
6
+ * OxyServices - Client library for interacting with the Oxy API
7
+ */
8
+ export class OxyServices {
9
+ accessToken = null;
10
+ refreshToken = null;
11
+ refreshPromise = null;
12
+
13
+ /**
14
+ * Creates a new instance of the OxyServices client
15
+ * @param config - Configuration for the client
16
+ */
17
+ constructor(config) {
18
+ this.client = axios.create({
19
+ baseURL: config.baseURL,
20
+ timeout: 10000 // 10 second timeout
21
+ });
22
+
23
+ // Interceptor for adding auth header and handling token refresh
24
+ this.client.interceptors.request.use(async req => {
25
+ if (!this.accessToken) {
26
+ return req;
27
+ } // Check if token is expired and refresh if needed
28
+ try {
29
+ const decoded = jwtDecode(this.accessToken);
30
+ const currentTime = Math.floor(Date.now() / 1000);
31
+
32
+ // If token expires in less than 60 seconds, refresh it
33
+ if (decoded.exp - currentTime < 60) {
34
+ await this.refreshTokens();
35
+ }
36
+ } catch (error) {
37
+ // If token can't be decoded, continue with request and let server handle it
38
+ console.warn('Error decoding JWT token', error);
39
+ }
40
+ req.headers = req.headers || {};
41
+ req.headers.Authorization = `Bearer ${this.accessToken}`;
42
+ return req;
43
+ });
44
+
45
+ // Response interceptor for handling errors
46
+ this.client.interceptors.response.use(response => response, async error => {
47
+ const originalRequest = error.config;
48
+
49
+ // If the error is due to an expired token and we haven't tried refreshing yet
50
+ if (error.response?.status === 401 && this.refreshToken && originalRequest && !originalRequest.headers?.['X-Retry-After-Refresh']) {
51
+ try {
52
+ await this.refreshTokens();
53
+
54
+ // Retry the original request with new token
55
+ const newRequest = {
56
+ ...originalRequest
57
+ };
58
+ if (newRequest.headers) {
59
+ newRequest.headers.Authorization = `Bearer ${this.accessToken}`;
60
+ newRequest.headers['X-Retry-After-Refresh'] = 'true';
61
+ }
62
+ return this.client(newRequest);
63
+ } catch (refreshError) {
64
+ // If refresh fails, force user to login again
65
+ this.accessToken = null;
66
+ this.refreshToken = null;
67
+ return Promise.reject(refreshError);
68
+ }
69
+ }
70
+
71
+ // Format error response
72
+ const apiError = {
73
+ message: error.response?.data?.message || 'An unknown error occurred',
74
+ code: error.response?.data?.code || 'UNKNOWN_ERROR',
75
+ status: error.response?.status || 500,
76
+ details: error.response?.data
77
+ };
78
+ return Promise.reject(apiError);
79
+ });
80
+ }
81
+
82
+ /**
83
+ * Gets the currently authenticated user ID from the token
84
+ * @returns The user ID or null if not authenticated
85
+ */
86
+ getCurrentUserId() {
87
+ if (!this.accessToken) return null;
88
+ try {
89
+ const decoded = jwtDecode(this.accessToken);
90
+ return decoded.userId;
91
+ } catch {
92
+ return null;
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Checks if the user is currently authenticated
98
+ * @returns Boolean indicating authentication status
99
+ */
100
+ isAuthenticated() {
101
+ return this.accessToken !== null;
102
+ }
103
+
104
+ /**
105
+ * Sets authentication tokens directly (useful for initializing from storage)
106
+ * @param accessToken - JWT access token
107
+ * @param refreshToken - Refresh token for getting new access tokens
108
+ */
109
+ setTokens(accessToken, refreshToken) {
110
+ this.accessToken = accessToken;
111
+ this.refreshToken = refreshToken;
112
+ }
113
+
114
+ /**
115
+ * Clears all authentication tokens
116
+ */
117
+ clearTokens() {
118
+ this.accessToken = null;
119
+ this.refreshToken = null;
120
+ }
121
+
122
+ /**
123
+ * Sign up a new user
124
+ * @param username - Desired username
125
+ * @param email - User's email address
126
+ * @param password - User's password
127
+ * @returns Object containing the message, token and user data
128
+ */
129
+ async signUp(username, email, password) {
130
+ try {
131
+ const res = await this.client.post('/auth/signup', {
132
+ username,
133
+ email,
134
+ password
135
+ });
136
+ const {
137
+ message,
138
+ token,
139
+ user
140
+ } = res.data;
141
+ this.accessToken = token;
142
+ return {
143
+ message,
144
+ token,
145
+ user
146
+ };
147
+ } catch (error) {
148
+ throw this.handleError(error);
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Log in and store tokens
154
+ * @param username - User's username or email
155
+ * @param password - User's password
156
+ * @returns Login response containing tokens and user data
157
+ */
158
+ async login(username, password) {
159
+ try {
160
+ const res = await this.client.post('/auth/login', {
161
+ username,
162
+ password
163
+ });
164
+ const {
165
+ accessToken,
166
+ refreshToken,
167
+ user
168
+ } = res.data;
169
+ this.accessToken = accessToken;
170
+ this.refreshToken = refreshToken;
171
+ return {
172
+ accessToken,
173
+ refreshToken,
174
+ user
175
+ };
176
+ } catch (error) {
177
+ throw this.handleError(error);
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Log out user
183
+ */
184
+ async logout() {
185
+ if (!this.refreshToken) return;
186
+ try {
187
+ await this.client.post('/auth/logout', {
188
+ refreshToken: this.refreshToken
189
+ });
190
+ } catch (error) {
191
+ console.warn('Error during logout', error);
192
+ } finally {
193
+ this.accessToken = null;
194
+ this.refreshToken = null;
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Refresh access and refresh tokens
200
+ * @returns New tokens
201
+ */
202
+ async refreshTokens() {
203
+ if (!this.refreshToken) {
204
+ throw new Error('No refresh token available');
205
+ }
206
+
207
+ // If a refresh is already in progress, return that promise
208
+ if (this.refreshPromise) {
209
+ return this.refreshPromise;
210
+ }
211
+
212
+ // Create a new refresh promise
213
+ this.refreshPromise = (async () => {
214
+ try {
215
+ const res = await this.client.post('/auth/refresh', {
216
+ refreshToken: this.refreshToken
217
+ });
218
+ const {
219
+ accessToken,
220
+ refreshToken
221
+ } = res.data;
222
+ this.accessToken = accessToken;
223
+ this.refreshToken = refreshToken;
224
+ return {
225
+ accessToken,
226
+ refreshToken
227
+ };
228
+ } catch (error) {
229
+ this.accessToken = null;
230
+ this.refreshToken = null;
231
+ throw this.handleError(error);
232
+ } finally {
233
+ this.refreshPromise = null;
234
+ }
235
+ })();
236
+ return this.refreshPromise;
237
+ }
238
+
239
+ /**
240
+ * Validate current access token
241
+ * @returns Boolean indicating if the token is valid
242
+ */
243
+ async validate() {
244
+ try {
245
+ const res = await this.client.get('/auth/validate');
246
+ return res.data.valid;
247
+ } catch (error) {
248
+ return false;
249
+ }
250
+ }
251
+
252
+ /* Profile Methods */
253
+
254
+ /**
255
+ * Fetch profile by username
256
+ * @param username - The username to look up
257
+ * @returns User profile data
258
+ */
259
+ async getProfileByUsername(username) {
260
+ try {
261
+ const res = await this.client.get(`/profiles/username/${username}`);
262
+ return res.data;
263
+ } catch (error) {
264
+ throw this.handleError(error);
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Search profiles
270
+ * @param query - Search query string
271
+ * @param limit - Maximum number of results to return
272
+ * @param offset - Number of results to skip for pagination
273
+ * @returns Array of matching user profiles
274
+ */
275
+ async searchProfiles(query, limit, offset) {
276
+ try {
277
+ const params = {
278
+ query
279
+ };
280
+ if (limit !== undefined) params.limit = limit;
281
+ if (offset !== undefined) params.offset = offset;
282
+ const res = await this.client.get('/profiles/search', {
283
+ params
284
+ });
285
+ return res.data;
286
+ } catch (error) {
287
+ throw this.handleError(error);
288
+ }
289
+ }
290
+
291
+ /* User Methods */
292
+
293
+ /**
294
+ * Get general user by ID
295
+ * @param userId - The user ID to look up
296
+ * @returns User data
297
+ */
298
+ async getUserById(userId) {
299
+ try {
300
+ const res = await this.client.get(`/users/${userId}`);
301
+ return res.data;
302
+ } catch (error) {
303
+ throw this.handleError(error);
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Update user profile (requires auth)
309
+ * @param userId - User ID to update (must match authenticated user or have admin rights)
310
+ * @param updates - Object containing fields to update
311
+ * @returns Updated user data
312
+ */
313
+ async updateUser(userId, updates) {
314
+ try {
315
+ const res = await this.client.put(`/users/${userId}`, updates);
316
+ return res.data;
317
+ } catch (error) {
318
+ throw this.handleError(error);
319
+ }
320
+ }
321
+
322
+ /**
323
+ * Follow a user
324
+ * @param userId - User ID to follow
325
+ * @returns Status of the follow operation
326
+ */
327
+ async followUser(userId) {
328
+ try {
329
+ const res = await this.client.post(`/users/${userId}/follow`);
330
+ return res.data;
331
+ } catch (error) {
332
+ throw this.handleError(error);
333
+ }
334
+ }
335
+
336
+ /**
337
+ * Unfollow a user
338
+ * @param userId - User ID to unfollow
339
+ * @returns Status of the unfollow operation
340
+ */
341
+ async unfollowUser(userId) {
342
+ try {
343
+ const res = await this.client.delete(`/users/${userId}/follow`);
344
+ return res.data;
345
+ } catch (error) {
346
+ throw this.handleError(error);
347
+ }
348
+ }
349
+
350
+ /* Notification Methods */
351
+
352
+ /**
353
+ * Fetch all notifications for the authenticated user
354
+ * @returns Array of notifications
355
+ */
356
+ async getNotifications() {
357
+ try {
358
+ const res = await this.client.get('/notifications');
359
+ return res.data;
360
+ } catch (error) {
361
+ throw this.handleError(error);
362
+ }
363
+ }
364
+
365
+ /**
366
+ * Get count of unread notifications
367
+ * @returns Number of unread notifications
368
+ */
369
+ async getUnreadCount() {
370
+ try {
371
+ const res = await this.client.get('/notifications/unread-count');
372
+ return res.data;
373
+ } catch (error) {
374
+ throw this.handleError(error);
375
+ }
376
+ }
377
+
378
+ /**
379
+ * Create a new notification (admin use)
380
+ * @param data - Notification data
381
+ * @returns Created notification
382
+ */
383
+ async createNotification(data) {
384
+ try {
385
+ const res = await this.client.post('/notifications', data);
386
+ return res.data;
387
+ } catch (error) {
388
+ throw this.handleError(error);
389
+ }
390
+ }
391
+
392
+ /**
393
+ * Mark a single notification as read
394
+ * @param notificationId - ID of notification to mark as read
395
+ */
396
+ async markNotificationAsRead(notificationId) {
397
+ try {
398
+ await this.client.put(`/notifications/${notificationId}/read`);
399
+ } catch (error) {
400
+ throw this.handleError(error);
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Mark all notifications as read
406
+ */
407
+ async markAllNotificationsAsRead() {
408
+ try {
409
+ await this.client.put('/notifications/read-all');
410
+ } catch (error) {
411
+ throw this.handleError(error);
412
+ }
413
+ }
414
+
415
+ /**
416
+ * Delete a notification
417
+ * @param notificationId - ID of notification to delete
418
+ */
419
+ async deleteNotification(notificationId) {
420
+ try {
421
+ await this.client.delete(`/notifications/${notificationId}`);
422
+ } catch (error) {
423
+ throw this.handleError(error);
424
+ }
425
+ }
426
+
427
+ /* Payment Methods */
428
+
429
+ /**
430
+ * Process a payment
431
+ * @param data - Payment data including user ID, plan, and payment method
432
+ * @returns Payment result with transaction ID
433
+ */
434
+ async processPayment(data) {
435
+ try {
436
+ const res = await this.client.post('/payments/process', data);
437
+ return res.data;
438
+ } catch (error) {
439
+ throw this.handleError(error);
440
+ }
441
+ }
442
+
443
+ /**
444
+ * Validate a payment method
445
+ * @param paymentMethod - Payment method to validate
446
+ * @returns Object indicating if the payment method is valid
447
+ */
448
+ async validatePaymentMethod(paymentMethod) {
449
+ try {
450
+ const res = await this.client.post('/payments/validate', {
451
+ paymentMethod
452
+ });
453
+ return res.data;
454
+ } catch (error) {
455
+ throw this.handleError(error);
456
+ }
457
+ }
458
+
459
+ /**
460
+ * Get saved payment methods for a user
461
+ * @param userId - User ID to get payment methods for
462
+ * @returns Array of payment methods
463
+ */
464
+ async getPaymentMethods(userId) {
465
+ try {
466
+ const res = await this.client.get(`/payments/methods/${userId}`);
467
+ return res.data;
468
+ } catch (error) {
469
+ throw this.handleError(error);
470
+ }
471
+ }
472
+
473
+ /* Analytics Methods */
474
+
475
+ /**
476
+ * Get analytics data
477
+ * @param userId - User ID to get analytics for
478
+ * @param period - Time period for analytics (e.g., "day", "week", "month")
479
+ * @returns Analytics data
480
+ */
481
+ async getAnalytics(userId, period) {
482
+ try {
483
+ const params = {
484
+ userID: userId
485
+ };
486
+ if (period) params.period = period;
487
+ const res = await this.client.get('/analytics', {
488
+ params
489
+ });
490
+ return res.data;
491
+ } catch (error) {
492
+ throw this.handleError(error);
493
+ }
494
+ }
495
+
496
+ /**
497
+ * Update analytics (internal use)
498
+ * @param userId - User ID to update analytics for
499
+ * @param type - Type of analytics to update
500
+ * @param data - Analytics data to update
501
+ * @returns Message indicating success
502
+ */
503
+ async updateAnalytics(userId, type, data) {
504
+ try {
505
+ const res = await this.client.post('/analytics/update', {
506
+ userID: userId,
507
+ type,
508
+ data
509
+ });
510
+ return res.data;
511
+ } catch (error) {
512
+ throw this.handleError(error);
513
+ }
514
+ }
515
+
516
+ /**
517
+ * Get content viewers analytics
518
+ * @param userId - User ID to get viewer data for
519
+ * @param period - Time period for analytics
520
+ * @returns Array of content viewer data
521
+ */
522
+ async getContentViewers(userId, period) {
523
+ try {
524
+ const params = {
525
+ userID: userId
526
+ };
527
+ if (period) params.period = period;
528
+ const res = await this.client.get('/analytics/viewers', {
529
+ params
530
+ });
531
+ return res.data;
532
+ } catch (error) {
533
+ throw this.handleError(error);
534
+ }
535
+ }
536
+
537
+ /**
538
+ * Get follower analytics details
539
+ * @param userId - User ID to get follower data for
540
+ * @param period - Time period for follower data
541
+ * @returns Follower details
542
+ */
543
+ async getFollowerDetails(userId, period) {
544
+ try {
545
+ const params = {
546
+ userID: userId
547
+ };
548
+ if (period) params.period = period;
549
+ const res = await this.client.get('/analytics/followers', {
550
+ params
551
+ });
552
+ return res.data;
553
+ } catch (error) {
554
+ throw this.handleError(error);
555
+ }
556
+ }
557
+
558
+ /* Wallet Methods */
559
+
560
+ /**
561
+ * Get wallet info
562
+ * @param userId - User ID to get wallet for
563
+ * @returns Wallet data
564
+ */
565
+ async getWallet(userId) {
566
+ try {
567
+ const res = await this.client.get(`/wallet/${userId}`);
568
+ return res.data;
569
+ } catch (error) {
570
+ throw this.handleError(error);
571
+ }
572
+ }
573
+
574
+ /**
575
+ * Get transaction history
576
+ * @param userId - User ID to get transactions for
577
+ * @param limit - Maximum number of transactions to return
578
+ * @param offset - Number of transactions to skip for pagination
579
+ * @returns Array of transactions and pagination info
580
+ */
581
+ async getTransactionHistory(userId, limit, offset) {
582
+ try {
583
+ const params = {};
584
+ if (limit !== undefined) params.limit = limit;
585
+ if (offset !== undefined) params.offset = offset;
586
+ const res = await this.client.get(`/wallet/transactions/${userId}`, {
587
+ params
588
+ });
589
+ return res.data;
590
+ } catch (error) {
591
+ throw this.handleError(error);
592
+ }
593
+ }
594
+
595
+ /**
596
+ * Get a specific transaction
597
+ * @param transactionId - ID of transaction to retrieve
598
+ * @returns Transaction data
599
+ */
600
+ async getTransaction(transactionId) {
601
+ try {
602
+ const res = await this.client.get(`/wallet/transaction/${transactionId}`);
603
+ return res.data;
604
+ } catch (error) {
605
+ throw this.handleError(error);
606
+ }
607
+ }
608
+
609
+ /**
610
+ * Transfer funds between users
611
+ * @param data - Transfer details including source, destination, and amount
612
+ * @returns Transaction response
613
+ */
614
+ async transferFunds(data) {
615
+ try {
616
+ const res = await this.client.post('/wallet/transfer', data);
617
+ return res.data;
618
+ } catch (error) {
619
+ throw this.handleError(error);
620
+ }
621
+ }
622
+
623
+ /**
624
+ * Process a purchase
625
+ * @param data - Purchase details including user, item, and amount
626
+ * @returns Transaction response
627
+ */
628
+ async processPurchase(data) {
629
+ try {
630
+ const res = await this.client.post('/wallet/purchase', data);
631
+ return res.data;
632
+ } catch (error) {
633
+ throw this.handleError(error);
634
+ }
635
+ }
636
+
637
+ /**
638
+ * Request a withdrawal
639
+ * @param data - Withdrawal details including user, amount, and address
640
+ * @returns Transaction response
641
+ */
642
+ async requestWithdrawal(data) {
643
+ try {
644
+ const res = await this.client.post('/wallet/withdraw', data);
645
+ return res.data;
646
+ } catch (error) {
647
+ throw this.handleError(error);
648
+ }
649
+ }
650
+
651
+ /* Karma Methods */
652
+
653
+ /**
654
+ * Get karma leaderboard
655
+ * @returns Array of karma leaderboard entries
656
+ */
657
+ async getKarmaLeaderboard() {
658
+ try {
659
+ const res = await this.client.get('/karma/leaderboard');
660
+ return res.data;
661
+ } catch (error) {
662
+ throw this.handleError(error);
663
+ }
664
+ }
665
+
666
+ /**
667
+ * Get karma rules
668
+ * @returns Array of karma rules
669
+ */
670
+ async getKarmaRules() {
671
+ try {
672
+ const res = await this.client.get('/karma/rules');
673
+ return res.data;
674
+ } catch (error) {
675
+ throw this.handleError(error);
676
+ }
677
+ }
678
+
679
+ /**
680
+ * Get total karma for a user
681
+ * @param userId - User ID to get karma for
682
+ * @returns Object with total karma points
683
+ */
684
+ async getUserKarmaTotal(userId) {
685
+ try {
686
+ const res = await this.client.get(`/karma/${userId}/total`);
687
+ return res.data;
688
+ } catch (error) {
689
+ throw this.handleError(error);
690
+ }
691
+ }
692
+
693
+ /**
694
+ * Get karma history for a user
695
+ * @param userId - User ID to get karma history for
696
+ * @param limit - Maximum number of history entries to return
697
+ * @param offset - Number of entries to skip for pagination
698
+ * @returns Karma history entries and pagination info
699
+ */
700
+ async getUserKarmaHistory(userId, limit, offset) {
701
+ try {
702
+ const params = {};
703
+ if (limit !== undefined) params.limit = limit;
704
+ if (offset !== undefined) params.offset = offset;
705
+ const res = await this.client.get(`/karma/${userId}/history`, {
706
+ params
707
+ });
708
+ return res.data;
709
+ } catch (error) {
710
+ throw this.handleError(error);
711
+ }
712
+ }
713
+
714
+ /**
715
+ * Award karma points to a user
716
+ * @param data - Karma award details
717
+ * @returns Karma award response
718
+ */
719
+ async awardKarma(data) {
720
+ try {
721
+ const res = await this.client.post('/karma/award', data);
722
+ return res.data;
723
+ } catch (error) {
724
+ throw this.handleError(error);
725
+ }
726
+ }
727
+
728
+ /**
729
+ * Deduct karma points from a user
730
+ * @param data - Karma deduction details
731
+ * @returns Karma deduction response
732
+ */
733
+ async deductKarma(data) {
734
+ try {
735
+ const res = await this.client.post('/karma/deduct', data);
736
+ return res.data;
737
+ } catch (error) {
738
+ throw this.handleError(error);
739
+ }
740
+ }
741
+
742
+ /**
743
+ * Create or update karma rule (admin)
744
+ * @param data - Karma rule data
745
+ * @returns Created or updated karma rule
746
+ */
747
+ async createOrUpdateKarmaRule(data) {
748
+ try {
749
+ const res = await this.client.post('/karma/rules', data);
750
+ return res.data;
751
+ } catch (error) {
752
+ throw this.handleError(error);
753
+ }
754
+ }
755
+
756
+ /**
757
+ * Centralized error handling
758
+ * @private
759
+ * @param error - Error object from API call
760
+ * @returns Formatted API error
761
+ */
762
+ handleError(error) {
763
+ if (error && error.code && error.status) {
764
+ // Already formatted as ApiError
765
+ return error;
766
+ }
767
+ const apiError = {
768
+ message: error?.message || error?.response?.data?.message || 'Unknown error occurred',
769
+ code: error?.response?.data?.code || 'UNKNOWN_ERROR',
770
+ status: error?.response?.status || 500,
771
+ details: error?.response?.data
772
+ };
773
+ return apiError;
774
+ }
775
+ }
776
+ export default OxyServices;
777
+ //# sourceMappingURL=index.js.map