@oxyhq/services 5.9.1 → 5.9.3

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