@oxyhq/services 0.0.85 → 0.1.0
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 +269 -79
- package/dist/components/AuthBottomSheet/types.d.ts +24 -0
- package/dist/components/AuthBottomSheet/types.js +2 -0
- package/dist/components/FileSelectorModal/types.d.ts +35 -0
- package/dist/components/FileSelectorModal/types.js +2 -0
- package/dist/components/SessionProvider.d.ts +26 -0
- package/dist/components/SessionProvider.js +367 -0
- package/dist/config.d.ts +169 -0
- package/dist/config.js +115 -0
- package/dist/constants.d.ts +54 -0
- package/dist/constants.js +61 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/index.js +23 -0
- package/dist/hooks/useAuth.d.ts +6 -0
- package/dist/hooks/useAuth.js +17 -0
- package/dist/hooks/useFiles.d.ts +10 -0
- package/dist/hooks/useFiles.js +329 -0
- package/dist/hooks/useProfile.d.ts +13 -0
- package/dist/hooks/useProfile.js +154 -0
- package/dist/hooks/useSession.d.ts +2 -0
- package/dist/hooks/useSession.js +12 -0
- package/dist/hooks/useSubscription.d.ts +15 -0
- package/dist/hooks/useSubscription.js +85 -0
- package/dist/index.d.ts +28 -7
- package/dist/index.js +82 -6
- package/dist/package.json +71 -0
- package/dist/reducers/index.d.ts +8 -0
- package/dist/reducers/index.js +29 -0
- package/dist/reducers/profileReducer.d.ts +55 -0
- package/dist/reducers/profileReducer.js +136 -0
- package/dist/services/OxyClient.d.ts +84 -0
- package/dist/services/OxyClient.js +309 -0
- package/dist/services/api.service.d.ts +61 -0
- package/dist/services/api.service.js +289 -0
- package/dist/services/auth.service.d.ts +87 -0
- package/dist/services/auth.service.js +266 -0
- package/dist/services/index.d.ts +30 -0
- package/dist/services/index.js +88 -0
- package/dist/services/payment.service.d.ts +20 -0
- package/dist/services/payment.service.js +56 -0
- package/dist/services/privacy.service.d.ts +16 -0
- package/dist/services/privacy.service.js +69 -0
- package/dist/services/profile.service.d.ts +20 -0
- package/dist/services/profile.service.js +158 -0
- package/dist/services/subscription.service.d.ts +7 -0
- package/dist/services/subscription.service.js +46 -0
- package/dist/services/user.service.d.ts +25 -0
- package/dist/services/user.service.js +109 -0
- package/dist/styles/colors.d.ts +24 -0
- package/dist/styles/colors.js +31 -0
- package/dist/styles/shared.d.ts +168 -0
- package/dist/styles/shared.js +177 -0
- package/dist/types/index.d.ts +136 -2
- package/dist/types/index.js +7 -1
- package/dist/utils/api.d.ts +20 -0
- package/dist/utils/api.js +546 -0
- package/dist/utils/authEvents.d.ts +44 -0
- package/dist/utils/authEvents.js +73 -0
- package/dist/utils/errorHandler.d.ts +68 -0
- package/dist/utils/errorHandler.js +166 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +41 -0
- package/dist/utils/logger.d.ts +100 -0
- package/dist/utils/logger.js +298 -0
- package/dist/utils/socket.d.ts +6 -0
- package/dist/utils/socket.js +179 -0
- package/dist/utils/socketConfig.d.ts +32 -0
- package/dist/utils/socketConfig.js +67 -0
- package/dist/utils/storage.d.ts +54 -0
- package/dist/utils/storage.js +253 -0
- package/package.json +71 -59
- package/dist/assets/dot-icon.d.ts +0 -3
- package/dist/assets/dot-icon.d.ts.map +0 -1
- package/dist/assets/dot-icon.js +0 -6
- package/dist/assets/verified-icon.d.ts +0 -3
- package/dist/assets/verified-icon.d.ts.map +0 -1
- package/dist/assets/verified-icon.js +0 -10
- package/dist/components/assets/oxy-logo.d.ts +0 -3
- package/dist/components/assets/oxy-logo.d.ts.map +0 -1
- package/dist/components/assets/oxy-logo.js +0 -30
- package/dist/components/auth/AccountSwitcherModal.d.ts +0 -7
- package/dist/components/auth/AccountSwitcherModal.d.ts.map +0 -1
- package/dist/components/auth/AccountSwitcherModal.js +0 -91
- package/dist/components/auth/SessionOwnerButton.d.ts +0 -3
- package/dist/components/auth/SessionOwnerButton.d.ts.map +0 -1
- package/dist/components/auth/SessionOwnerButton.js +0 -35
- package/dist/components/auth/SignInButton.d.ts +0 -8
- package/dist/components/auth/SignInButton.d.ts.map +0 -1
- package/dist/components/auth/SignInButton.js +0 -15
- package/dist/components/auth/styles/account-switcher-modal.module.css +0 -29
- package/dist/components/auth/styles/account-switcher-modal.module.css.map +0 -1
- package/dist/components/auth/styles/oavatar.module.css +0 -34
- package/dist/components/auth/styles/oavatar.module.css.map +0 -1
- package/dist/components/auth/styles/session-owner-modal.module.css +0 -35
- package/dist/components/auth/styles/session-owner-modal.module.css.map +0 -1
- package/dist/components/auth/styles/sign-in-button.module.css +0 -30
- package/dist/components/auth/styles/sign-in-button.module.css.map +0 -1
- package/dist/components/elements/button/components/button.d.ts +0 -7
- package/dist/components/elements/button/components/button.d.ts.map +0 -1
- package/dist/components/elements/button/components/button.js +0 -6
- package/dist/components/elements/button/components/styles/button.module.css +0 -25
- package/dist/components/elements/button/components/styles/button.module.css.map +0 -1
- package/dist/components/elements/button/index.d.ts +0 -2
- package/dist/components/elements/button/index.d.ts.map +0 -1
- package/dist/components/elements/button/index.js +0 -1
- package/dist/components/elements/ellipsis-wrapper/components/EllipsisWrapper.d.ts +0 -5
- package/dist/components/elements/ellipsis-wrapper/components/EllipsisWrapper.d.ts.map +0 -1
- package/dist/components/elements/ellipsis-wrapper/components/EllipsisWrapper.js +0 -4
- package/dist/components/elements/ellipsis-wrapper/components/ellipsis-wrapper.d.ts +0 -5
- package/dist/components/elements/ellipsis-wrapper/components/ellipsis-wrapper.d.ts.map +0 -1
- package/dist/components/elements/ellipsis-wrapper/components/ellipsis-wrapper.js +0 -4
- package/dist/components/elements/ellipsis-wrapper/components/styles/ellipses-wrapper.module.css +0 -11
- package/dist/components/elements/ellipsis-wrapper/components/styles/ellipses-wrapper.module.css.map +0 -1
- package/dist/components/elements/ellipsis-wrapper/index.d.ts +0 -2
- package/dist/components/elements/ellipsis-wrapper/index.d.ts.map +0 -1
- package/dist/components/elements/ellipsis-wrapper/index.js +0 -1
- package/dist/components/elements/modal/components/confirmation-modal.d.ts +0 -12
- package/dist/components/elements/modal/components/confirmation-modal.d.ts.map +0 -1
- package/dist/components/elements/modal/components/confirmation-modal.js +0 -21
- package/dist/components/elements/modal/components/modal.d.ts +0 -13
- package/dist/components/elements/modal/components/modal.d.ts.map +0 -1
- package/dist/components/elements/modal/components/modal.js +0 -111
- package/dist/components/elements/modal/components/styles/confirmation-modal.module.css +0 -105
- package/dist/components/elements/modal/components/styles/confirmation-modal.module.css.map +0 -1
- package/dist/components/elements/modal/components/styles/modal.module.css +0 -10
- package/dist/components/elements/modal/components/styles/modal.module.css.map +0 -1
- package/dist/components/elements/modal/hooks/use-track-position.d.ts +0 -5
- package/dist/components/elements/modal/hooks/use-track-position.d.ts.map +0 -1
- package/dist/components/elements/modal/hooks/use-track-position.js +0 -35
- package/dist/components/elements/modal/index.d.ts +0 -4
- package/dist/components/elements/modal/index.d.ts.map +0 -1
- package/dist/components/elements/modal/index.js +0 -3
- package/dist/config/index.d.ts +0 -21
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -7
- package/dist/features/profile/components/avatar.d.ts +0 -10
- package/dist/features/profile/components/avatar.d.ts.map +0 -1
- package/dist/features/profile/components/avatar.js +0 -7
- package/dist/features/profile/components/styles/avatar.module.css +0 -15
- package/dist/features/profile/components/styles/avatar.module.css.map +0 -1
- package/dist/features/profile/components/styles/user-name.module.css +0 -18
- package/dist/features/profile/components/styles/user-name.module.css.map +0 -1
- package/dist/features/profile/components/styles/user-username.module.css +0 -6
- package/dist/features/profile/components/styles/user-username.module.css.map +0 -1
- package/dist/features/profile/components/user-name.d.ts +0 -7
- package/dist/features/profile/components/user-name.d.ts.map +0 -1
- package/dist/features/profile/components/user-name.js +0 -8
- package/dist/features/profile/components/user-username.d.ts +0 -5
- package/dist/features/profile/components/user-username.d.ts.map +0 -1
- package/dist/features/profile/components/user-username.js +0 -7
- package/dist/features/profile/index.d.ts +0 -4
- package/dist/features/profile/index.d.ts.map +0 -1
- package/dist/features/profile/index.js +0 -3
- package/dist/hooks/get-user.d.ts +0 -2
- package/dist/hooks/get-user.d.ts.map +0 -1
- package/dist/hooks/get-user.js +0 -31
- package/dist/hooks/getClientKey.d.ts +0 -2
- package/dist/hooks/getClientKey.d.ts.map +0 -1
- package/dist/hooks/getClientKey.js +0 -19
- package/dist/hooks/getUserById.d.ts +0 -11
- package/dist/hooks/getUserById.d.ts.map +0 -1
- package/dist/hooks/getUserById.js +0 -31
- package/dist/hooks/use-user.d.ts +0 -14
- package/dist/hooks/use-user.d.ts.map +0 -1
- package/dist/hooks/use-user.js +0 -8
- package/dist/hooks/useCrossDomainStorage.d.ts +0 -6
- package/dist/hooks/useCrossDomainStorage.d.ts.map +0 -1
- package/dist/hooks/useCrossDomainStorage.js +0 -24
- package/dist/hooks/useOxySession.d.ts +0 -30
- package/dist/hooks/useOxySession.d.ts.map +0 -1
- package/dist/hooks/useOxySession.js +0 -64
- package/dist/index.css +0 -5
- package/dist/index.css.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interfaces/index.d.ts +0 -10
- package/dist/interfaces/index.d.ts.map +0 -1
- package/dist/interfaces/index.js +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/utils/cn.d.ts +0 -3
- package/dist/utils/cn.d.ts.map +0 -1
- package/dist/utils/cn.js +0 -5
package/README.md
CHANGED
|
@@ -1,114 +1,304 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OxyHQ Services Module
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A comprehensive module for interacting with the OxyHQ platform APIs. This module provides authentication, profile management, file handling, and other services.
|
|
4
4
|
|
|
5
|
-
## Features
|
|
6
|
-
- **Session Management**: Easily manage user sessions with hooks like `useOxySession`.
|
|
7
|
-
- **User Handling**: Fetch and display user information using functions like `getUserById`.
|
|
8
|
-
- **Components**: Ready-to-use components such as `SignInButton`, `AccountSwitcherModal`, and `SessionOwnerButton`.
|
|
5
|
+
## Features
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
- 🔐 **Authentication**: Complete authentication flow with token management
|
|
8
|
+
- 👤 **Profile Management**: User profile creation, retrieval, and updates
|
|
9
|
+
- 📁 **File Handling**: Upload, download, and manage files
|
|
10
|
+
- 💳 **Payments**: Process payments and manage subscriptions
|
|
11
|
+
- 🔄 **Caching**: Efficient data caching for improved performance
|
|
12
|
+
- 🔌 **Offline Support**: Graceful handling of offline scenarios
|
|
13
|
+
- 📊 **Analytics**: User activity tracking and reporting
|
|
14
|
+
- 🚀 **Performance Optimized**: Lazy loading, request deduplication, and more
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
## Installation
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
+
```bash
|
|
19
|
+
npm install @oxyhq/services
|
|
20
|
+
```
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
import { useOxySession, getUserById, SignInButton, AccountSwitcherModal, SessionOwnerButton } from '@oxyhq/services';
|
|
22
|
-
```
|
|
22
|
+
## Quick Start
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import React from 'react';
|
|
27
|
-
import { SignInButton } from '@oxyhq/services';
|
|
24
|
+
```typescript
|
|
25
|
+
import { initialize, authService, oxyClient } from '@oxyhq/services';
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
27
|
+
// Initialize the module with custom configuration
|
|
28
|
+
initialize({
|
|
29
|
+
apiUrl: 'https://api.your-instance.oxy.so',
|
|
30
|
+
enableLogging: true,
|
|
31
|
+
logLevel: 'debug'
|
|
32
|
+
});
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
// Use the authentication service
|
|
35
|
+
const login = async () => {
|
|
36
|
+
try {
|
|
37
|
+
const result = await authService.login({
|
|
38
|
+
email: 'user@example.com',
|
|
39
|
+
password: 'password123'
|
|
40
|
+
});
|
|
41
|
+
console.log('Logged in successfully', result.user);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Login failed', error);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
39
46
|
|
|
40
|
-
|
|
47
|
+
// Get a user profile
|
|
48
|
+
const getProfile = async (userId) => {
|
|
49
|
+
try {
|
|
50
|
+
const profile = await oxyClient.getProfile(userId);
|
|
51
|
+
console.log('Profile retrieved', profile);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('Failed to get profile', error);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
```
|
|
41
57
|
|
|
42
|
-
|
|
58
|
+
## Architecture
|
|
43
59
|
|
|
44
|
-
The
|
|
60
|
+
The OxyHQ Services module is built with a focus on performance, maintainability, and developer experience. Key architectural features include:
|
|
45
61
|
|
|
46
|
-
|
|
47
|
-
import React from 'react';
|
|
48
|
-
import { useOxySession } from '@oxyhq/services';
|
|
62
|
+
### Service Layer
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
const { session, status, error } = useOxySession();
|
|
64
|
+
The module is organized into specialized services, each responsible for a specific domain:
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
- **ApiService**: Core HTTP client with caching, retry logic, and token management
|
|
67
|
+
- **AuthService**: Authentication and session management
|
|
68
|
+
- **OxyClient**: High-level client for OxyHQ platform features
|
|
69
|
+
- **ProfileService**: User profile management
|
|
70
|
+
- **PaymentService**: Payment processing
|
|
71
|
+
- **SubscriptionService**: Subscription management
|
|
72
|
+
- **PrivacyService**: Privacy settings management
|
|
56
73
|
|
|
57
|
-
|
|
58
|
-
return <div>Error: {error}</div>;
|
|
59
|
-
}
|
|
74
|
+
### Lazy Loading
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
<div>
|
|
63
|
-
<h1>Welcome, {session.user.name}!</h1>
|
|
64
|
-
<p>Email: {session.user.email}</p>
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
};
|
|
76
|
+
Services are lazy-loaded to minimize initial bundle size and improve startup performance. The module exports getter functions that instantiate services only when needed:
|
|
68
77
|
|
|
69
|
-
|
|
78
|
+
```typescript
|
|
79
|
+
import { getAuthService, getOxyClient } from '@oxyhq/services';
|
|
80
|
+
|
|
81
|
+
// Service is instantiated only when called
|
|
82
|
+
const auth = getAuthService();
|
|
70
83
|
```
|
|
71
84
|
|
|
72
|
-
###
|
|
85
|
+
### Caching System
|
|
73
86
|
|
|
74
|
-
The
|
|
87
|
+
The module includes a sophisticated caching system to minimize network requests:
|
|
75
88
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
89
|
+
- **In-memory Cache**: Fast access to recently used data
|
|
90
|
+
- **Persistent Cache**: Data is stored for offline access
|
|
91
|
+
- **Cache Invalidation**: Automatic and manual cache invalidation strategies
|
|
92
|
+
- **TTL Support**: Time-based expiration for cached items
|
|
79
93
|
|
|
80
|
-
|
|
81
|
-
const [user, setUser] = useState(null);
|
|
82
|
-
const [error, setError] = useState(null);
|
|
94
|
+
### Error Handling
|
|
83
95
|
|
|
84
|
-
|
|
85
|
-
const fetchUser = async () => {
|
|
86
|
-
try {
|
|
87
|
-
const fetchedUser = await getUserById(userId);
|
|
88
|
-
setUser(fetchedUser);
|
|
89
|
-
} catch (err) {
|
|
90
|
-
setError(err.message);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
96
|
+
Comprehensive error handling with:
|
|
93
97
|
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
- **Error Normalization**: Consistent error format across services
|
|
99
|
+
- **Retry Logic**: Automatic retry for transient failures
|
|
100
|
+
- **Offline Detection**: Graceful handling of network unavailability
|
|
101
|
+
- **Detailed Logging**: Contextual error information for debugging
|
|
96
102
|
|
|
97
|
-
|
|
98
|
-
return <div>Error: {error}</div>;
|
|
99
|
-
}
|
|
103
|
+
### Logging
|
|
100
104
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
A centralized logging system with:
|
|
106
|
+
|
|
107
|
+
- **Log Levels**: DEBUG, INFO, WARN, ERROR, FATAL
|
|
108
|
+
- **Context Support**: Logs include contextual information
|
|
109
|
+
- **Remote Logging**: Optional sending of logs to a remote server
|
|
110
|
+
- **Performance Metrics**: Timing of operations for performance analysis
|
|
111
|
+
- **Sensitive Data Redaction**: Automatic redaction of sensitive information
|
|
112
|
+
|
|
113
|
+
## API Reference
|
|
114
|
+
|
|
115
|
+
### Core Services
|
|
116
|
+
|
|
117
|
+
#### ApiService
|
|
118
|
+
|
|
119
|
+
Low-level HTTP client with caching, retry logic, and token management.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { apiService } from '@oxyhq/services';
|
|
123
|
+
|
|
124
|
+
// GET request with caching
|
|
125
|
+
const data = await apiService.get('/endpoint', {
|
|
126
|
+
useCache: true,
|
|
127
|
+
cacheTTL: 5 * 60 * 1000 // 5 minutes
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// POST request
|
|
131
|
+
const result = await apiService.post('/endpoint', { data: 'value' });
|
|
132
|
+
|
|
133
|
+
// Cancel requests
|
|
134
|
+
apiService.cancelAllRequests();
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### OxyClient
|
|
138
|
+
|
|
139
|
+
High-level client for OxyHQ platform features.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { oxyClient } from '@oxyhq/services';
|
|
143
|
+
|
|
144
|
+
// Get user profile
|
|
145
|
+
const profile = await oxyClient.getProfile('user-id');
|
|
146
|
+
|
|
147
|
+
// Get file data
|
|
148
|
+
const files = await oxyClient.getFilesData(['file-id-1', 'file-id-2']);
|
|
149
|
+
|
|
150
|
+
// Get recommendations
|
|
151
|
+
const recommendations = await oxyClient.getRecommendations(10);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Authentication
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { authService } from '@oxyhq/services';
|
|
158
|
+
|
|
159
|
+
// Login
|
|
160
|
+
const loginResult = await authService.login({
|
|
161
|
+
email: 'user@example.com',
|
|
162
|
+
password: 'password123'
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Register
|
|
166
|
+
const registerResult = await authService.register({
|
|
167
|
+
username: 'newuser',
|
|
168
|
+
email: 'newuser@example.com',
|
|
169
|
+
password: 'password123'
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Logout
|
|
173
|
+
await authService.logout();
|
|
174
|
+
|
|
175
|
+
// Check if user is authenticated
|
|
176
|
+
const isAuthenticated = await authService.isAuthenticated();
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### User Management
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { userService } from '@oxyhq/services';
|
|
183
|
+
|
|
184
|
+
// Get current user
|
|
185
|
+
const currentUser = await userService.getCurrentUser();
|
|
186
|
+
|
|
187
|
+
// Update user profile
|
|
188
|
+
await userService.updateProfile({
|
|
189
|
+
name: {
|
|
190
|
+
first: 'John',
|
|
191
|
+
last: 'Doe'
|
|
192
|
+
},
|
|
193
|
+
avatar: 'avatar-url'
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Follow a user
|
|
197
|
+
await userService.followUser('user-id-to-follow');
|
|
198
|
+
|
|
199
|
+
// Unfollow a user
|
|
200
|
+
await userService.unfollowUser('user-id-to-unfollow');
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### File Management
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { useFiles } from '@oxyhq/services';
|
|
207
|
+
|
|
208
|
+
// In a React component
|
|
209
|
+
function MyComponent() {
|
|
210
|
+
const {
|
|
211
|
+
uploadFile,
|
|
212
|
+
deleteFile,
|
|
213
|
+
getFileUrl,
|
|
214
|
+
isUploading
|
|
215
|
+
} = useFiles();
|
|
216
|
+
|
|
217
|
+
const handleUpload = async (file) => {
|
|
218
|
+
const fileId = await uploadFile(file);
|
|
219
|
+
console.log('File uploaded with ID:', fileId);
|
|
220
|
+
};
|
|
104
221
|
|
|
105
222
|
return (
|
|
106
223
|
<div>
|
|
107
|
-
<
|
|
108
|
-
<p>
|
|
224
|
+
<input type="file" onChange={(e) => handleUpload(e.target.files[0])} />
|
|
225
|
+
{isUploading && <p>Uploading...</p>}
|
|
109
226
|
</div>
|
|
110
227
|
);
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Configuration
|
|
232
|
+
|
|
233
|
+
The module can be configured using the `initialize` function:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { initialize } from '@oxyhq/services';
|
|
237
|
+
|
|
238
|
+
initialize({
|
|
239
|
+
apiUrl: 'https://api.custom-instance.oxy.so',
|
|
240
|
+
cloudUrl: 'https://files.custom-instance.oxy.so',
|
|
241
|
+
enableLogging: true,
|
|
242
|
+
logLevel: 'debug',
|
|
243
|
+
enableOfflineMode: true
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Advanced Usage
|
|
248
|
+
|
|
249
|
+
### Custom Error Handling
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
import { errorHandler } from '@oxyhq/services';
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
// Your code
|
|
256
|
+
} catch (error) {
|
|
257
|
+
errorHandler.handleError(error, {
|
|
258
|
+
context: 'Custom operation',
|
|
259
|
+
fallbackMessage: 'Operation failed',
|
|
260
|
+
showToast: true,
|
|
261
|
+
onAuthError: () => {
|
|
262
|
+
// Handle authentication errors
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Performance Logging
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { logger } from '@oxyhq/services';
|
|
272
|
+
|
|
273
|
+
const performOperation = async () => {
|
|
274
|
+
const startTime = Date.now();
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
// Perform operation
|
|
278
|
+
await someExpensiveOperation();
|
|
279
|
+
} finally {
|
|
280
|
+
// Log performance metrics
|
|
281
|
+
logger.logPerformance('someExpensiveOperation', startTime, 'MyComponent');
|
|
282
|
+
}
|
|
111
283
|
};
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Scoped Logging
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import { logger } from '@oxyhq/services';
|
|
290
|
+
|
|
291
|
+
// Create a logger scoped to a specific context
|
|
292
|
+
const componentLogger = logger.createScopedLogger('MyComponent');
|
|
112
293
|
|
|
113
|
-
|
|
294
|
+
componentLogger.info('Component initialized');
|
|
295
|
+
componentLogger.error('Error in component', { details: 'error details' });
|
|
114
296
|
```
|
|
297
|
+
|
|
298
|
+
## Contributing
|
|
299
|
+
|
|
300
|
+
We welcome contributions to the OxyHQ Services module! Please see our [Contributing Guide](CONTRIBUTING.md) for more information.
|
|
301
|
+
|
|
302
|
+
## License
|
|
303
|
+
|
|
304
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { OxyProfile } from '../../types';
|
|
2
|
+
export type AuthMode = 'signin' | 'signup' | 'session';
|
|
3
|
+
export interface AuthBottomSheetProps {
|
|
4
|
+
/** Initial auth mode to display */
|
|
5
|
+
initialMode?: AuthMode;
|
|
6
|
+
/** Whether to show the logo in the header (default: true) */
|
|
7
|
+
showLogo?: boolean;
|
|
8
|
+
/** Callback when authentication is successful */
|
|
9
|
+
onSuccess?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface UserSession {
|
|
12
|
+
id: string;
|
|
13
|
+
username: string;
|
|
14
|
+
name?: {
|
|
15
|
+
first?: string;
|
|
16
|
+
last?: string;
|
|
17
|
+
};
|
|
18
|
+
avatar?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Session {
|
|
21
|
+
id: string;
|
|
22
|
+
profile: OxyProfile;
|
|
23
|
+
lastActive: Date;
|
|
24
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface FileType {
|
|
2
|
+
_id: string;
|
|
3
|
+
filename: string;
|
|
4
|
+
contentType: string;
|
|
5
|
+
uploadDate: string;
|
|
6
|
+
length: number;
|
|
7
|
+
metadata?: {
|
|
8
|
+
userID: string;
|
|
9
|
+
originalname?: string;
|
|
10
|
+
sanitizedFilename?: string;
|
|
11
|
+
size?: number;
|
|
12
|
+
uploadDate?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface FileSelectorModalProps {
|
|
16
|
+
isVisible: boolean;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
onSelect: (files: FileType[]) => void;
|
|
19
|
+
options?: {
|
|
20
|
+
fileTypeFilter?: string[];
|
|
21
|
+
maxFiles?: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface UseFilesOptions {
|
|
25
|
+
fileTypeFilter?: string[];
|
|
26
|
+
maxFiles?: number;
|
|
27
|
+
userId?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface FileItemProps {
|
|
30
|
+
file: FileType;
|
|
31
|
+
isSelected: boolean;
|
|
32
|
+
onSelect: (file: FileType) => void;
|
|
33
|
+
onDelete: (fileId: string) => void;
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { User } from '../services/auth.service';
|
|
3
|
+
import type { UserSession } from '../services/user.service';
|
|
4
|
+
interface SessionState {
|
|
5
|
+
userId: string | null;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
error: string | null;
|
|
8
|
+
user: User | null;
|
|
9
|
+
sessions: UserSession[];
|
|
10
|
+
lastActivity: number;
|
|
11
|
+
}
|
|
12
|
+
export interface SessionContextType {
|
|
13
|
+
state: SessionState;
|
|
14
|
+
loginUser: (username: string, password: string) => Promise<void>;
|
|
15
|
+
logoutUser: () => Promise<boolean>;
|
|
16
|
+
getCurrentUserId: () => string | null;
|
|
17
|
+
switchSession: (userId: string) => Promise<void>;
|
|
18
|
+
refreshTokenIfNeeded: () => Promise<boolean>;
|
|
19
|
+
sessions: UserSession[];
|
|
20
|
+
isAuthenticated: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const SessionContext: import("react").Context<SessionContextType | null>;
|
|
23
|
+
export declare function SessionProvider({ children }: {
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
}): import("react").JSX.Element;
|
|
26
|
+
export {};
|