@oxyhq/services 5.2.2 → 5.2.4

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 (64) hide show
  1. package/lib/commonjs/core/index.js +117 -0
  2. package/lib/commonjs/core/index.js.map +1 -1
  3. package/lib/commonjs/models/secureSession.js +2 -0
  4. package/lib/commonjs/models/secureSession.js.map +1 -0
  5. package/lib/commonjs/ui/context/LegacyOxyContext.js +643 -0
  6. package/lib/commonjs/ui/context/LegacyOxyContext.js.map +1 -0
  7. package/lib/commonjs/ui/context/OxyContext.js +215 -450
  8. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  9. package/lib/commonjs/ui/context/SecureOxyContext.js +408 -0
  10. package/lib/commonjs/ui/context/SecureOxyContext.js.map +1 -0
  11. package/lib/commonjs/ui/screens/AccountCenterScreen.js +3 -3
  12. package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
  13. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +31 -30
  14. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
  15. package/lib/commonjs/ui/screens/AppInfoScreen.js +4 -4
  16. package/lib/commonjs/ui/screens/AppInfoScreen.js.map +1 -1
  17. package/lib/commonjs/ui/screens/SessionManagementScreen.js +34 -34
  18. package/lib/commonjs/ui/screens/SessionManagementScreen.js.map +1 -1
  19. package/lib/commonjs/ui/screens/SignInScreen.js +2 -2
  20. package/lib/commonjs/ui/screens/SignInScreen.js.map +1 -1
  21. package/lib/module/core/index.js +117 -0
  22. package/lib/module/core/index.js.map +1 -1
  23. package/lib/module/models/secureSession.js +2 -0
  24. package/lib/module/models/secureSession.js.map +1 -0
  25. package/lib/module/ui/context/LegacyOxyContext.js +639 -0
  26. package/lib/module/ui/context/LegacyOxyContext.js.map +1 -0
  27. package/lib/module/ui/context/OxyContext.js +214 -450
  28. package/lib/module/ui/context/OxyContext.js.map +1 -1
  29. package/lib/module/ui/context/SecureOxyContext.js +403 -0
  30. package/lib/module/ui/context/SecureOxyContext.js.map +1 -0
  31. package/lib/module/ui/screens/AccountCenterScreen.js +3 -3
  32. package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
  33. package/lib/module/ui/screens/AccountSwitcherScreen.js +31 -30
  34. package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
  35. package/lib/module/ui/screens/AppInfoScreen.js +4 -4
  36. package/lib/module/ui/screens/AppInfoScreen.js.map +1 -1
  37. package/lib/module/ui/screens/SessionManagementScreen.js +34 -34
  38. package/lib/module/ui/screens/SessionManagementScreen.js.map +1 -1
  39. package/lib/module/ui/screens/SignInScreen.js +2 -2
  40. package/lib/module/ui/screens/SignInScreen.js.map +1 -1
  41. package/lib/typescript/core/index.d.ts +51 -0
  42. package/lib/typescript/core/index.d.ts.map +1 -1
  43. package/lib/typescript/models/secureSession.d.ts +25 -0
  44. package/lib/typescript/models/secureSession.d.ts.map +1 -0
  45. package/lib/typescript/ui/context/LegacyOxyContext.d.ts +40 -0
  46. package/lib/typescript/ui/context/LegacyOxyContext.d.ts.map +1 -0
  47. package/lib/typescript/ui/context/OxyContext.d.ts +11 -12
  48. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
  49. package/lib/typescript/ui/context/SecureOxyContext.d.ts +39 -0
  50. package/lib/typescript/ui/context/SecureOxyContext.d.ts.map +1 -0
  51. package/lib/typescript/ui/screens/AccountSwitcherScreen.d.ts.map +1 -1
  52. package/lib/typescript/ui/screens/SessionManagementScreen.d.ts.map +1 -1
  53. package/package.json +1 -1
  54. package/src/core/index.ts +117 -0
  55. package/src/index.ts +2 -2
  56. package/src/models/secureSession.ts +27 -0
  57. package/src/ui/context/LegacyOxyContext.tsx +735 -0
  58. package/src/ui/context/OxyContext.tsx +412 -674
  59. package/src/ui/context/SecureOxyContext.tsx +473 -0
  60. package/src/ui/screens/AccountCenterScreen.tsx +4 -4
  61. package/src/ui/screens/AccountSwitcherScreen.tsx +36 -34
  62. package/src/ui/screens/AppInfoScreen.tsx +3 -3
  63. package/src/ui/screens/SessionManagementScreen.tsx +31 -35
  64. package/src/ui/screens/SignInScreen.tsx +2 -2
@@ -31,7 +31,7 @@ const AppInfoScreen: React.FC<BaseScreenProps> = ({
31
31
  theme,
32
32
  navigate,
33
33
  }) => {
34
- const { user, users } = useOxy();
34
+ const { user, sessions } = useOxy();
35
35
  const [systemInfo, setSystemInfo] = useState<SystemInfo | null>(null);
36
36
 
37
37
  const isDarkTheme = theme === 'dark';
@@ -76,7 +76,7 @@ const AppInfoScreen: React.FC<BaseScreenProps> = ({
76
76
  isAuthenticated: !!user,
77
77
  userId: user?.id || 'Not authenticated',
78
78
  username: user?.username || 'N/A',
79
- totalUsers: users?.length || 0,
79
+ totalUsers: sessions?.length || 0,
80
80
  },
81
81
  apiConfiguration: {
82
82
  apiUrl: 'http://localhost:3001',
@@ -164,7 +164,7 @@ const AppInfoScreen: React.FC<BaseScreenProps> = ({
164
164
  <InfoRow label="Premium Status" value={user.isPremium ? 'Premium' : 'Standard'} />
165
165
  </>
166
166
  )}
167
- <InfoRow label="Total Signed-in Users" value={users?.length?.toString() || '0'} />
167
+ <InfoRow label="Total Active Sessions" value={sessions?.length?.toString() || '0'} />
168
168
  </InfoSection>
169
169
 
170
170
  <InfoSection title="API Configuration">
@@ -31,8 +31,7 @@ const SessionManagementScreen: React.FC<BaseScreenProps> = ({
31
31
  onClose,
32
32
  theme,
33
33
  }) => {
34
- const { getUserSessions, logoutSession, oxyServices } = useOxy();
35
- const [sessions, setSessions] = useState<Session[]>([]);
34
+ const { sessions: userSessions, activeSessionId, refreshSessions, logout, oxyServices } = useOxy();
36
35
  const [loading, setLoading] = useState(true);
37
36
  const [refreshing, setRefreshing] = useState(false);
38
37
  const [actionLoading, setActionLoading] = useState<string | null>(null);
@@ -54,8 +53,7 @@ const SessionManagementScreen: React.FC<BaseScreenProps> = ({
54
53
  setLoading(true);
55
54
  }
56
55
 
57
- const userSessions = await getUserSessions();
58
- setSessions(userSessions);
56
+ await refreshSessions();
59
57
  } catch (error) {
60
58
  console.error('Failed to load sessions:', error);
61
59
  Alert.alert(
@@ -81,10 +79,10 @@ const SessionManagementScreen: React.FC<BaseScreenProps> = ({
81
79
  onPress: async () => {
82
80
  try {
83
81
  setActionLoading(sessionId);
84
- await logoutSession(sessionId);
82
+ await logout(sessionId);
85
83
 
86
- // Remove the session from local state
87
- setSessions(prev => prev.filter(s => s.id !== sessionId));
84
+ // Refresh sessions to update the list
85
+ await refreshSessions();
88
86
 
89
87
  Alert.alert('Success', 'Session logged out successfully');
90
88
  } catch (error) {
@@ -103,7 +101,7 @@ const SessionManagementScreen: React.FC<BaseScreenProps> = ({
103
101
  };
104
102
 
105
103
  const handleLogoutOtherSessions = async () => {
106
- const otherSessionsCount = sessions.filter(s => !s.isCurrent).length;
104
+ const otherSessionsCount = userSessions.filter(s => s.sessionId !== activeSessionId).length;
107
105
 
108
106
  if (otherSessionsCount === 0) {
109
107
  Alert.alert('Info', 'No other sessions to logout.');
@@ -121,10 +119,15 @@ const SessionManagementScreen: React.FC<BaseScreenProps> = ({
121
119
  onPress: async () => {
122
120
  try {
123
121
  setActionLoading('others');
124
- await oxyServices.logoutOtherSessions();
122
+ // Logout each non-active session
123
+ for (const session of userSessions) {
124
+ if (session.sessionId !== activeSessionId) {
125
+ await logout(session.sessionId);
126
+ }
127
+ }
125
128
 
126
- // Keep only current session in local state
127
- setSessions(prev => prev.filter(s => s.isCurrent));
129
+ // Refresh sessions to update the list
130
+ await refreshSessions();
128
131
 
129
132
  Alert.alert('Success', 'Other sessions logged out successfully');
130
133
  } catch (error) {
@@ -232,30 +235,30 @@ const SessionManagementScreen: React.FC<BaseScreenProps> = ({
232
235
  />
233
236
  }
234
237
  >
235
- {sessions.length > 0 ? (
238
+ {userSessions.length > 0 ? (
236
239
  <>
237
- {sessions.map((session) => (
240
+ {userSessions.map((session) => (
238
241
  <View
239
- key={session.id}
242
+ key={session.sessionId}
240
243
  style={[
241
244
  styles.sessionCard,
242
245
  {
243
246
  backgroundColor: secondaryBackgroundColor,
244
247
  borderColor,
245
- borderLeftColor: session.isCurrent ? successColor : borderColor,
248
+ borderLeftColor: session.sessionId === activeSessionId ? successColor : borderColor,
246
249
  },
247
250
  ]}
248
251
  >
249
252
  <View style={styles.sessionHeader}>
250
253
  <View style={styles.sessionTitleRow}>
251
254
  <Text style={styles.deviceIcon}>
252
- {getDeviceIcon(session.deviceType, session.platform)}
255
+ 📱
253
256
  </Text>
254
257
  <View style={styles.sessionTitleText}>
255
258
  <Text style={[styles.deviceName, { color: textColor }]}>
256
- {session.deviceName || 'Unknown Device'}
259
+ Session {session.sessionId.substring(0, 8)}...
257
260
  </Text>
258
- {session.isCurrent && (
261
+ {session.sessionId === activeSessionId && (
259
262
  <Text style={[styles.currentBadge, { color: successColor }]}>
260
263
  Current Session
261
264
  </Text>
@@ -266,30 +269,23 @@ const SessionManagementScreen: React.FC<BaseScreenProps> = ({
266
269
 
267
270
  <View style={styles.sessionDetails}>
268
271
  <Text style={[styles.sessionDetail, { color: isDarkTheme ? '#BBBBBB' : '#666666' }]}>
269
- {session.platform} {session.deviceType}
272
+ Device ID: {session.deviceId.substring(0, 12)}...
270
273
  </Text>
271
- {session.browser && (
272
- <Text style={[styles.sessionDetail, { color: isDarkTheme ? '#BBBBBB' : '#666666' }]}>
273
- {session.browser}
274
- </Text>
275
- )}
276
274
  <Text style={[styles.sessionDetail, { color: isDarkTheme ? '#BBBBBB' : '#666666' }]}>
277
- Last active: {formatDate(session.lastActivity)}
275
+ Last active: {new Date(session.lastActive).toLocaleDateString()}
276
+ </Text>
277
+ <Text style={[styles.sessionDetail, { color: isDarkTheme ? '#BBBBBB' : '#666666' }]}>
278
+ Expires: {new Date(session.expiresAt).toLocaleDateString()}
278
279
  </Text>
279
- {session.ipAddress && (
280
- <Text style={[styles.sessionDetail, { color: isDarkTheme ? '#BBBBBB' : '#666666' }]}>
281
- IP: {session.ipAddress}
282
- </Text>
283
- )}
284
280
  </View>
285
281
 
286
- {!session.isCurrent && (
282
+ {session.sessionId !== activeSessionId && (
287
283
  <TouchableOpacity
288
284
  style={[styles.logoutButton, { backgroundColor: isDarkTheme ? '#400000' : '#FFEBEE' }]}
289
- onPress={() => handleLogoutSession(session.id)}
290
- disabled={actionLoading === session.id}
285
+ onPress={() => handleLogoutSession(session.sessionId)}
286
+ disabled={actionLoading === session.sessionId}
291
287
  >
292
- {actionLoading === session.id ? (
288
+ {actionLoading === session.sessionId ? (
293
289
  <ActivityIndicator size="small" color={dangerColor} />
294
290
  ) : (
295
291
  <Text style={[styles.logoutButtonText, { color: dangerColor }]}>
@@ -305,7 +301,7 @@ const SessionManagementScreen: React.FC<BaseScreenProps> = ({
305
301
  <TouchableOpacity
306
302
  style={[styles.bulkActionButton, { backgroundColor: isDarkTheme ? '#1A1A1A' : '#F0F0F0', borderColor }]}
307
303
  onPress={handleLogoutOtherSessions}
308
- disabled={actionLoading === 'others' || sessions.filter(s => !s.isCurrent).length === 0}
304
+ disabled={actionLoading === 'others' || userSessions.filter(s => s.sessionId !== activeSessionId).length === 0}
309
305
  >
310
306
  {actionLoading === 'others' ? (
311
307
  <ActivityIndicator size="small" color={primaryColor} />
@@ -25,13 +25,13 @@ const SignInScreen: React.FC<BaseScreenProps> = ({
25
25
  const [password, setPassword] = useState('');
26
26
  const [errorMessage, setErrorMessage] = useState('');
27
27
 
28
- const { login, isLoading, user, isAuthenticated, users } = useOxy();
28
+ const { login, isLoading, user, isAuthenticated, sessions } = useOxy();
29
29
 
30
30
  const colors = useThemeColors(theme);
31
31
  const commonStyles = createCommonStyles(theme);
32
32
 
33
33
  // Check if this should be treated as "Add Account" mode
34
- const isAddAccountMode = user && isAuthenticated && users && users.length > 0;
34
+ const isAddAccountMode = user && isAuthenticated && sessions && sessions.length > 0;
35
35
 
36
36
  const handleLogin = async () => {
37
37
  if (!username || !password) {