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