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