@oxyhq/services 5.3.10 → 5.3.11
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/LICENSE +21 -0
- package/README.md +63 -571
- package/lib/commonjs/core/index.js +103 -34
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/lib/sonner.js +17 -0
- package/lib/commonjs/lib/sonner.js.map +1 -0
- package/lib/commonjs/lib/sonner.web.js +17 -0
- package/lib/commonjs/lib/sonner.web.js.map +1 -0
- package/lib/commonjs/ui/components/FollowButton.js +54 -4
- package/lib/commonjs/ui/components/FollowButton.js.map +1 -1
- package/lib/commonjs/ui/components/OxyProvider.js +22 -3
- package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountCenterScreen.js +4 -3
- package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountOverviewScreen.js +15 -14
- package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js +10 -9
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +17 -16
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AppInfoScreen.js +4 -5
- package/lib/commonjs/ui/screens/AppInfoScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SessionManagementScreen.js +7 -6
- package/lib/commonjs/ui/screens/SessionManagementScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SignInScreen.js +821 -74
- package/lib/commonjs/ui/screens/SignInScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SignUpScreen.js +7 -5
- package/lib/commonjs/ui/screens/SignUpScreen.js.map +1 -1
- package/lib/commonjs/ui/styles/theme.js +1 -1
- package/lib/module/core/index.js +103 -34
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/lib/sonner.js +4 -0
- package/lib/module/lib/sonner.js.map +1 -0
- package/lib/module/lib/sonner.web.js +4 -0
- package/lib/module/lib/sonner.web.js.map +1 -0
- package/lib/module/ui/components/FollowButton.js +54 -4
- package/lib/module/ui/components/FollowButton.js.map +1 -1
- package/lib/module/ui/components/OxyProvider.js +22 -3
- package/lib/module/ui/components/OxyProvider.js.map +1 -1
- package/lib/module/ui/screens/AccountCenterScreen.js +4 -3
- package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountOverviewScreen.js +15 -14
- package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSettingsScreen.js +10 -9
- package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSwitcherScreen.js +17 -16
- package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/module/ui/screens/AppInfoScreen.js +5 -6
- package/lib/module/ui/screens/AppInfoScreen.js.map +1 -1
- package/lib/module/ui/screens/SessionManagementScreen.js +7 -6
- package/lib/module/ui/screens/SessionManagementScreen.js.map +1 -1
- package/lib/module/ui/screens/SignInScreen.js +824 -77
- package/lib/module/ui/screens/SignInScreen.js.map +1 -1
- package/lib/module/ui/screens/SignUpScreen.js +7 -5
- package/lib/module/ui/screens/SignUpScreen.js.map +1 -1
- package/lib/module/ui/styles/theme.js +1 -1
- package/lib/typescript/core/index.d.ts +44 -23
- package/lib/typescript/core/index.d.ts.map +1 -1
- package/lib/typescript/lib/sonner.d.ts +2 -0
- package/lib/typescript/lib/sonner.d.ts.map +1 -0
- package/lib/typescript/lib/sonner.web.d.ts +2 -0
- package/lib/typescript/lib/sonner.web.d.ts.map +1 -0
- package/lib/typescript/models/interfaces.d.ts +24 -0
- package/lib/typescript/models/interfaces.d.ts.map +1 -1
- package/lib/typescript/ui/components/FollowButton.d.ts +32 -1
- package/lib/typescript/ui/components/FollowButton.d.ts.map +1 -1
- package/lib/typescript/ui/components/OxyProvider.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountCenterScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountSwitcherScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AppInfoScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/SessionManagementScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/SignInScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/SignUpScreen.d.ts.map +1 -1
- package/package.json +5 -3
- package/src/core/index.ts +104 -36
- package/src/lib/sonner.ts +1 -0
- package/src/lib/sonner.web.ts +1 -0
- package/src/models/interfaces.ts +29 -0
- package/src/ui/components/FollowButton.tsx +67 -3
- package/src/ui/components/OxyProvider.tsx +15 -0
- package/src/ui/screens/AccountCenterScreen.tsx +4 -3
- package/src/ui/screens/AccountOverviewScreen.tsx +15 -14
- package/src/ui/screens/AccountSettingsScreen.tsx +10 -9
- package/src/ui/screens/AccountSwitcherScreen.tsx +17 -16
- package/src/ui/screens/AppInfoScreen.tsx +4 -7
- package/src/ui/screens/SessionManagementScreen.tsx +7 -15
- package/src/ui/screens/SignInScreen.tsx +729 -52
- package/src/ui/screens/SignUpScreen.tsx +7 -5
- package/src/ui/styles/theme.ts +1 -1
- package/CHANGELOG.md +0 -97
- package/UI_COMPONENTS.md +0 -462
package/README.md
CHANGED
|
@@ -1,621 +1,113 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OxyHQServices
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A TypeScript client library for the Oxy API providing authentication, user management, and UI components for React and React Native applications.
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
7
|
-
- [
|
|
8
|
-
- [
|
|
9
|
-
- [
|
|
10
|
-
- [Usage](#usage)
|
|
11
|
-
- [Using in React Native](#using-in-react-native)
|
|
12
|
-
- [Using in Node.js / Express](#using-in-nodejs--express)
|
|
13
|
-
- [Enhanced Device Session Management](#enhanced-device-session-management)
|
|
14
|
-
- [Configuration](#configuration)
|
|
15
|
-
- [API Reference](#api-reference)
|
|
16
|
-
- [OxyConfig](#oxyconfig)
|
|
17
|
-
- [Class: OxyServices](#class-oxyservices)
|
|
18
|
-
- [Models and Types](#models-and-types)
|
|
7
|
+
- [Features](#features)
|
|
8
|
+
- [Quick Start](#quick-start)
|
|
9
|
+
- [Documentation](#documentation)
|
|
19
10
|
- [UI Components](#ui-components)
|
|
20
|
-
- [
|
|
11
|
+
- [Package Exports](#package-exports)
|
|
12
|
+
- [Requirements](#requirements)
|
|
21
13
|
- [Development](#development)
|
|
22
|
-
- [
|
|
14
|
+
- [Integration](#integration)
|
|
23
15
|
- [License](#license)
|
|
24
16
|
|
|
25
|
-
|
|
17
|
+
## Features
|
|
26
18
|
|
|
27
|
-
|
|
19
|
+
- 🔐 **Authentication**: JWT-based auth with automatic token refresh
|
|
20
|
+
- 👥 **User Management**: Profile operations and social features
|
|
21
|
+
- 🎨 **UI Components**: Pre-built React components for common functionality
|
|
22
|
+
- 📱 **Cross-Platform**: Works in React Native and web applications
|
|
23
|
+
- 🔧 **TypeScript**: Full type safety and IntelliSense support
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- Authentication (signup, login, token refresh, logout, validation)
|
|
32
|
-
- User & profile operations (fetch, update, follow/unfollow)
|
|
33
|
-
- Real‑time notifications (list, create, mark read, delete)
|
|
34
|
-
- Payments & wallet (process payment, validate method, transfer funds, purchase, withdrawal)
|
|
35
|
-
- Analytics & content insights (time‑series data, viewers, follower stats)
|
|
36
|
-
- Karma system (leaderboard, rules, award/deduct points)
|
|
37
|
-
- File management (upload, download, stream, list, update, delete files using GridFS)
|
|
38
|
-
|
|
39
|
-
## Models and Types
|
|
40
|
-
|
|
41
|
-
The package exports TypeScript interfaces for all data models used by the API. These can be used in your application for type safety and better IntelliSense support.
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
// Import specific models directly from main export
|
|
45
|
-
import { User, LoginResponse, Notification } from '@oxyhq/services';
|
|
46
|
-
|
|
47
|
-
// Or import all models as a namespace
|
|
48
|
-
import { Models } from '@oxyhq/services';
|
|
49
|
-
|
|
50
|
-
// For full package usage (includes UI components)
|
|
51
|
-
import { Models, User, LoginResponse } from '@oxyhq/services/full';
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
For detailed documentation on using models in your application, see [MODEL_USAGE.md](docs/MODEL_USAGE.md).
|
|
55
|
-
|
|
56
|
-
## UI Components
|
|
57
|
-
|
|
58
|
-
This package includes several UI components that can be used in your React or React Native application:
|
|
59
|
-
|
|
60
|
-
- `OxyProvider`: Context provider for authentication and settings
|
|
61
|
-
- `OxySignInButton`: Pre-styled authentication button
|
|
62
|
-
- `FollowButton`: Animated button for follow/unfollow interactions
|
|
63
|
-
- `Avatar`: User avatar component with fallback options
|
|
64
|
-
- `OxyLogo`: Brand logo component
|
|
65
|
-
|
|
66
|
-
**Import UI Components:**
|
|
67
|
-
```javascript
|
|
68
|
-
// Import specific UI components
|
|
69
|
-
import { OxyProvider, OxySignInButton, Avatar } from '@oxyhq/services/ui';
|
|
70
|
-
|
|
71
|
-
// Or import from full package
|
|
72
|
-
import { OxyProvider, OxySignInButton, Avatar } from '@oxyhq/services/full';
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
For detailed documentation on UI components, see [UI_COMPONENTS.md](UI_COMPONENTS.md).
|
|
76
|
-
|
|
77
|
-
## What's New in 5.2.0
|
|
78
|
-
|
|
79
|
-
- **Multi-User Authentication**: Support for signing in with multiple accounts simultaneously
|
|
80
|
-
- **Account Switcher**: Built-in UI for switching between authenticated accounts
|
|
81
|
-
- **Session Management**: View and manage active sessions across devices with remote logout capabilities
|
|
82
|
-
- **Enhanced Security**: Comprehensive session tracking with device information
|
|
83
|
-
- **Account Center**: New account management interface with multi-user support
|
|
84
|
-
|
|
85
|
-
## What's New in 5.1.5
|
|
86
|
-
|
|
87
|
-
- **Fixed BottomSheet on Native Platforms**: The `OxyProvider` component now correctly displays the authentication UI in a bottom sheet on native platforms.
|
|
88
|
-
- **Added Bottom Sheet Controls**: The `OxyProvider` component now provides methods via context (`showBottomSheet`, `hideBottomSheet`) for programmatic control of the bottom sheet.
|
|
89
|
-
- **Improved Native Animations**: Enhanced animation and layout behavior for a smoother experience on all platforms.
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
## What's New in v5.3.0
|
|
94
|
-
|
|
95
|
-
### 🔐 Enhanced Device-Based Session Management
|
|
96
|
-
|
|
97
|
-
This release introduces a comprehensive device-based session management system that enables:
|
|
98
|
-
|
|
99
|
-
- **Device Fingerprinting**: Consistent device identification across sessions
|
|
100
|
-
- **Multi-User Support**: Multiple users can sign in on shared devices with session isolation
|
|
101
|
-
- **Remote Session Management**: View and manage sessions across all devices
|
|
102
|
-
- **Enhanced Security**: No PII stored locally, server-side session validation
|
|
103
|
-
- **Cross-Platform Support**: Works with both web browsers and React Native apps
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
import { DeviceManager, OxyServices } from '@oxyhq/services';
|
|
107
|
-
|
|
108
|
-
// Initialize device manager for fingerprinting
|
|
109
|
-
const deviceManager = new DeviceManager();
|
|
110
|
-
await deviceManager.initialize();
|
|
111
|
-
|
|
112
|
-
// Enhanced login with device fingerprinting
|
|
113
|
-
const oxyServices = new OxyServices(config);
|
|
114
|
-
const response = await oxyServices.secureLogin(username, password, {
|
|
115
|
-
deviceFingerprint: await deviceManager.generateFingerprint()
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// Manage device sessions
|
|
119
|
-
const deviceSessions = await oxyServices.getDeviceSessions(sessionId);
|
|
120
|
-
await oxyServices.logoutAllDeviceSessions(sessionId);
|
|
121
|
-
await oxyServices.updateDeviceName(sessionId, 'My Device');
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### 🎨 Complete UI Component Suite
|
|
125
|
-
|
|
126
|
-
All UI components and screens are now fully implemented:
|
|
127
|
-
|
|
128
|
-
- **Authentication Screens**: SignInScreen, SignUpScreen, SessionManagementScreen
|
|
129
|
-
- **Account Management**: AccountCenterScreen, AccountOverviewScreen, AccountSettingsScreen
|
|
130
|
-
- **Karma System**: KarmaCenterScreen, KarmaLeaderboardScreen, KarmaRewardsScreen, KarmaRulesScreen, KarmaAboutScreen, KarmaFAQScreen
|
|
131
|
-
- **Utility Components**: OxyIcon, Avatar, FollowButton, OxyLogo, FontLoader
|
|
132
|
-
|
|
133
|
-
---
|
|
134
|
-
|
|
135
|
-
## Installation
|
|
25
|
+
## Quick Start
|
|
136
26
|
|
|
137
27
|
```bash
|
|
138
|
-
# npm
|
|
139
28
|
npm install @oxyhq/services
|
|
140
|
-
|
|
141
|
-
# yarn
|
|
142
|
-
yarn add @oxyhq/services
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## Import Guide
|
|
146
|
-
|
|
147
|
-
The package provides different entry points for different use cases:
|
|
148
|
-
|
|
149
|
-
### Node.js/Express (Server-side only)
|
|
150
|
-
For server-side applications that only need core services and models:
|
|
151
|
-
|
|
152
|
-
```javascript
|
|
153
|
-
// CommonJS
|
|
154
|
-
const { OxyServices, Models } = require('@oxyhq/services');
|
|
155
|
-
|
|
156
|
-
// ES Modules
|
|
157
|
-
import { OxyServices, Models } from '@oxyhq/services';
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### React/React Native (UI components only)
|
|
161
|
-
For client-side applications that only need UI components:
|
|
162
|
-
|
|
163
|
-
```javascript
|
|
164
|
-
// Import UI components
|
|
165
|
-
import {
|
|
166
|
-
OxyProvider,
|
|
167
|
-
OxySignInButton,
|
|
168
|
-
OxyLogo,
|
|
169
|
-
Avatar,
|
|
170
|
-
FollowButton
|
|
171
|
-
} from '@oxyhq/services/ui';
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Full Package (Core + UI)
|
|
175
|
-
For applications that need both core services and UI components:
|
|
176
|
-
|
|
177
|
-
```javascript
|
|
178
|
-
// Import everything
|
|
179
|
-
import {
|
|
180
|
-
OxyServices,
|
|
181
|
-
OxyProvider,
|
|
182
|
-
OxySignInButton,
|
|
183
|
-
Models
|
|
184
|
-
} from '@oxyhq/services/full';
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
## Usage
|
|
188
|
-
|
|
189
|
-
This section details how to use the `@oxyhq/services` package in different JavaScript environments.
|
|
190
|
-
|
|
191
|
-
### Using in React Native
|
|
192
|
-
|
|
193
|
-
For React Native applications, you can import UI components and core services as needed:
|
|
194
|
-
|
|
195
|
-
```javascript
|
|
196
|
-
// Import core services
|
|
197
|
-
import { OxyServices } from '@oxyhq/services';
|
|
198
|
-
|
|
199
|
-
// Import UI components
|
|
200
|
-
import { OxyProvider, OxySignInButton } from '@oxyhq/services/ui';
|
|
201
|
-
|
|
202
|
-
// Or import everything together
|
|
203
|
-
import { OxyServices, OxyProvider, OxySignInButton } from '@oxyhq/services/full';
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
**Required Peer Dependencies:**
|
|
207
|
-
|
|
208
|
-
If you plan to use UI components that rely on native capabilities, such as the bottom sheet authentication UI, you'll need to install the following peer dependencies:
|
|
209
|
-
|
|
210
|
-
```bash
|
|
211
|
-
# npm
|
|
212
|
-
npm install react-native-gesture-handler react-native-reanimated react-native-safe-area-context
|
|
213
|
-
|
|
214
|
-
# yarn
|
|
215
|
-
yarn add react-native-gesture-handler react-native-reanimated react-native-safe-area-context
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
Note: The bottom sheet functionality is managed internally by the package, so you no longer need to install `@gorhom/bottom-sheet` directly.
|
|
219
|
-
|
|
220
|
-
Refer to the [UI Components](#ui-components) section for more information on available React Native components.
|
|
221
|
-
|
|
222
|
-
### Using in Node.js / Express
|
|
223
|
-
|
|
224
|
-
The `@oxyhq/services` package can also be used in Node.js backend environments.
|
|
225
|
-
|
|
226
|
-
**Installation:**
|
|
227
|
-
|
|
228
|
-
The installation is the same as for client-side usage:
|
|
229
|
-
```bash
|
|
230
|
-
# npm
|
|
231
|
-
npm install @oxyhq/services
|
|
232
|
-
|
|
233
|
-
# yarn
|
|
234
|
-
yarn add @oxyhq/services
|
|
235
29
|
```
|
|
236
30
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
You can import the class using either CommonJS or ES Modules syntax.
|
|
240
|
-
|
|
241
|
-
*CommonJS:*
|
|
242
|
-
```javascript
|
|
243
|
-
const { OxyServices } = require('@oxyhq/services');
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
*ES Modules:*
|
|
247
|
-
```javascript
|
|
31
|
+
```typescript
|
|
248
32
|
import { OxyServices } from '@oxyhq/services';
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
**Initializing `OxyServices`:**
|
|
252
|
-
|
|
253
|
-
Here's a brief example of how to initialize and use `OxyServices` in a Node.js context:
|
|
254
|
-
|
|
255
|
-
```javascript
|
|
256
|
-
const { OxyServices, OXY_CLOUD_URL } = require('@oxyhq/services'); // Or use import for ES Modules
|
|
257
33
|
|
|
258
34
|
const oxy = new OxyServices({
|
|
259
|
-
baseURL:
|
|
260
|
-
// In a Node.js environment, you typically don't use client-side storage for tokens.
|
|
261
|
-
// Token management should be handled per user session or through other server-side mechanisms.
|
|
35
|
+
baseURL: 'http://localhost:3000'
|
|
262
36
|
});
|
|
263
37
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
console.log('Login successful for user:', user.username);
|
|
269
|
-
// IMPORTANT: In a server environment, you would typically not store tokens in the OxyService instance directly.
|
|
270
|
-
// Instead, you would manage them securely, perhaps in an HTTP-only cookie, a session store,
|
|
271
|
-
// or by passing them to the client that initiated the request.
|
|
272
|
-
// The accessToken can then be used to make further API calls on behalf of this user.
|
|
273
|
-
} catch (error) {
|
|
274
|
-
console.error('Login failed:', error.message || error);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// Example usage:
|
|
279
|
-
// loginUser();
|
|
280
|
-
// (Call this function based on your application's logic, e.g., in an Express route handler)
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
#### Server Authentication Utilities
|
|
284
|
-
|
|
285
|
-
For Express.js applications, OxyServices provides built-in authentication middleware and utilities:
|
|
286
|
-
|
|
287
|
-
```javascript
|
|
288
|
-
const { OxyServices } = require('@oxyhq/services');
|
|
289
|
-
|
|
290
|
-
const oxyServices = new OxyServices({
|
|
291
|
-
baseURL: process.env.OXY_API_URL || 'https://api.oxy.so'
|
|
38
|
+
// Authenticate
|
|
39
|
+
const response = await oxy.auth.login({
|
|
40
|
+
email: 'user@example.com',
|
|
41
|
+
password: 'password'
|
|
292
42
|
});
|
|
293
43
|
|
|
294
|
-
//
|
|
295
|
-
const
|
|
296
|
-
loadFullUser: true, // Load complete user profile
|
|
297
|
-
onError: (error) => {
|
|
298
|
-
// Custom error handling
|
|
299
|
-
console.error('Auth error:', error);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
// Use middleware to protect routes
|
|
304
|
-
app.get('/api/protected', authenticateToken, (req, res) => {
|
|
305
|
-
// req.userId - User ID
|
|
306
|
-
// req.accessToken - Validated token
|
|
307
|
-
// req.user - Full user object (if loadFullUser: true)
|
|
308
|
-
res.json({ message: 'Access granted', user: req.user });
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
// Standalone token validation (for WebSocket, background jobs, etc.)
|
|
312
|
-
async function validateToken(token) {
|
|
313
|
-
const result = await oxyServices.authenticateToken(token);
|
|
314
|
-
return result.valid ? result.user : null;
|
|
315
|
-
}
|
|
44
|
+
// Get current user
|
|
45
|
+
const user = await oxy.users.getCurrentUser();
|
|
316
46
|
```
|
|
317
47
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
**Important Notes for Node.js Usage:**
|
|
48
|
+
## Documentation
|
|
321
49
|
|
|
322
|
-
|
|
323
|
-
* **Buffer File Uploads**: For file uploads, if you are providing data as a `Buffer` (common in Node.js when handling file streams or direct file reads), the package automatically uses `form-data` internally to correctly construct the multipart/form-data request. This ensures seamless file uploads from server-side buffers.
|
|
50
|
+
For comprehensive documentation, API reference, and examples:
|
|
324
51
|
|
|
325
|
-
|
|
52
|
+
- [📚 Full Documentation](./docs/README.md)
|
|
53
|
+
- [🚀 Quick Start Guide](./docs/quick-start.md)
|
|
54
|
+
- [🔐 Core API Reference](./docs/core-api.md)
|
|
55
|
+
- [💼 Integration Examples](./docs/examples/)
|
|
326
56
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
### Features
|
|
330
|
-
|
|
331
|
-
- **Multiple Account Support**: Users can sign in with multiple accounts and switch between them
|
|
332
|
-
- **Account Switcher**: Built-in UI component for easy account switching
|
|
333
|
-
- **Session Management**: View and manage active sessions across all devices
|
|
334
|
-
- **Remote Logout**: Log out from specific sessions remotely
|
|
335
|
-
- **Device Tracking**: Track session activity across different devices and platforms
|
|
336
|
-
|
|
337
|
-
### Usage
|
|
338
|
-
|
|
339
|
-
```typescript
|
|
340
|
-
import { OxyProvider, useOxy } from '@oxyhq/services/full';
|
|
341
|
-
|
|
342
|
-
// The OxyProvider automatically handles multi-user state
|
|
343
|
-
function App() {
|
|
344
|
-
return (
|
|
345
|
-
<OxyProvider oxyServices={oxyServices}>
|
|
346
|
-
<MyApp />
|
|
347
|
-
</OxyProvider>
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function MyApp() {
|
|
352
|
-
const {
|
|
353
|
-
user, // Current active user
|
|
354
|
-
users, // Array of all authenticated users
|
|
355
|
-
switchUser, // Switch to a different user
|
|
356
|
-
removeUser, // Remove a user from the account list
|
|
357
|
-
getUserSessions, // Get sessions for a user
|
|
358
|
-
logoutSession // Logout from a specific session
|
|
359
|
-
} = useOxy();
|
|
360
|
-
|
|
361
|
-
// Switch to a different user
|
|
362
|
-
const handleSwitchUser = async (userId) => {
|
|
363
|
-
await switchUser(userId);
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
// Remove a user account
|
|
367
|
-
const handleRemoveUser = async (userId) => {
|
|
368
|
-
await removeUser(userId);
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
// Get sessions for current user
|
|
372
|
-
const handleGetSessions = async () => {
|
|
373
|
-
const sessions = await getUserSessions();
|
|
374
|
-
console.log('Active sessions:', sessions);
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
return (
|
|
378
|
-
<div>
|
|
379
|
-
<h1>Welcome, {user?.username}</h1>
|
|
380
|
-
<p>You have {users.length} account(s) signed in</p>
|
|
381
|
-
|
|
382
|
-
{/* Account switcher */}
|
|
383
|
-
{users.length > 1 && (
|
|
384
|
-
<AccountSwitcher
|
|
385
|
-
users={users}
|
|
386
|
-
currentUser={user}
|
|
387
|
-
onSwitchUser={handleSwitchUser}
|
|
388
|
-
/>
|
|
389
|
-
)}
|
|
390
|
-
</div>
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
### Built-in UI Components
|
|
396
|
-
|
|
397
|
-
The library includes several UI components for multi-user functionality:
|
|
398
|
-
|
|
399
|
-
#### AccountSwitcherScreen
|
|
400
|
-
Displays all authenticated accounts and allows switching between them:
|
|
401
|
-
|
|
402
|
-
```typescript
|
|
403
|
-
import { AccountSwitcherScreen } from '@oxyhq/services/full';
|
|
404
|
-
|
|
405
|
-
// The component is automatically available through OxyProvider navigation
|
|
406
|
-
// Access via: showBottomSheet('AccountSwitcher')
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
#### SessionManagementScreen
|
|
410
|
-
Shows active sessions across devices with logout capabilities:
|
|
411
|
-
|
|
412
|
-
```typescript
|
|
413
|
-
import { SessionManagementScreen } from '@oxyhq/services/full';
|
|
414
|
-
|
|
415
|
-
// Access via: showBottomSheet('SessionManagement')
|
|
416
|
-
```
|
|
57
|
+
## UI Components
|
|
417
58
|
|
|
418
|
-
|
|
419
|
-
The sign-in screen now supports adding additional accounts:
|
|
59
|
+
Import and use pre-built React components:
|
|
420
60
|
|
|
421
61
|
```typescript
|
|
422
|
-
|
|
423
|
-
// automatically switches to "Add Account" mode
|
|
424
|
-
const { showBottomSheet } = useOxy();
|
|
425
|
-
|
|
426
|
-
// Show sign-in screen (will show "Add Account" if user is authenticated)
|
|
427
|
-
showBottomSheet('SignIn');
|
|
62
|
+
import { OxyProvider, Avatar, FollowButton } from '@oxyhq/services/ui';
|
|
428
63
|
```
|
|
429
64
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
#### Multi-User Context Methods
|
|
433
|
-
|
|
434
|
-
```typescript
|
|
435
|
-
interface OxyContextState {
|
|
436
|
-
// Multi-user state
|
|
437
|
-
user: User | null; // Current active user
|
|
438
|
-
users: AuthenticatedUser[]; // All authenticated users
|
|
439
|
-
|
|
440
|
-
// Multi-user methods
|
|
441
|
-
switchUser: (userId: string) => Promise<void>;
|
|
442
|
-
removeUser: (userId: string) => Promise<void>;
|
|
443
|
-
getUserSessions: (userId?: string) => Promise<SessionData[]>;
|
|
444
|
-
logoutSession: (sessionId: string, userId?: string) => Promise<void>;
|
|
445
|
-
logoutAll: () => Promise<void>; // Logout all users
|
|
446
|
-
}
|
|
447
|
-
```
|
|
65
|
+
## Package Exports
|
|
448
66
|
|
|
449
|
-
|
|
67
|
+
The library provides multiple entry points:
|
|
450
68
|
|
|
451
69
|
```typescript
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
deviceInfo: {
|
|
455
|
-
deviceType: string;
|
|
456
|
-
platform: string;m
|
|
457
|
-
browser?: string;
|
|
458
|
-
os?: string;
|
|
459
|
-
ipAddress: string;
|
|
460
|
-
lastActive: Date;
|
|
461
|
-
};
|
|
462
|
-
createdAt: Date;
|
|
463
|
-
isCurrent: boolean;
|
|
464
|
-
}
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
## Package Version Management
|
|
468
|
-
|
|
469
|
-
## Version Constants
|
|
470
|
-
|
|
471
|
-
To avoid runtime dependencies on `package.json`, version information is stored in `/src/constants/version.ts`. This ensures compatibility with bundlers and prevents Metro/Webpack resolution issues.
|
|
472
|
-
|
|
473
|
-
### Updating Version Information
|
|
474
|
-
|
|
475
|
-
When updating the package version in `package.json`, also update the version constants:
|
|
476
|
-
|
|
477
|
-
1. Update `package.json` version
|
|
478
|
-
2. Update `src/constants/version.ts` with the same version number
|
|
479
|
-
3. Run `npm run build` to generate updated library files
|
|
480
|
-
|
|
481
|
-
### Automatic Version Sync
|
|
482
|
-
|
|
483
|
-
You can add this script to `package.json` to automatically sync versions:
|
|
484
|
-
|
|
485
|
-
```json
|
|
486
|
-
{
|
|
487
|
-
"scripts": {
|
|
488
|
-
"version": "node scripts/update-version-constants.js && git add src/constants/version.ts"
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
```
|
|
492
|
-
|
|
493
|
-
Create `scripts/update-version-constants.js`:
|
|
494
|
-
|
|
495
|
-
```javascript
|
|
496
|
-
const fs = require('fs');
|
|
497
|
-
const packageJson = require('../package.json');
|
|
498
|
-
|
|
499
|
-
const versionFile = `/**
|
|
500
|
-
* Package version and metadata constants
|
|
501
|
-
* This file is auto-generated to avoid runtime dependency on package.json
|
|
502
|
-
*/
|
|
503
|
-
|
|
504
|
-
export const packageInfo = {
|
|
505
|
-
name: "${packageJson.name}",
|
|
506
|
-
version: "${packageJson.version}",
|
|
507
|
-
description: "${packageJson.description}",
|
|
508
|
-
main: "${packageJson.main}",
|
|
509
|
-
module: "${packageJson.module}",
|
|
510
|
-
types: "${packageJson.types}"
|
|
511
|
-
} as const;
|
|
70
|
+
// Core services only (Node.js/Express)
|
|
71
|
+
import { OxyServices } from '@oxyhq/services';
|
|
512
72
|
|
|
513
|
-
|
|
73
|
+
// UI components only (React/React Native)
|
|
74
|
+
import { OxyProvider, Avatar } from '@oxyhq/services/ui';
|
|
514
75
|
|
|
515
|
-
|
|
516
|
-
|
|
76
|
+
// Full package (Core + UI)
|
|
77
|
+
import { OxyServices, OxyProvider } from '@oxyhq/services/full';
|
|
517
78
|
```
|
|
518
79
|
|
|
519
|
-
|
|
80
|
+
## Requirements
|
|
520
81
|
|
|
521
|
-
|
|
82
|
+
- **Node.js** 16+ (for backend usage)
|
|
83
|
+
- **React** 16.8+ (for React components)
|
|
84
|
+
- **React Native** 0.60+ (for mobile components)
|
|
85
|
+
- **TypeScript** 4.0+ (optional but recommended)
|
|
522
86
|
|
|
523
|
-
|
|
524
|
-
import { packageInfo } from '../../constants/version';
|
|
87
|
+
## Development
|
|
525
88
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
// Use in reports or debugging
|
|
530
|
-
const appInfo = {
|
|
531
|
-
name: packageInfo.name,
|
|
532
|
-
version: packageInfo.version,
|
|
533
|
-
// ... other info
|
|
534
|
-
};
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
## Usage Examples
|
|
538
|
-
|
|
539
|
-
### File Management
|
|
89
|
+
```bash
|
|
90
|
+
# Install dependencies
|
|
91
|
+
npm install
|
|
540
92
|
|
|
541
|
-
|
|
93
|
+
# Build the library
|
|
94
|
+
npm run build
|
|
542
95
|
|
|
543
|
-
|
|
544
|
-
|
|
96
|
+
# Run tests
|
|
97
|
+
npm test
|
|
545
98
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
// Upload a file
|
|
550
|
-
async function uploadProfileImage(file, userId) {
|
|
551
|
-
const response = await oxyServices.uploadFile(file, 'profile.jpg', {
|
|
552
|
-
userId,
|
|
553
|
-
description: 'Profile picture',
|
|
554
|
-
tags: ['profile', 'avatar']
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
return response.file;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
// Download a file
|
|
561
|
-
function getFileUrl(fileId) {
|
|
562
|
-
return oxyServices.getFileDownloadUrl(fileId);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// List user files
|
|
566
|
-
async function getUserFiles(userId) {
|
|
567
|
-
const response = await oxyServices.listUserFiles(userId);
|
|
568
|
-
return response.files;
|
|
569
|
-
}
|
|
99
|
+
# Development mode
|
|
100
|
+
npm run dev
|
|
570
101
|
```
|
|
571
102
|
|
|
572
|
-
|
|
573
|
-
- [File Upload Example](examples/FileUploadExample.tsx) - Complete React Native component for file upload and management
|
|
574
|
-
- [GridFS Server Example](examples/GridFSServerExample.js) - Server-side implementation using Express and MongoDB
|
|
575
|
-
|
|
576
|
-
For detailed documentation on file management, see [FILE_MANAGEMENT.md](docs/FILE_MANAGEMENT.md).
|
|
577
|
-
|
|
578
|
-
### Export Structure
|
|
579
|
-
|
|
580
|
-
#### 🔧 Public API Components (Exported)
|
|
581
|
-
These are available for external use in your applications:
|
|
582
|
-
|
|
583
|
-
```typescript
|
|
584
|
-
// Context & Hooks
|
|
585
|
-
import { OxyProvider, OxyContextProvider, useOxy } from '@oxyhq/services';
|
|
586
|
-
|
|
587
|
-
// UI Components
|
|
588
|
-
import {
|
|
589
|
-
OxySignInButton,
|
|
590
|
-
OxyLogo,
|
|
591
|
-
Avatar,
|
|
592
|
-
FollowButton,
|
|
593
|
-
FontLoader,
|
|
594
|
-
OxyIcon
|
|
595
|
-
} from '@oxyhq/services';
|
|
596
|
-
|
|
597
|
-
// Device Management
|
|
598
|
-
import { DeviceManager } from '@oxyhq/services';
|
|
599
|
-
import type { DeviceFingerprint, StoredDeviceInfo } from '@oxyhq/services';
|
|
600
|
-
|
|
601
|
-
// Core Services
|
|
602
|
-
import { OxyServices } from '@oxyhq/services';
|
|
603
|
-
|
|
604
|
-
// Types
|
|
605
|
-
import type {
|
|
606
|
-
OxyContextState,
|
|
607
|
-
OxyContextProviderProps
|
|
608
|
-
} from '@oxyhq/services';
|
|
609
|
-
```
|
|
103
|
+
## Integration
|
|
610
104
|
|
|
611
|
-
|
|
612
|
-
|
|
105
|
+
This library works with:
|
|
106
|
+
- **[Oxy API](../oxy-api/)** - The companion authentication server
|
|
107
|
+
- **Express.js** - Built-in middleware support
|
|
108
|
+
- **React/React Native** - UI components and hooks
|
|
109
|
+
- **Next.js** - SSR/SSG authentication
|
|
613
110
|
|
|
614
|
-
|
|
615
|
-
- `AccountCenterScreen`, `SessionManagementScreen`
|
|
616
|
-
- `AccountOverviewScreen`, `AccountSettingsScreen`
|
|
617
|
-
- `KarmaCenterScreen`, `KarmaLeaderboardScreen`, `KarmaRewardsScreen`
|
|
618
|
-
- `KarmaRulesScreen`, `KarmaAboutScreen`, `KarmaFAQScreen`
|
|
619
|
-
- `AccountSwitcherScreen`, `AppInfoScreen`
|
|
111
|
+
## License
|
|
620
112
|
|
|
621
|
-
|
|
113
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|