@oxyhq/services 5.10.4 → 5.10.6

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 (142) hide show
  1. package/README.md +62 -14
  2. package/lib/commonjs/core/OxyServices.js +797 -5
  3. package/lib/commonjs/core/OxyServices.js.map +1 -1
  4. package/lib/commonjs/core/index.js +8 -83
  5. package/lib/commonjs/core/index.js.map +1 -1
  6. package/lib/commonjs/index.js +31 -1
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/ui/screens/FileManagementScreen.js +12 -12
  9. package/lib/commonjs/ui/screens/FileManagementScreen.js.map +1 -1
  10. package/lib/commonjs/ui/screens/ProfileScreen.js +2 -2
  11. package/lib/commonjs/ui/screens/ProfileScreen.js.map +1 -1
  12. package/lib/commonjs/ui/screens/SignInScreen.js +1 -1
  13. package/lib/commonjs/ui/screens/SignInScreen.js.map +1 -1
  14. package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js +1 -1
  15. package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js.map +1 -1
  16. package/lib/commonjs/ui/screens/karma/KarmaLeaderboardScreen.js +1 -1
  17. package/lib/commonjs/ui/screens/karma/KarmaLeaderboardScreen.js.map +1 -1
  18. package/lib/commonjs/ui/screens/karma/KarmaRulesScreen.js +1 -1
  19. package/lib/commonjs/ui/screens/karma/KarmaRulesScreen.js.map +1 -1
  20. package/lib/commonjs/ui/stores/followStore.js +4 -4
  21. package/lib/commonjs/ui/stores/followStore.js.map +1 -1
  22. package/lib/commonjs/utils/s3FileManager.js +243 -0
  23. package/lib/commonjs/utils/s3FileManager.js.map +1 -0
  24. package/lib/commonjs/utils/s3FileManagerExample.js +407 -0
  25. package/lib/commonjs/utils/s3FileManagerExample.js.map +1 -0
  26. package/lib/commonjs/utils/s3FileManagerRN.js +274 -0
  27. package/lib/commonjs/utils/s3FileManagerRN.js.map +1 -0
  28. package/lib/module/core/OxyServices.js +796 -4
  29. package/lib/module/core/OxyServices.js.map +1 -1
  30. package/lib/module/core/index.js +9 -24
  31. package/lib/module/core/index.js.map +1 -1
  32. package/lib/module/index.js +4 -0
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/module/ui/screens/FileManagementScreen.js +12 -12
  35. package/lib/module/ui/screens/FileManagementScreen.js.map +1 -1
  36. package/lib/module/ui/screens/ProfileScreen.js +2 -2
  37. package/lib/module/ui/screens/ProfileScreen.js.map +1 -1
  38. package/lib/module/ui/screens/SignInScreen.js +1 -1
  39. package/lib/module/ui/screens/SignInScreen.js.map +1 -1
  40. package/lib/module/ui/screens/karma/KarmaCenterScreen.js +1 -1
  41. package/lib/module/ui/screens/karma/KarmaCenterScreen.js.map +1 -1
  42. package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js +1 -1
  43. package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js.map +1 -1
  44. package/lib/module/ui/screens/karma/KarmaRulesScreen.js +1 -1
  45. package/lib/module/ui/screens/karma/KarmaRulesScreen.js.map +1 -1
  46. package/lib/module/ui/stores/followStore.js +4 -4
  47. package/lib/module/ui/stores/followStore.js.map +1 -1
  48. package/lib/module/utils/s3FileManager.js +237 -0
  49. package/lib/module/utils/s3FileManager.js.map +1 -0
  50. package/lib/module/utils/s3FileManagerExample.js +400 -0
  51. package/lib/module/utils/s3FileManagerExample.js.map +1 -0
  52. package/lib/module/utils/s3FileManagerRN.js +268 -0
  53. package/lib/module/utils/s3FileManagerRN.js.map +1 -0
  54. package/lib/typescript/core/OxyServices.d.ts +292 -3
  55. package/lib/typescript/core/OxyServices.d.ts.map +1 -1
  56. package/lib/typescript/core/index.d.ts +7 -16
  57. package/lib/typescript/core/index.d.ts.map +1 -1
  58. package/lib/typescript/index.d.ts +4 -0
  59. package/lib/typescript/index.d.ts.map +1 -1
  60. package/lib/typescript/utils/s3FileManager.d.ts +81 -0
  61. package/lib/typescript/utils/s3FileManager.d.ts.map +1 -0
  62. package/lib/typescript/utils/s3FileManagerExample.d.ts +87 -0
  63. package/lib/typescript/utils/s3FileManagerExample.d.ts.map +1 -0
  64. package/lib/typescript/utils/s3FileManagerRN.d.ts +104 -0
  65. package/lib/typescript/utils/s3FileManagerRN.d.ts.map +1 -0
  66. package/package.json +3 -1
  67. package/src/core/OxyServices.ts +881 -46
  68. package/src/core/index.ts +9 -24
  69. package/src/index.ts +17 -1
  70. package/src/ui/screens/FileManagementScreen.tsx +12 -12
  71. package/src/ui/screens/ProfileScreen.tsx +3 -3
  72. package/src/ui/screens/SignInScreen.tsx +1 -1
  73. package/src/ui/screens/karma/KarmaCenterScreen.tsx +2 -2
  74. package/src/ui/screens/karma/KarmaLeaderboardScreen.tsx +1 -1
  75. package/src/ui/screens/karma/KarmaRulesScreen.tsx +1 -1
  76. package/src/ui/stores/followStore.ts +4 -4
  77. package/src/utils/s3FileManager.ts +281 -0
  78. package/src/utils/s3FileManagerExample.ts +432 -0
  79. package/src/utils/s3FileManagerRN.ts +322 -0
  80. package/lib/commonjs/core/OxyServicesMain.js +0 -51
  81. package/lib/commonjs/core/OxyServicesMain.js.map +0 -1
  82. package/lib/commonjs/core/analytics/AnalyticsService.js +0 -67
  83. package/lib/commonjs/core/analytics/AnalyticsService.js.map +0 -1
  84. package/lib/commonjs/core/auth/AuthService.js +0 -538
  85. package/lib/commonjs/core/auth/AuthService.js.map +0 -1
  86. package/lib/commonjs/core/devices/DeviceService.js +0 -61
  87. package/lib/commonjs/core/devices/DeviceService.js.map +0 -1
  88. package/lib/commonjs/core/files/FileService.js +0 -180
  89. package/lib/commonjs/core/files/FileService.js.map +0 -1
  90. package/lib/commonjs/core/karma/KarmaService.js +0 -100
  91. package/lib/commonjs/core/karma/KarmaService.js.map +0 -1
  92. package/lib/commonjs/core/locations/LocationService.js +0 -131
  93. package/lib/commonjs/core/locations/LocationService.js.map +0 -1
  94. package/lib/commonjs/core/payments/PaymentService.js +0 -124
  95. package/lib/commonjs/core/payments/PaymentService.js.map +0 -1
  96. package/lib/commonjs/core/users/UserService.js +0 -234
  97. package/lib/commonjs/core/users/UserService.js.map +0 -1
  98. package/lib/module/core/OxyServicesMain.js +0 -47
  99. package/lib/module/core/OxyServicesMain.js.map +0 -1
  100. package/lib/module/core/analytics/AnalyticsService.js +0 -62
  101. package/lib/module/core/analytics/AnalyticsService.js.map +0 -1
  102. package/lib/module/core/auth/AuthService.js +0 -533
  103. package/lib/module/core/auth/AuthService.js.map +0 -1
  104. package/lib/module/core/devices/DeviceService.js +0 -57
  105. package/lib/module/core/devices/DeviceService.js.map +0 -1
  106. package/lib/module/core/files/FileService.js +0 -175
  107. package/lib/module/core/files/FileService.js.map +0 -1
  108. package/lib/module/core/karma/KarmaService.js +0 -95
  109. package/lib/module/core/karma/KarmaService.js.map +0 -1
  110. package/lib/module/core/locations/LocationService.js +0 -127
  111. package/lib/module/core/locations/LocationService.js.map +0 -1
  112. package/lib/module/core/payments/PaymentService.js +0 -119
  113. package/lib/module/core/payments/PaymentService.js.map +0 -1
  114. package/lib/module/core/users/UserService.js +0 -230
  115. package/lib/module/core/users/UserService.js.map +0 -1
  116. package/lib/typescript/core/OxyServicesMain.d.ts +0 -33
  117. package/lib/typescript/core/OxyServicesMain.d.ts.map +0 -1
  118. package/lib/typescript/core/analytics/AnalyticsService.d.ts +0 -26
  119. package/lib/typescript/core/analytics/AnalyticsService.d.ts.map +0 -1
  120. package/lib/typescript/core/auth/AuthService.d.ts +0 -165
  121. package/lib/typescript/core/auth/AuthService.d.ts.map +0 -1
  122. package/lib/typescript/core/devices/DeviceService.d.ts +0 -20
  123. package/lib/typescript/core/devices/DeviceService.d.ts.map +0 -1
  124. package/lib/typescript/core/files/FileService.d.ts +0 -59
  125. package/lib/typescript/core/files/FileService.d.ts.map +0 -1
  126. package/lib/typescript/core/karma/KarmaService.d.ts +0 -50
  127. package/lib/typescript/core/karma/KarmaService.d.ts.map +0 -1
  128. package/lib/typescript/core/locations/LocationService.d.ts +0 -39
  129. package/lib/typescript/core/locations/LocationService.d.ts.map +0 -1
  130. package/lib/typescript/core/payments/PaymentService.d.ts +0 -50
  131. package/lib/typescript/core/payments/PaymentService.d.ts.map +0 -1
  132. package/lib/typescript/core/users/UserService.d.ts +0 -111
  133. package/lib/typescript/core/users/UserService.d.ts.map +0 -1
  134. package/src/core/OxyServicesMain.ts +0 -57
  135. package/src/core/analytics/AnalyticsService.ts +0 -64
  136. package/src/core/auth/AuthService.ts +0 -560
  137. package/src/core/devices/DeviceService.ts +0 -55
  138. package/src/core/files/FileService.ts +0 -198
  139. package/src/core/karma/KarmaService.ts +0 -104
  140. package/src/core/locations/LocationService.ts +0 -141
  141. package/src/core/payments/PaymentService.ts +0 -133
  142. package/src/core/users/UserService.ts +0 -241
@@ -1,560 +0,0 @@
1
- import { jwtDecode } from 'jwt-decode';
2
- import { OxyServices } from '../OxyServices';
3
- import { User, LoginResponse, ApiError } from '../../models/interfaces';
4
- import { SessionLoginResponse } from '../../models/session';
5
- import { validateAndSanitizeUserInput } from '../../utils/validationUtils';
6
- import { validateRequiredFields } from '../../utils/errorUtils';
7
-
8
- interface JwtPayload {
9
- exp: number;
10
- userId: string;
11
- [key: string]: any;
12
- }
13
-
14
- /**
15
- * Authentication service for handling login, signup, and session management
16
- */
17
- export class AuthService extends OxyServices {
18
- /**
19
- * Sign up a new user
20
- */
21
- async signUp(username: string, email: string, password: string): Promise<{ message: string; token: string; user: User }> {
22
- try {
23
- const res = await this.getClient().post('/api/auth/signup', {
24
- username,
25
- email,
26
- password
27
- });
28
- return res.data;
29
- } catch (error) {
30
- throw this.handleError(error);
31
- }
32
- }
33
-
34
- /**
35
- * Sign in with device management
36
- */
37
- async signIn(username: string, password: string, deviceName?: string, deviceFingerprint?: any): Promise<SessionLoginResponse> {
38
- try {
39
- const res = await this.getClient().post('/api/auth/login', {
40
- username,
41
- password,
42
- deviceName,
43
- deviceFingerprint
44
- });
45
- return res.data;
46
- } catch (error) {
47
- throw this.handleError(error);
48
- }
49
- }
50
-
51
- /**
52
- * Get user by session ID
53
- */
54
- async getUserBySession(sessionId: string): Promise<User> {
55
- try {
56
- const res = await this.getClient().get(`/api/session/user/${sessionId}`);
57
- return res.data;
58
- } catch (error) {
59
- throw this.handleError(error);
60
- }
61
- }
62
-
63
- /**
64
- * Get access token by session ID and set it in the token store
65
- */
66
- async getTokenBySession(sessionId: string): Promise<{ accessToken: string; expiresAt: string }> {
67
- try {
68
- console.log('🔑 getTokenBySession - Fetching token for session:', sessionId);
69
- const res = await this.getClient().get(`/api/session/token/${sessionId}`);
70
- const { accessToken } = res.data;
71
-
72
- console.log('🔑 getTokenBySession - Token received:', !!accessToken);
73
-
74
- // Set the token in the centralized token store
75
- this.setTokens(accessToken);
76
- console.log('🔑 getTokenBySession - Token set in store');
77
-
78
- return res.data;
79
- } catch (error) {
80
- console.log('❌ getTokenBySession - Error:', error);
81
- throw this.handleError(error);
82
- }
83
- }
84
-
85
- /**
86
- * Get sessions by session ID
87
- */
88
- async getSessionsBySessionId(sessionId: string): Promise<any[]> {
89
- try {
90
- const res = await this.getClient().get(`/api/session/sessions/${sessionId}`);
91
- return res.data;
92
- } catch (error) {
93
- throw this.handleError(error);
94
- }
95
- }
96
-
97
- /**
98
- * Logout from a specific session
99
- */
100
- async logoutSession(sessionId: string, targetSessionId?: string): Promise<void> {
101
- try {
102
- await this.getClient().delete(`/api/session/logout/${sessionId}`, {
103
- data: { targetSessionId }
104
- });
105
- } catch (error) {
106
- throw this.handleError(error);
107
- }
108
- }
109
-
110
- /**
111
- * Logout from all sessions
112
- */
113
- async logoutAllSessions(sessionId: string): Promise<void> {
114
- try {
115
- await this.getClient().delete(`/api/session/logout-all/${sessionId}`);
116
- } catch (error) {
117
- throw this.handleError(error);
118
- }
119
- }
120
-
121
- /**
122
- * Validate a session with optional device fingerprint
123
- *
124
- * @example
125
- * ```typescript
126
- * // Basic session validation
127
- * const result = await authService.validateSession('session-id');
128
- *
129
- * // With device fingerprint for enhanced security
130
- * const result = await authService.validateSession('session-id', {
131
- * deviceFingerprint: 'device-fingerprint',
132
- * useHeaderValidation: true
133
- * });
134
- * ```
135
- *
136
- * @param sessionId The session ID to validate
137
- * @param options Validation options
138
- * @param options.deviceFingerprint Optional device fingerprint for enhanced validation
139
- * @param options.useHeaderValidation Whether to use header-based validation (default: false)
140
- * @returns Session validation result
141
- */
142
- async validateSession(
143
- sessionId: string,
144
- options: {
145
- deviceFingerprint?: string;
146
- useHeaderValidation?: boolean;
147
- } = {}
148
- ): Promise<{
149
- valid: boolean;
150
- expiresAt: string;
151
- lastActivity: string;
152
- user: User;
153
- sessionId?: string;
154
- source?: string;
155
- }> {
156
- const { deviceFingerprint, useHeaderValidation = false } = options;
157
-
158
- try {
159
- if (useHeaderValidation) {
160
- // Use header-based validation with device fingerprint
161
- const headers: Record<string, string> = {};
162
-
163
- if (deviceFingerprint) {
164
- headers['X-Device-Fingerprint'] = deviceFingerprint;
165
- }
166
-
167
- const res = await this.getClient().get(`/api/session/validate-header/${sessionId}`, {
168
- headers
169
- });
170
- return { ...res.data, source: 'header' };
171
- } else {
172
- // Use standard session validation
173
- const res = await this.getClient().get(`/api/session/validate/${sessionId}`);
174
- return { ...res.data, source: 'standard' };
175
- }
176
- } catch (error) {
177
- throw this.handleError(error);
178
- }
179
- }
180
-
181
- /**
182
- * Express.js authentication middleware
183
- *
184
- * A simple, efficient, and debuggable authentication middleware that supports both
185
- * session-based and legacy token-based authentication.
186
- *
187
- * @example
188
- * ```typescript
189
- * // Basic usage
190
- * app.use('/api/protected', authService.authenticateToken());
191
- *
192
- * // With debug logging
193
- * app.use('/api/protected', authService.authenticateToken({ debug: true }));
194
- *
195
- * // Without loading full user data (faster)
196
- * app.use('/api/protected', authService.authenticateToken({ loadFullUser: false }));
197
- *
198
- * // With custom error handling
199
- * app.use('/api/protected', authService.authenticateToken({
200
- * onError: (error) => {
201
- * console.error('Auth error:', error);
202
- * // Custom error handling logic
203
- * }
204
- * }));
205
- * ```
206
- *
207
- * @param options Configuration options
208
- * @param options.loadFullUser Whether to load complete user data (default: true)
209
- * @param options.onError Custom error handler function
210
- * @param options.debug Enable debug logging (default: false)
211
- * @returns Express middleware function
212
- */
213
- authenticateToken(options: {
214
- loadFullUser?: boolean;
215
- onError?: (error: ApiError) => any;
216
- debug?: boolean;
217
- } = {}) {
218
- const { loadFullUser = true, onError, debug = false } = options;
219
-
220
- return async (req: any, res: any, next: any) => {
221
- const startTime = Date.now();
222
-
223
- try {
224
- // Extract token from Authorization header
225
- const authHeader = req.headers['authorization'];
226
- const token = authHeader?.startsWith('Bearer ') ? authHeader.substring(7) : null;
227
-
228
- if (debug) {
229
- console.log(`🔐 Auth Middleware: Processing request to ${req.method} ${req.path}`);
230
- console.log(`🔐 Auth Middleware: Token present: ${!!token}`);
231
- }
232
-
233
- if (!token) {
234
- const error = {
235
- message: 'Access token required',
236
- code: 'MISSING_TOKEN',
237
- status: 401
238
- };
239
-
240
- if (debug) console.log(`❌ Auth Middleware: Missing token`);
241
-
242
- if (onError) return onError(error);
243
- return res.status(401).json(error);
244
- }
245
-
246
- // Decode and validate token
247
- let decoded: JwtPayload;
248
- try {
249
- decoded = jwtDecode<JwtPayload>(token);
250
-
251
- if (debug) {
252
- console.log(`🔐 Auth Middleware: Token decoded successfully`);
253
- console.log(`🔐 Auth Middleware: User ID: ${decoded.userId || decoded.id}`);
254
- console.log(`🔐 Auth Middleware: Has session ID: ${!!decoded.sessionId}`);
255
- }
256
- } catch (decodeError) {
257
- const error = {
258
- message: 'Invalid token format',
259
- code: 'INVALID_TOKEN_FORMAT',
260
- status: 403
261
- };
262
-
263
- if (debug) console.log(`❌ Auth Middleware: Token decode failed:`, decodeError);
264
-
265
- if (onError) return onError(error);
266
- return res.status(403).json(error);
267
- }
268
-
269
- const userId = decoded.userId || decoded.id;
270
- if (!userId) {
271
- const error = {
272
- message: 'Token missing user ID',
273
- code: 'INVALID_TOKEN_PAYLOAD',
274
- status: 403
275
- };
276
-
277
- if (debug) console.log(`❌ Auth Middleware: Token missing user ID`);
278
-
279
- if (onError) return onError(error);
280
- return res.status(403).json(error);
281
- }
282
-
283
- // Validate session or token
284
- let isValid = false;
285
- let user: User | null = null;
286
-
287
- if (decoded.sessionId) {
288
- // Session-based validation
289
- if (debug) console.log(`🔐 Auth Middleware: Using session validation for session: ${decoded.sessionId}`);
290
-
291
- try {
292
- const validation = await this.validateSession(decoded.sessionId, {
293
- useHeaderValidation: true
294
- });
295
- isValid = validation.valid;
296
- user = validation.user;
297
-
298
- if (debug) {
299
- console.log(`🔐 Auth Middleware: Session validation result: ${isValid}`);
300
- console.log(`🔐 Auth Middleware: User loaded: ${!!user}`);
301
- }
302
- } catch (sessionError) {
303
- if (debug) console.log(`❌ Auth Middleware: Session validation failed:`, sessionError);
304
- isValid = false;
305
- }
306
- } else {
307
- // Legacy token validation
308
- if (debug) console.log(`🔐 Auth Middleware: Using legacy token validation`);
309
-
310
- try {
311
- isValid = await this.validate();
312
-
313
- if (isValid && loadFullUser) {
314
- // Use minimal user data for performance - full user can be loaded separately if needed
315
- user = { id: userId } as User;
316
- }
317
-
318
- if (debug) {
319
- console.log(`🔐 Auth Middleware: Legacy validation result: ${isValid}`);
320
- console.log(`🔐 Auth Middleware: User loaded: ${!!user}`);
321
- }
322
- } catch (validationError) {
323
- if (debug) console.log(`❌ Auth Middleware: Legacy validation failed:`, validationError);
324
- isValid = false;
325
- }
326
- }
327
-
328
- if (!isValid) {
329
- const error = {
330
- message: 'Invalid or expired token',
331
- code: 'INVALID_TOKEN',
332
- status: 403
333
- };
334
-
335
- if (debug) console.log(`❌ Auth Middleware: Token validation failed`);
336
-
337
- if (onError) return onError(error);
338
- return res.status(403).json(error);
339
- }
340
-
341
- // Set request properties
342
- req.userId = userId;
343
- req.accessToken = token;
344
- req.user = user || { id: userId };
345
-
346
- if (debug) {
347
- const duration = Date.now() - startTime;
348
- console.log(`✅ Auth Middleware: Authentication successful in ${duration}ms`);
349
- console.log(`✅ Auth Middleware: User ID: ${userId}`);
350
- console.log(`✅ Auth Middleware: Full user loaded: ${loadFullUser && !!user}`);
351
- }
352
-
353
- next();
354
- } catch (error) {
355
- const duration = Date.now() - startTime;
356
- const apiError = this.handleError(error);
357
-
358
- if (debug) {
359
- console.log(`❌ Auth Middleware: Unexpected error after ${duration}ms:`, error);
360
- console.log(`❌ Auth Middleware: API Error:`, apiError);
361
- }
362
-
363
- if (onError) return onError(apiError);
364
- return res.status(apiError.status || 500).json(apiError);
365
- }
366
- };
367
- }
368
-
369
- /**
370
- * Helper method for validating tokens without Express middleware
371
- *
372
- * Use this method when you need to validate tokens programmatically
373
- * outside of Express middleware context.
374
- *
375
- * @example
376
- * ```typescript
377
- * const result = await authService.validateToken(token);
378
- * if (result.valid) {
379
- * console.log('User ID:', result.userId);
380
- * console.log('User data:', result.user);
381
- * } else {
382
- * console.log('Validation failed:', result.error);
383
- * }
384
- * ```
385
- *
386
- * @param token JWT token to validate
387
- * @returns Validation result with user data if valid
388
- */
389
- async validateToken(token: string): Promise<{
390
- valid: boolean;
391
- userId?: string;
392
- user?: any;
393
- error?: string;
394
- }> {
395
- try {
396
- if (!token) {
397
- return {
398
- valid: false,
399
- error: 'Token is required'
400
- };
401
- }
402
-
403
- // Decode token
404
- let decoded: JwtPayload;
405
- try {
406
- decoded = jwtDecode<JwtPayload>(token);
407
- } catch (decodeError) {
408
- return {
409
- valid: false,
410
- error: 'Invalid token format'
411
- };
412
- }
413
-
414
- const userId = decoded.userId || decoded.id;
415
- if (!userId) {
416
- return {
417
- valid: false,
418
- error: 'Token missing user ID'
419
- };
420
- }
421
-
422
- // Validate based on token type
423
- if (decoded.sessionId) {
424
- // Session-based validation
425
- try {
426
- const validation = await this.validateSession(decoded.sessionId, {
427
- useHeaderValidation: true
428
- });
429
- return {
430
- valid: validation.valid,
431
- userId,
432
- user: validation.user,
433
- error: validation.valid ? undefined : 'Invalid or expired session'
434
- };
435
- } catch (sessionError) {
436
- return {
437
- valid: false,
438
- userId,
439
- error: 'Session validation failed'
440
- };
441
- }
442
- } else {
443
- // Legacy token validation
444
- try {
445
- const isValid = await this.validate();
446
- if (!isValid) {
447
- return {
448
- valid: false,
449
- userId,
450
- error: 'Invalid or expired token'
451
- };
452
- }
453
-
454
- // Use minimal user data for performance
455
- const user = { id: userId } as User;
456
-
457
- return {
458
- valid: true,
459
- userId,
460
- user
461
- };
462
- } catch (validationError) {
463
- return {
464
- valid: false,
465
- userId,
466
- error: 'Token validation failed'
467
- };
468
- }
469
- }
470
- } catch (error) {
471
- return {
472
- valid: false,
473
- error: error instanceof Error ? error.message : 'Token validation failed'
474
- };
475
- }
476
- }
477
-
478
- /**
479
- * Get device sessions (delegates to DeviceService)
480
- */
481
- async getDeviceSessions(sessionId: string): Promise<any[]> {
482
- try {
483
- const res = await this.getClient().get(`/api/session/device/sessions/${sessionId}`);
484
- return res.data;
485
- } catch (error) {
486
- throw this.handleError(error);
487
- }
488
- }
489
-
490
- /**
491
- * Logout from all device sessions (delegates to DeviceService)
492
- */
493
- async logoutAllDeviceSessions(sessionId: string): Promise<void> {
494
- try {
495
- await this.getClient().delete(`/api/session/device/logout-all/${sessionId}`);
496
- } catch (error) {
497
- throw this.handleError(error);
498
- }
499
- }
500
-
501
- /**
502
- * Update device name (delegates to DeviceService)
503
- */
504
- async updateDeviceName(sessionId: string, deviceName: string): Promise<void> {
505
- try {
506
- await this.getClient().put(`/api/session/device/name/${sessionId}`, { deviceName });
507
- } catch (error) {
508
- throw this.handleError(error);
509
- }
510
- }
511
-
512
- /**
513
- * Check username availability
514
- */
515
- async checkUsernameAvailability(username: string): Promise<{ available: boolean; message: string }> {
516
- try {
517
- const res = await this.getClient().get(`/api/auth/check-username/${username}`);
518
- return res.data;
519
- } catch (error: any) {
520
- // If the endpoint doesn't exist, fall back to basic validation
521
- if (error.response?.status === 404) {
522
- console.warn('Username validation endpoint not found, using fallback validation');
523
- return { available: true, message: 'Username validation not available' };
524
- }
525
-
526
- // If it's a validation error (400), return the error message
527
- if (error.response?.status === 400) {
528
- return { available: false, message: error.response.data.message || 'Username not available' };
529
- }
530
-
531
- throw this.handleError(error);
532
- }
533
- }
534
-
535
- /**
536
- * Check email availability
537
- */
538
- async checkEmailAvailability(email: string): Promise<{ available: boolean; message: string }> {
539
- try {
540
- const res = await this.getClient().get(`/api/auth/check-email/${email}`);
541
- return res.data;
542
- } catch (error: any) {
543
- // If the endpoint doesn't exist, fall back to basic validation
544
- if (error.response?.status === 404) {
545
- console.warn('Email validation endpoint not found, using fallback validation');
546
- return { available: true, message: 'Email validation not available' };
547
- }
548
-
549
- // If it's a validation error (400), return the error message
550
- if (error.response?.status === 400) {
551
- return { available: false, message: error.response.data.message || 'Email not available' };
552
- }
553
-
554
- throw this.handleError(error);
555
- }
556
- }
557
-
558
- // Note: getUserById and getUserProfileByUsername methods have been moved to UserService
559
- // Use oxyServices.users.getUserById() and oxyServices.users.getProfileByUsername() instead
560
- }
@@ -1,55 +0,0 @@
1
- import { OxyServices } from '../OxyServices';
2
- import {
3
- DeviceSession,
4
- DeviceSessionsResponse,
5
- DeviceSessionLogoutResponse,
6
- UpdateDeviceNameResponse
7
- } from '../../models/interfaces';
8
- import { buildSearchParams } from '../../utils/apiUtils';
9
-
10
- /**
11
- * Device service for handling device session management
12
- */
13
- export class DeviceService extends OxyServices {
14
- /**
15
- * Get device sessions
16
- */
17
- async getDeviceSessions(sessionId: string, deviceId?: string): Promise<DeviceSession[]> {
18
- try {
19
- const params = { deviceId };
20
- const searchParams = buildSearchParams(params);
21
-
22
- const res = await this.getClient().get(`/api/session/device/sessions/${sessionId}?${searchParams.toString()}`);
23
- return res.data;
24
- } catch (error) {
25
- throw this.handleError(error);
26
- }
27
- }
28
-
29
- /**
30
- * Logout from all device sessions
31
- */
32
- async logoutAllDeviceSessions(sessionId: string, deviceId?: string, excludeCurrent?: boolean): Promise<DeviceSessionLogoutResponse> {
33
- try {
34
- const params = { deviceId, excludeCurrent };
35
- const searchParams = buildSearchParams(params);
36
-
37
- const res = await this.getClient().post(`/api/session/device/logout-all/${sessionId}?${searchParams.toString()}`);
38
- return res.data;
39
- } catch (error) {
40
- throw this.handleError(error);
41
- }
42
- }
43
-
44
- /**
45
- * Update device name
46
- */
47
- async updateDeviceName(sessionId: string, deviceName: string): Promise<UpdateDeviceNameResponse> {
48
- try {
49
- const res = await this.getClient().put(`/api/session/device/name/${sessionId}`, { deviceName });
50
- return res.data;
51
- } catch (error) {
52
- throw this.handleError(error);
53
- }
54
- }
55
- }