@oxyhq/services 0.1.13 → 0.1.16
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 +151 -320
- package/dist/index.d.ts +152 -3
- package/dist/index.js +1 -2
- package/package.json +10 -3
- package/dist/backend/auth.d.ts +0 -37
- package/dist/backend/index.d.ts +0 -12
- package/dist/backend/karma.d.ts +0 -45
- package/dist/backend/users.d.ts +0 -39
- package/dist/backend/wallet.d.ts +0 -29
- package/dist/bundle.js +0 -2
- package/dist/bundle.js.LICENSE.txt +0 -9
- package/dist/frontend/context/OxyContext.d.ts +0 -20
- package/dist/frontend/hooks/useAuth.d.ts +0 -20
- package/dist/frontend/hooks/useKarma.d.ts +0 -27
- package/dist/frontend/hooks/useUser.d.ts +0 -13
- package/dist/frontend/hooks/useWallet.d.ts +0 -14
- package/dist/frontend/index.d.ts +0 -6
- package/dist/index.js.LICENSE.txt +0 -9
- package/dist/shared/api-client.d.ts +0 -15
- package/dist/shared/types.d.ts +0 -136
package/README.md
CHANGED
|
@@ -1,350 +1,181 @@
|
|
|
1
1
|
# Oxy Services Module
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A unified client library for the Oxy API (authentication, user management, notifications, payments, analytics, wallet, and karma).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
7
|
+
- [Overview](#overview)
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Usage](#usage)
|
|
10
|
+
- [Configuration](#configuration)
|
|
11
|
+
- [API Reference](#api-reference)
|
|
12
|
+
- [OxyConfig](#oxyconfig)
|
|
13
|
+
- [Class: OxyServices](#class-oxyservices)
|
|
14
|
+
- [Examples](#examples)
|
|
15
|
+
- [Development](#development)
|
|
16
|
+
- [Contributing](#contributing)
|
|
17
|
+
- [License](#license)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Overview
|
|
22
|
+
|
|
23
|
+
The `@oxyhq/services` package provides a simple, promise-based client to interact with the Oxy API. It wraps HTTP calls to endpoints for:
|
|
24
|
+
|
|
25
|
+
- Authentication (signup, login, token refresh, logout, validation)
|
|
26
|
+
- User & profile operations (fetch, update, follow/unfollow)
|
|
27
|
+
- Real‑time notifications (list, create, mark read, delete)
|
|
28
|
+
- Payments & wallet (process payment, validate method, transfer funds, purchase, withdrawal)
|
|
29
|
+
- Analytics & content insights (time‑series data, viewers, follower stats)
|
|
30
|
+
- Karma system (leaderboard, rules, award/deduct points)
|
|
31
|
+
|
|
32
|
+
This library is framework-agnostic and works in Node.js, browser, and React Native environments.
|
|
11
33
|
|
|
12
34
|
## Installation
|
|
13
35
|
|
|
14
36
|
```bash
|
|
15
|
-
npm install @oxyhq/services
|
|
37
|
+
npm install @oxyhq/services axios jwt-decode
|
|
16
38
|
```
|
|
17
39
|
|
|
18
|
-
|
|
40
|
+
> **Peer Dependencies**: React, React Native, and optional storage libraries if used in mobile apps.
|
|
19
41
|
|
|
20
|
-
|
|
42
|
+
## Usage
|
|
21
43
|
|
|
22
44
|
```typescript
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// Handle login failure
|
|
36
|
-
console.error('Login failed:', response.error);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// Use user service
|
|
41
|
-
const getUserProfile = async (userId) => {
|
|
42
|
-
const response = await oxyBackend.users.getUserById(userId);
|
|
43
|
-
if (response.success) {
|
|
44
|
-
console.log('User profile:', response.data);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// Use karma service
|
|
49
|
-
const getUserKarma = async (userId) => {
|
|
50
|
-
const response = await oxyBackend.karma.getUserKarma(userId);
|
|
51
|
-
if (response.success) {
|
|
52
|
-
console.log('User karma:', response.data.karma);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Use wallet service
|
|
57
|
-
const getWallet = async (userId) => {
|
|
58
|
-
const response = await oxyBackend.wallet.getWallet(userId);
|
|
59
|
-
if (response.success) {
|
|
60
|
-
console.log('Wallet balance:', response.data.balance);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
45
|
+
import OxyServices, { OxyConfig } from '@oxyhq/services';
|
|
46
|
+
|
|
47
|
+
const config: OxyConfig = { baseURL: 'https://api.mention.earth' };
|
|
48
|
+
const client = new OxyServices(config);
|
|
49
|
+
|
|
50
|
+
// Authenticate and start using API
|
|
51
|
+
(async () => {
|
|
52
|
+
const login = await client.login('alice', 'Secret123!');
|
|
53
|
+
console.log('Logged in user:', login.user);
|
|
54
|
+
const profile = await client.getProfileByUsername('bob');
|
|
55
|
+
console.log('Bob’s profile:', profile);
|
|
56
|
+
})();
|
|
63
57
|
```
|
|
64
58
|
|
|
65
|
-
|
|
59
|
+
## Configuration
|
|
66
60
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
import React, { useState, useEffect } from 'react';
|
|
71
|
-
import { OxyProvider, useAuth, useUser, useKarma, useWallet } from '@oxyhq/services';
|
|
72
|
-
|
|
73
|
-
// Wrap your app with OxyProvider
|
|
74
|
-
function App() {
|
|
75
|
-
return (
|
|
76
|
-
<OxyProvider apiUrl="https://api.oxy.example.com" storage="local">
|
|
77
|
-
<AuthenticatedApp />
|
|
78
|
-
</OxyProvider>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
61
|
+
`OxyConfig`:
|
|
81
62
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const wallet = useWallet();
|
|
89
|
-
|
|
90
|
-
// State for login form
|
|
91
|
-
const [username, setUsername] = useState('');
|
|
92
|
-
const [password, setPassword] = useState('');
|
|
93
|
-
const [authStatus, setAuthStatus] = useState(false);
|
|
94
|
-
|
|
95
|
-
// Check authentication status on component mount and when auth changes
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
const checkAuth = async () => {
|
|
98
|
-
const isAuthenticated = await auth.isAuthenticated();
|
|
99
|
-
setAuthStatus(isAuthenticated);
|
|
100
|
-
|
|
101
|
-
// If authenticated but no user data, fetch the user profile
|
|
102
|
-
if (isAuthenticated && !auth.user) {
|
|
103
|
-
await auth.getCurrentUser();
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
checkAuth();
|
|
108
|
-
}, [auth]);
|
|
109
|
-
|
|
110
|
-
const handleLogin = async () => {
|
|
111
|
-
const result = await auth.login({
|
|
112
|
-
username,
|
|
113
|
-
password
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
if (result.success) {
|
|
117
|
-
console.log('Logged in successfully');
|
|
118
|
-
// User data should be automatically set from the response
|
|
119
|
-
// which may include a user object directly
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
return (
|
|
124
|
-
<div>
|
|
125
|
-
{authStatus ? (
|
|
126
|
-
<div>
|
|
127
|
-
<h2>Welcome, {auth.user?.username}</h2>
|
|
128
|
-
<button onClick={auth.logout}>Logout</button>
|
|
129
|
-
</div>
|
|
130
|
-
) : (
|
|
131
|
-
<form onSubmit={(e) => {
|
|
132
|
-
e.preventDefault();
|
|
133
|
-
handleLogin();
|
|
134
|
-
}}>
|
|
135
|
-
<input
|
|
136
|
-
type="text"
|
|
137
|
-
value={username}
|
|
138
|
-
onChange={(e) => setUsername(e.target.value)}
|
|
139
|
-
placeholder="Username"
|
|
140
|
-
/>
|
|
141
|
-
<input
|
|
142
|
-
type="password"
|
|
143
|
-
value={password}
|
|
144
|
-
onChange={(e) => setPassword(e.target.value)}
|
|
145
|
-
placeholder="Password"
|
|
146
|
-
/>
|
|
147
|
-
<button type="submit">Login</button>
|
|
148
|
-
</form>
|
|
149
|
-
)}
|
|
150
|
-
</div>
|
|
151
|
-
);
|
|
63
|
+
```ts
|
|
64
|
+
interface OxyConfig {
|
|
65
|
+
/** Base URL of the Oxy API, e.g. https://api.mention.earth */
|
|
66
|
+
baseURL: string;
|
|
67
|
+
/** Optional timeout in milliseconds (default: 0 for no timeout) */
|
|
68
|
+
timeout?: number;
|
|
152
69
|
}
|
|
153
|
-
|
|
154
|
-
export default App;
|
|
155
70
|
```
|
|
156
71
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
```typescript
|
|
160
|
-
import React, { useState, useEffect } from 'react';
|
|
161
|
-
import { useAuth, useUser, useKarma, useWallet } from '@oxyhq/services';
|
|
162
|
-
|
|
163
|
-
function App() {
|
|
164
|
-
// Use authentication hook
|
|
165
|
-
const auth = useAuth({
|
|
166
|
-
apiUrl: 'https://api.oxy.example.com',
|
|
167
|
-
storage: 'local',
|
|
168
|
-
tokenRefreshInterval: 1000 * 60 * 15 // 15 minutes
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
// Use user management hook
|
|
172
|
-
const user = useUser({
|
|
173
|
-
apiUrl: 'https://api.oxy.example.com',
|
|
174
|
-
getToken: auth.getToken
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// Use karma hook
|
|
178
|
-
const karma = useKarma({
|
|
179
|
-
apiUrl: 'https://api.oxy.example.com',
|
|
180
|
-
getToken: auth.getToken
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// Use wallet hook
|
|
184
|
-
const wallet = useWallet({
|
|
185
|
-
apiUrl: 'https://api.oxy.example.com',
|
|
186
|
-
getToken: auth.getToken
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// State for login form and auth status
|
|
190
|
-
const [username, setUsername] = useState('');
|
|
191
|
-
const [password, setPassword] = useState('');
|
|
192
|
-
const [authStatus, setAuthStatus] = useState(false);
|
|
193
|
-
|
|
194
|
-
// Check authentication status on component mount and when auth changes
|
|
195
|
-
useEffect(() => {
|
|
196
|
-
const checkAuth = async () => {
|
|
197
|
-
const isAuthenticated = await auth.isAuthenticated();
|
|
198
|
-
setAuthStatus(isAuthenticated);
|
|
199
|
-
|
|
200
|
-
// If authenticated but no user data, fetch the user profile
|
|
201
|
-
if (isAuthenticated && !auth.user) {
|
|
202
|
-
await auth.getCurrentUser();
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
checkAuth();
|
|
207
|
-
}, [auth]);
|
|
208
|
-
|
|
209
|
-
const handleLogin = async () => {
|
|
210
|
-
const result = await auth.login({
|
|
211
|
-
username,
|
|
212
|
-
password
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
if (result.success) {
|
|
216
|
-
console.log('Logged in successfully');
|
|
217
|
-
// User data should be automatically set from the response
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
return (
|
|
222
|
-
<div>
|
|
223
|
-
{authStatus ? (
|
|
224
|
-
<div>
|
|
225
|
-
<h2>Welcome, {auth.user?.username}</h2>
|
|
226
|
-
<button onClick={auth.logout}>Logout</button>
|
|
227
|
-
</div>
|
|
228
|
-
) : (
|
|
229
|
-
<form onSubmit={(e) => {
|
|
230
|
-
e.preventDefault();
|
|
231
|
-
handleLogin();
|
|
232
|
-
}}>
|
|
233
|
-
<input
|
|
234
|
-
type="text"
|
|
235
|
-
value={username}
|
|
236
|
-
onChange={(e) => setUsername(e.target.value)}
|
|
237
|
-
placeholder="Username"
|
|
238
|
-
/>
|
|
239
|
-
<input
|
|
240
|
-
type="password"
|
|
241
|
-
value={password}
|
|
242
|
-
onChange={(e) => setPassword(e.target.value)}
|
|
243
|
-
placeholder="Password"
|
|
244
|
-
/>
|
|
245
|
-
<button type="submit">Login</button>
|
|
246
|
-
</form>
|
|
247
|
-
)}
|
|
248
|
-
</div>
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export default App;
|
|
253
|
-
```
|
|
72
|
+
- Requests use `axios` under the hood. You can set `timeout` or other axios defaults via config or by accessing `client.client.defaults`.
|
|
73
|
+
- Tokens are stored in-memory; for persistence (e.g. React Native storage), handle saving and restoring external to this library.
|
|
254
74
|
|
|
255
75
|
## API Reference
|
|
256
76
|
|
|
257
|
-
###
|
|
258
|
-
|
|
259
|
-
- `OxyAuthBackend` - Authentication services
|
|
260
|
-
- `OxyUsersBackend` - User management services
|
|
261
|
-
- `OxyKarmaBackend` - Karma/reputation services
|
|
262
|
-
- `OxyWalletBackend` - Wallet and transaction services
|
|
263
|
-
|
|
264
|
-
### Frontend Hooks & Context
|
|
77
|
+
### OxyConfig
|
|
265
78
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
- `useKarma()` - Karma/reputation hooks
|
|
271
|
-
- `useWallet()` - Wallet and transaction hooks
|
|
79
|
+
| Property | Type | Required | Description |
|
|
80
|
+
| -------- | --------- | -------- | ------------------------------------- |
|
|
81
|
+
| baseURL | `string` | Yes | Root URL of the Oxy API server |
|
|
82
|
+
| timeout | `number` | No | Request timeout in milliseconds |
|
|
272
83
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
MIT
|
|
276
|
-
|
|
277
|
-
## Authentication Changes (v0.1.12)
|
|
278
|
-
|
|
279
|
-
### Important Updates
|
|
280
|
-
|
|
281
|
-
1. **Robust Authentication State Management**:
|
|
282
|
-
- Changed `isAuthenticated` from a boolean state to an async function that checks for tokens in real-time
|
|
283
|
-
- Eliminates race conditions and ensures authentication state is always current
|
|
284
|
-
- Provides more reliable session handling across the entire application
|
|
285
|
-
|
|
286
|
-
2. **Improved Session Persistence**:
|
|
287
|
-
- Authentication state now directly reflects the presence of valid tokens rather than a separate state
|
|
288
|
-
- More reliable initialization of user data when app is reloaded with existing tokens
|
|
289
|
-
|
|
290
|
-
3. **Better Dependency Management**:
|
|
291
|
-
- Fixed circular dependencies in authentication-related functions
|
|
292
|
-
- Made hook dependencies more explicit and safer to prevent potential bugs
|
|
293
|
-
|
|
294
|
-
4. **Consistent Token Storage Key Names**:
|
|
295
|
-
- Fixed critical bug where token storage keys were inconsistent between OxyContext and ApiClient
|
|
296
|
-
- Standardized all token keys to `oxy_access_token` and `oxy_refresh_token` across all components
|
|
297
|
-
|
|
298
|
-
5. **Automatic User Profile Loading**:
|
|
299
|
-
- Added automatic user profile loading on initialization when a valid token exists
|
|
300
|
-
- Ensures the user profile is available as soon as possible after authentication
|
|
84
|
+
### Class: OxyServices
|
|
301
85
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
7. **Fixed Authentication Token Storage**:
|
|
307
|
-
- Resolved issues with token storage and retrieval by making all token operations asynchronous
|
|
308
|
-
- Added direct token storage via ApiClient during login/register for consistent token management
|
|
309
|
-
- Properly implemented `/auth/me` endpoint in the API to fetch user profiles
|
|
310
|
-
|
|
311
|
-
8. **Enhanced Login/Register Response Handling**:
|
|
312
|
-
- Both `login()` and `register()` functions now support receiving the user object directly in the API response
|
|
313
|
-
- If the API returns a user object with the tokens, it will be stored automatically without making an extra `/auth/me` request
|
|
314
|
-
|
|
315
|
-
9. **Client-side Validation**:
|
|
316
|
-
- Added input validation for login and registration requests
|
|
317
|
-
- Provides detailed error feedback with field-specific error messages
|
|
318
|
-
- Prevents unnecessary API calls when required fields are missing
|
|
319
|
-
|
|
320
|
-
10. **Async Authentication Methods**:
|
|
321
|
-
- All authentication methods are now properly asynchronous and return Promises
|
|
322
|
-
- Use `await auth.isAuthenticated()` to get the current authentication status
|
|
86
|
+
Instantiate with:
|
|
87
|
+
```ts
|
|
88
|
+
const client = new OxyServices(config);
|
|
89
|
+
```
|
|
323
90
|
|
|
324
|
-
|
|
91
|
+
#### Authentication
|
|
92
|
+
|
|
93
|
+
| Method | Signature | Description |
|
|
94
|
+
| -------------------- | ----------------------------------------------------------- | ---------------------------------------------- |
|
|
95
|
+
| `signUp` | `(username: string, email: string, password: string) => Promise<{ message: string; token: string; user: User }>` | Create a new user and receive a token |
|
|
96
|
+
| `login` | `(username: string, password: string) => Promise<LoginResponse>` | Authenticate and store access & refresh tokens |
|
|
97
|
+
| `logout` | `() => Promise<void>` | Revoke current refresh token |
|
|
98
|
+
| `refreshTokens` | `() => Promise<{ accessToken: string; refreshToken: string }>` | Obtain new tokens using stored refresh token |
|
|
99
|
+
| `validate` | `() => Promise<boolean>` | Check if current access token is valid |
|
|
100
|
+
|
|
101
|
+
#### User & Profiles
|
|
102
|
+
|
|
103
|
+
| Method | Signature | Description |
|
|
104
|
+
| ---------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------- |
|
|
105
|
+
| `getProfileByUsername` | `(username: string) => Promise<any>` | Fetch public profile by username |
|
|
106
|
+
| `searchProfiles` | `(query: string, limit?: number, offset?: number) => Promise<any[]>` | Full-text search for profiles |
|
|
107
|
+
| `getUserById` | `(userId: string) => Promise<any>` | Fetch user data by user ID |
|
|
108
|
+
| `updateUser` | `(userId: string, updates: Record<string, any>) => Promise<any>` | Update fields on authenticated user profile |
|
|
109
|
+
| `followUser` / `unfollowUser`| `(userId: string) => Promise<any>` | Toggle following relationship with target user |
|
|
110
|
+
|
|
111
|
+
#### Notifications
|
|
112
|
+
|
|
113
|
+
| Method | Signature | Description |
|
|
114
|
+
| ------------------------------- | ----------------------------------------- | ----------------------------------------- |
|
|
115
|
+
| `getNotifications` | `() => Promise<Notification[]>` | Retrieve all notifications for current user|
|
|
116
|
+
| `getUnreadCount` | `() => Promise<number>` | Count unread notifications |
|
|
117
|
+
| `createNotification` | `(data: Partial<Notification>) => Promise<Notification>` | (Admin) create custom notification |
|
|
118
|
+
| `markNotificationAsRead` | `(id: string) => Promise<void>` | Mark one notification as read |
|
|
119
|
+
| `markAllNotificationsAsRead` | `() => Promise<void>` | Mark all notifications as read |
|
|
120
|
+
| `deleteNotification` | `(id: string) => Promise<void>` | Delete a notification |
|
|
121
|
+
|
|
122
|
+
#### Payments & Wallet
|
|
123
|
+
|
|
124
|
+
| Method | Signature | Description |
|
|
125
|
+
| ------------------------ | --------------------------------------------------------------- | ---------------------------------------- |
|
|
126
|
+
| `processPayment` | `(data: { userId: string; plan: string; paymentMethod: any; platform: string }) => Promise<{ success: boolean; transactionId: string }>` | Charge user for subscription or plan |
|
|
127
|
+
| `validatePaymentMethod` | `(paymentMethod: any) => Promise<{ valid: boolean }>` | Pre-validate payment method |
|
|
128
|
+
| `getPaymentMethods` | `(userId: string) => Promise<any>` | List saved payment methods |
|
|
129
|
+
| `getWallet` | `(userId: string) => Promise<any>` | Fetch or initialize wallet balance |
|
|
130
|
+
| `getTransactionHistory` | `(userId: string, limit?: number, offset?: number) => Promise<any>` | Retrieve paginated transaction history |
|
|
131
|
+
| `getTransaction` | `(transactionId: string) => Promise<any>` | Fetch details for a specific transaction |
|
|
132
|
+
| `transferFunds` | `(data: { fromUserId: string; toUserId: string; amount: number; description?: string }) => Promise<any>` | Transfer funds between users |
|
|
133
|
+
| `processPurchase` | `(data: { userId: string; amount: number; itemId: string; itemType: string; description?: string }) => Promise<any>` | Debit wallet for an in‑app purchase |
|
|
134
|
+
| `requestWithdrawal` | `(data: { userId: string; amount: number; address: string }) => Promise<any>` | Initiate a withdrawal request |
|
|
135
|
+
|
|
136
|
+
#### Analytics
|
|
137
|
+
|
|
138
|
+
| Method | Signature | Description |
|
|
139
|
+
| ------------------------ | -------------------------------------------------------------- | ----------------------------------------- |
|
|
140
|
+
| `getAnalytics` | `(userId: string, period?: string) => Promise<any>` | Time‑series metrics for a user |
|
|
141
|
+
| `updateAnalytics` | `(userId: string, type: string, data: Record<string, any>) => Promise<{ message: string }>` | Increment analytics counters |
|
|
142
|
+
| `getContentViewers` | `(userId: string, period?: string) => Promise<any[]>` | List viewers of user content |
|
|
143
|
+
| `getFollowerDetails` | `(userId: string, period?: string) => Promise<any>` | Insights on follower growth |
|
|
144
|
+
|
|
145
|
+
#### Karma System
|
|
146
|
+
|
|
147
|
+
| Method | Signature | Description |
|
|
148
|
+
| --------------------------- | ----------------------------------------------------------- | --------------------------------------------- |
|
|
149
|
+
| `getKarmaLeaderboard` | `() => Promise<any[]>` | Global leaderboard of top karma earners |
|
|
150
|
+
| `getKarmaRules` | `() => Promise<any[]>` | List configured karma rules |
|
|
151
|
+
| `getUserKarmaTotal` | `(userId: string) => Promise<{ total: number }>` | Fetch total karma for a user |
|
|
152
|
+
| `getUserKarmaHistory` | `(userId: string, limit?: number, offset?: number) => Promise<any>` | User’s karma event history |
|
|
153
|
+
| `awardKarma` / `deductKarma`| `(data: { userId: string; points: number; reason?: string }) => Promise<any>` | Modify user karma (requires auth) |
|
|
154
|
+
| `createOrUpdateKarmaRule` | `(data: any) => Promise<any>` | (Admin) define or update karma rules |
|
|
155
|
+
|
|
156
|
+
## Examples
|
|
157
|
+
|
|
158
|
+
See usage in the [Fast Start](#usage) section above. For advanced scenarios (e.g., external token storage, Axios customization), refer to source code: `src/index.ts`.
|
|
159
|
+
|
|
160
|
+
## Development
|
|
325
161
|
|
|
326
|
-
|
|
162
|
+
```bash
|
|
163
|
+
# Install dev deps
|
|
164
|
+
tonpm install
|
|
165
|
+
# Build library
|
|
166
|
+
npm run build
|
|
167
|
+
# Run tests (no tests by default)
|
|
168
|
+
npm test
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Contributing
|
|
172
|
+
|
|
173
|
+
1. Fork the repo
|
|
174
|
+
2. Create feature branch
|
|
175
|
+
3. Code and add tests
|
|
176
|
+
4. Build and commit
|
|
177
|
+
5. Open PR for review
|
|
327
178
|
|
|
328
|
-
|
|
329
|
-
// Before
|
|
330
|
-
if (auth.isAuthenticated) {
|
|
331
|
-
// User is logged in
|
|
332
|
-
}
|
|
179
|
+
## License
|
|
333
180
|
|
|
334
|
-
|
|
335
|
-
const checkAuth = async () => {
|
|
336
|
-
if (await auth.isAuthenticated()) {
|
|
337
|
-
// User is logged in
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
// After - with useEffect
|
|
342
|
-
useEffect(() => {
|
|
343
|
-
const checkAuth = async () => {
|
|
344
|
-
const isAuthenticated = await auth.isAuthenticated();
|
|
345
|
-
// Update your component state
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
checkAuth();
|
|
349
|
-
}, [auth]);
|
|
350
|
-
```
|
|
181
|
+
MIT © Oxy
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,152 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export interface OxyConfig {
|
|
2
|
+
/** Base URL of the Oxy API, e.g. https://api.mention.earth or http://localhost:3001 */
|
|
3
|
+
baseURL: string;
|
|
4
|
+
}
|
|
5
|
+
export interface User {
|
|
6
|
+
id: string;
|
|
7
|
+
username: string;
|
|
8
|
+
email: string;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
updatedAt: string;
|
|
11
|
+
}
|
|
12
|
+
export interface LoginResponse {
|
|
13
|
+
accessToken: string;
|
|
14
|
+
refreshToken: string;
|
|
15
|
+
user: User;
|
|
16
|
+
}
|
|
17
|
+
export interface Notification {
|
|
18
|
+
id: string;
|
|
19
|
+
recipientId: string;
|
|
20
|
+
actorId: string;
|
|
21
|
+
type: string;
|
|
22
|
+
entityId: string;
|
|
23
|
+
entityType: string;
|
|
24
|
+
read: boolean;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
updatedAt: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class OxyServices {
|
|
29
|
+
private client;
|
|
30
|
+
private accessToken;
|
|
31
|
+
private refreshToken;
|
|
32
|
+
constructor(config: OxyConfig);
|
|
33
|
+
/** Sign up a new user */
|
|
34
|
+
signUp(username: string, email: string, password: string): Promise<{
|
|
35
|
+
message: string;
|
|
36
|
+
token: string;
|
|
37
|
+
user: User;
|
|
38
|
+
}>;
|
|
39
|
+
/** Log in and store tokens */
|
|
40
|
+
login(username: string, password: string): Promise<LoginResponse>;
|
|
41
|
+
/** Log out user */
|
|
42
|
+
logout(): Promise<void>;
|
|
43
|
+
/** Refresh access and refresh tokens */
|
|
44
|
+
refreshTokens(): Promise<{
|
|
45
|
+
accessToken: string;
|
|
46
|
+
refreshToken: string;
|
|
47
|
+
}>;
|
|
48
|
+
/** Validate current access token */
|
|
49
|
+
validate(): Promise<boolean>;
|
|
50
|
+
/** Fetch profile by username */
|
|
51
|
+
getProfileByUsername(username: string): Promise<any>;
|
|
52
|
+
/** Search profiles */
|
|
53
|
+
searchProfiles(query: string, limit?: number, offset?: number): Promise<any[]>;
|
|
54
|
+
/** Get general user by ID */
|
|
55
|
+
getUserById(userId: string): Promise<any>;
|
|
56
|
+
/** Update user profile (requires auth) */
|
|
57
|
+
updateUser(userId: string, updates: Record<string, any>): Promise<any>;
|
|
58
|
+
/** Follow a user */
|
|
59
|
+
followUser(userId: string): Promise<any>;
|
|
60
|
+
/** Unfollow a user */
|
|
61
|
+
unfollowUser(userId: string): Promise<any>;
|
|
62
|
+
/** Fetch all notifications for the authenticated user */
|
|
63
|
+
getNotifications(): Promise<Notification[]>;
|
|
64
|
+
/** Get count of unread notifications */
|
|
65
|
+
getUnreadCount(): Promise<number>;
|
|
66
|
+
/** Create a new notification (admin use) */
|
|
67
|
+
createNotification(data: Partial<Notification>): Promise<Notification>;
|
|
68
|
+
/** Mark a single notification as read */
|
|
69
|
+
markNotificationAsRead(notificationId: string): Promise<void>;
|
|
70
|
+
/** Mark all notifications as read */
|
|
71
|
+
markAllNotificationsAsRead(): Promise<void>;
|
|
72
|
+
/** Delete a notification */
|
|
73
|
+
deleteNotification(notificationId: string): Promise<void>;
|
|
74
|
+
/** Process a payment */
|
|
75
|
+
processPayment(data: {
|
|
76
|
+
userId: string;
|
|
77
|
+
plan: string;
|
|
78
|
+
paymentMethod: any;
|
|
79
|
+
platform: string;
|
|
80
|
+
}): Promise<{
|
|
81
|
+
success: boolean;
|
|
82
|
+
transactionId: string;
|
|
83
|
+
}>;
|
|
84
|
+
/** Validate a payment method */
|
|
85
|
+
validatePaymentMethod(paymentMethod: any): Promise<{
|
|
86
|
+
valid: boolean;
|
|
87
|
+
}>;
|
|
88
|
+
/** Get saved payment methods for a user */
|
|
89
|
+
getPaymentMethods(userId: string): Promise<any>;
|
|
90
|
+
/** Get analytics data */
|
|
91
|
+
getAnalytics(userId: string, period?: string): Promise<any>;
|
|
92
|
+
/** Update analytics (internal use) */
|
|
93
|
+
updateAnalytics(userId: string, type: string, data: Record<string, any>): Promise<{
|
|
94
|
+
message: string;
|
|
95
|
+
}>;
|
|
96
|
+
/** Get content viewers analytics */
|
|
97
|
+
getContentViewers(userId: string, period?: string): Promise<any[]>;
|
|
98
|
+
/** Get follower analytics details */
|
|
99
|
+
getFollowerDetails(userId: string, period?: string): Promise<any>;
|
|
100
|
+
/** Get wallet info */
|
|
101
|
+
getWallet(userId: string): Promise<any>;
|
|
102
|
+
/** Get transaction history */
|
|
103
|
+
getTransactionHistory(userId: string, limit?: number, offset?: number): Promise<any>;
|
|
104
|
+
/** Get a specific transaction */
|
|
105
|
+
getTransaction(transactionId: string): Promise<any>;
|
|
106
|
+
/** Transfer funds */
|
|
107
|
+
transferFunds(data: {
|
|
108
|
+
fromUserId: string;
|
|
109
|
+
toUserId: string;
|
|
110
|
+
amount: number;
|
|
111
|
+
description?: string;
|
|
112
|
+
}): Promise<any>;
|
|
113
|
+
/** Process a purchase */
|
|
114
|
+
processPurchase(data: {
|
|
115
|
+
userId: string;
|
|
116
|
+
amount: number;
|
|
117
|
+
itemId: string;
|
|
118
|
+
itemType: string;
|
|
119
|
+
description?: string;
|
|
120
|
+
}): Promise<any>;
|
|
121
|
+
/** Request a withdrawal */
|
|
122
|
+
requestWithdrawal(data: {
|
|
123
|
+
userId: string;
|
|
124
|
+
amount: number;
|
|
125
|
+
address: string;
|
|
126
|
+
}): Promise<any>;
|
|
127
|
+
/** Karma: get leaderboard */
|
|
128
|
+
getKarmaLeaderboard(): Promise<any[]>;
|
|
129
|
+
/** Karma: get rules */
|
|
130
|
+
getKarmaRules(): Promise<any[]>;
|
|
131
|
+
/** Karma: get total for a user */
|
|
132
|
+
getUserKarmaTotal(userId: string): Promise<{
|
|
133
|
+
total: number;
|
|
134
|
+
}>;
|
|
135
|
+
/** Karma: get history for a user */
|
|
136
|
+
getUserKarmaHistory(userId: string, limit?: number, offset?: number): Promise<any>;
|
|
137
|
+
/** Karma: award points */
|
|
138
|
+
awardKarma(data: {
|
|
139
|
+
userId: string;
|
|
140
|
+
points: number;
|
|
141
|
+
reason?: string;
|
|
142
|
+
}): Promise<any>;
|
|
143
|
+
/** Karma: deduct points */
|
|
144
|
+
deductKarma(data: {
|
|
145
|
+
userId: string;
|
|
146
|
+
points: number;
|
|
147
|
+
reason?: string;
|
|
148
|
+
}): Promise<any>;
|
|
149
|
+
/** Karma: create or update rule (admin) */
|
|
150
|
+
createOrUpdateKarmaRule(data: any): Promise<any>;
|
|
151
|
+
}
|
|
152
|
+
export default OxyServices;
|