@oxyhq/services 0.0.85 → 0.1.1
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 +165 -81
- package/dist/backend/auth.d.ts +37 -0
- package/dist/backend/auth.js +81 -0
- package/dist/backend/index.d.ts +12 -0
- package/dist/backend/index.js +20 -0
- package/dist/backend/karma.d.ts +45 -0
- package/dist/backend/karma.js +83 -0
- package/dist/backend/users.d.ts +39 -0
- package/dist/backend/users.js +87 -0
- package/dist/backend/wallet.d.ts +29 -0
- package/dist/backend/wallet.js +68 -0
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +1 -0
- package/dist/frontend/context/OxyContext.d.ts +20 -0
- package/dist/frontend/context/OxyContext.js +97 -0
- package/dist/frontend/hooks/useAuth.d.ts +19 -0
- package/dist/frontend/hooks/useAuth.js +234 -0
- package/dist/frontend/hooks/useKarma.d.ts +27 -0
- package/dist/frontend/hooks/useKarma.js +187 -0
- package/dist/frontend/hooks/useUser.d.ts +13 -0
- package/dist/frontend/hooks/useUser.js +136 -0
- package/dist/frontend/hooks/useWallet.d.ts +14 -0
- package/dist/frontend/hooks/useWallet.js +174 -0
- package/dist/frontend/index.d.ts +6 -0
- package/dist/frontend/index.js +14 -0
- package/dist/index.d.ts +3 -7
- package/dist/index.js +33 -6
- package/dist/shared/api-client.d.ts +15 -0
- package/dist/shared/api-client.js +197 -0
- package/dist/shared/types.d.ts +135 -0
- package/dist/shared/types.js +2 -0
- package/package.json +43 -57
- 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 +0 -2
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +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,198 @@
|
|
|
1
|
-
# Oxy Services Module
|
|
1
|
+
# Oxy Services Module
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A comprehensive authentication, user management, and karma system module for Oxy applications.
|
|
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 system with JWT support
|
|
8
|
+
- User profile management
|
|
9
|
+
- Karma/reputation system
|
|
10
|
+
- Wallet and transaction management
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
## Installation
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```
|
|
14
|
+
```bash
|
|
15
|
+
npm install @oxyhq/services
|
|
16
|
+
```
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
import { useOxySession, getUserById, SignInButton, AccountSwitcherModal, SessionOwnerButton } from '@oxyhq/services';
|
|
22
|
-
```
|
|
18
|
+
## Usage
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
```javascript
|
|
26
|
-
import React from 'react';
|
|
27
|
-
import { SignInButton } from '@oxyhq/services';
|
|
20
|
+
### Backend Usage
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<div>
|
|
32
|
-
<SignInButton />
|
|
33
|
-
</div>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
22
|
+
```typescript
|
|
23
|
+
import { OxyBackend } from '@oxyhq/services';
|
|
36
24
|
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
// Initialize the backend services
|
|
26
|
+
const oxyBackend = new OxyBackend('https://api.oxy.example.com');
|
|
39
27
|
|
|
40
|
-
|
|
28
|
+
// Use authentication service
|
|
29
|
+
const login = async (username, password) => {
|
|
30
|
+
const response = await oxyBackend.auth.login({ username, password });
|
|
31
|
+
if (response.success) {
|
|
32
|
+
// Handle successful login
|
|
33
|
+
console.log('Tokens:', response.data);
|
|
34
|
+
} else {
|
|
35
|
+
// Handle login failure
|
|
36
|
+
console.error('Login failed:', response.error);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
41
39
|
|
|
42
|
-
|
|
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
|
+
};
|
|
43
47
|
|
|
44
|
-
|
|
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
|
+
};
|
|
45
55
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
};
|
|
63
|
+
```
|
|
49
64
|
|
|
50
|
-
|
|
51
|
-
const { session, status, error } = useOxySession();
|
|
65
|
+
### Frontend Usage (React)
|
|
52
66
|
|
|
53
|
-
|
|
54
|
-
return <div>Loading...</div>;
|
|
55
|
-
}
|
|
67
|
+
#### Using OxyProvider (Recommended)
|
|
56
68
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
```typescript
|
|
70
|
+
import React 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
|
+
}
|
|
81
|
+
|
|
82
|
+
// Then in your components, you don't need to specify apiUrl
|
|
83
|
+
function AuthenticatedApp() {
|
|
84
|
+
// Use hooks without needing to specify apiUrl each time
|
|
85
|
+
const auth = useAuth();
|
|
86
|
+
const user = useUser();
|
|
87
|
+
const karma = useKarma();
|
|
88
|
+
const wallet = useWallet();
|
|
89
|
+
|
|
90
|
+
const handleLogin = async () => {
|
|
91
|
+
const result = await auth.login({
|
|
92
|
+
username: 'user123',
|
|
93
|
+
password: 'secure-password'
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (result.success) {
|
|
97
|
+
console.log('Logged in successfully');
|
|
98
|
+
}
|
|
99
|
+
};
|
|
60
100
|
|
|
61
101
|
return (
|
|
62
102
|
<div>
|
|
63
|
-
|
|
64
|
-
|
|
103
|
+
{auth.isAuthenticated ? (
|
|
104
|
+
<div>
|
|
105
|
+
<h2>Welcome, {auth.user?.username}</h2>
|
|
106
|
+
<button onClick={auth.logout}>Logout</button>
|
|
107
|
+
</div>
|
|
108
|
+
) : (
|
|
109
|
+
<button onClick={handleLogin}>Login</button>
|
|
110
|
+
)}
|
|
65
111
|
</div>
|
|
66
112
|
);
|
|
67
|
-
}
|
|
113
|
+
}
|
|
68
114
|
|
|
69
|
-
export default
|
|
115
|
+
export default App;
|
|
70
116
|
```
|
|
71
117
|
|
|
72
|
-
|
|
118
|
+
#### Direct Usage (Without Provider)
|
|
73
119
|
|
|
74
|
-
|
|
120
|
+
```typescript
|
|
121
|
+
import React from 'react';
|
|
122
|
+
import { useAuth, useUser, useKarma, useWallet } from '@oxyhq/services';
|
|
123
|
+
|
|
124
|
+
function App() {
|
|
125
|
+
// Use authentication hook
|
|
126
|
+
const auth = useAuth({
|
|
127
|
+
apiUrl: 'https://api.oxy.example.com',
|
|
128
|
+
storage: 'local',
|
|
129
|
+
tokenRefreshInterval: 1000 * 60 * 15 // 15 minutes
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Use user management hook
|
|
133
|
+
const user = useUser({
|
|
134
|
+
apiUrl: 'https://api.oxy.example.com',
|
|
135
|
+
getToken: auth.getToken
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Use karma hook
|
|
139
|
+
const karma = useKarma({
|
|
140
|
+
apiUrl: 'https://api.oxy.example.com',
|
|
141
|
+
getToken: auth.getToken
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Use wallet hook
|
|
145
|
+
const wallet = useWallet({
|
|
146
|
+
apiUrl: 'https://api.oxy.example.com',
|
|
147
|
+
getToken: auth.getToken
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const handleLogin = async () => {
|
|
151
|
+
const result = await auth.login({
|
|
152
|
+
username: 'user123',
|
|
153
|
+
password: 'secure-password'
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
if (result.success) {
|
|
157
|
+
console.log('Logged in successfully');
|
|
158
|
+
}
|
|
159
|
+
};
|
|
75
160
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
161
|
+
return (
|
|
162
|
+
<div>
|
|
163
|
+
{auth.isAuthenticated ? (
|
|
164
|
+
<div>
|
|
165
|
+
<h2>Welcome, {auth.user?.username}</h2>
|
|
166
|
+
<button onClick={auth.logout}>Logout</button>
|
|
167
|
+
</div>
|
|
168
|
+
) : (
|
|
169
|
+
<button onClick={handleLogin}>Login</button>
|
|
170
|
+
)}
|
|
171
|
+
</div>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
79
174
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const [error, setError] = useState(null);
|
|
175
|
+
export default App;
|
|
176
|
+
```
|
|
83
177
|
|
|
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
|
-
};
|
|
178
|
+
## API Reference
|
|
93
179
|
|
|
94
|
-
|
|
95
|
-
}, [userId]);
|
|
180
|
+
### Backend Services
|
|
96
181
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
182
|
+
- `OxyAuthBackend` - Authentication services
|
|
183
|
+
- `OxyUsersBackend` - User management services
|
|
184
|
+
- `OxyKarmaBackend` - Karma/reputation services
|
|
185
|
+
- `OxyWalletBackend` - Wallet and transaction services
|
|
100
186
|
|
|
101
|
-
|
|
102
|
-
return <div>Loading...</div>;
|
|
103
|
-
}
|
|
187
|
+
### Frontend Hooks & Context
|
|
104
188
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
189
|
+
- `OxyProvider` - Context provider for API URL and authentication
|
|
190
|
+
- `useOxyContext` - Hook to access the Oxy context
|
|
191
|
+
- `useAuth()` - Authentication hooks
|
|
192
|
+
- `useUser()` - User management hooks
|
|
193
|
+
- `useKarma()` - Karma/reputation hooks
|
|
194
|
+
- `useWallet()` - Wallet and transaction hooks
|
|
112
195
|
|
|
113
|
-
|
|
114
|
-
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
MIT
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ApiResponse, AuthTokens, UserCredentials, UserProfile, UserRegistration } from '../shared/types';
|
|
2
|
+
export declare class OxyAuthBackend {
|
|
3
|
+
private apiClient;
|
|
4
|
+
constructor(apiUrl: string);
|
|
5
|
+
/**
|
|
6
|
+
* Authenticate a user with username/email and password
|
|
7
|
+
*/
|
|
8
|
+
login(credentials: UserCredentials): Promise<ApiResponse<AuthTokens>>;
|
|
9
|
+
/**
|
|
10
|
+
* Register a new user
|
|
11
|
+
*/
|
|
12
|
+
register(userData: UserRegistration): Promise<ApiResponse<AuthTokens>>;
|
|
13
|
+
/**
|
|
14
|
+
* Refresh the authentication token
|
|
15
|
+
*/
|
|
16
|
+
refreshToken(refreshToken: string): Promise<ApiResponse<AuthTokens>>;
|
|
17
|
+
/**
|
|
18
|
+
* Logout the current user
|
|
19
|
+
*/
|
|
20
|
+
logout(refreshToken: string): Promise<ApiResponse<void>>;
|
|
21
|
+
/**
|
|
22
|
+
* Validate if a token is valid
|
|
23
|
+
*/
|
|
24
|
+
validateToken(token: string): Promise<ApiResponse<{
|
|
25
|
+
valid: boolean;
|
|
26
|
+
}>>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the current user's profile
|
|
29
|
+
*/
|
|
30
|
+
getCurrentUser(token: string): Promise<ApiResponse<UserProfile>>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a username is available
|
|
33
|
+
*/
|
|
34
|
+
checkUsernameAvailability(username: string): Promise<ApiResponse<{
|
|
35
|
+
available: boolean;
|
|
36
|
+
}>>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OxyAuthBackend = void 0;
|
|
4
|
+
const api_client_1 = require("../shared/api-client");
|
|
5
|
+
class OxyAuthBackend {
|
|
6
|
+
constructor(apiUrl) {
|
|
7
|
+
this.apiClient = new api_client_1.ApiClient({ apiUrl });
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Authenticate a user with username/email and password
|
|
11
|
+
*/
|
|
12
|
+
async login(credentials) {
|
|
13
|
+
return this.apiClient.request({
|
|
14
|
+
method: 'POST',
|
|
15
|
+
url: '/auth/login',
|
|
16
|
+
data: credentials
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Register a new user
|
|
21
|
+
*/
|
|
22
|
+
async register(userData) {
|
|
23
|
+
return this.apiClient.request({
|
|
24
|
+
method: 'POST',
|
|
25
|
+
url: '/auth/signup',
|
|
26
|
+
data: userData
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Refresh the authentication token
|
|
31
|
+
*/
|
|
32
|
+
async refreshToken(refreshToken) {
|
|
33
|
+
return this.apiClient.request({
|
|
34
|
+
method: 'POST',
|
|
35
|
+
url: '/auth/refresh-token',
|
|
36
|
+
data: { refreshToken }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Logout the current user
|
|
41
|
+
*/
|
|
42
|
+
async logout(refreshToken) {
|
|
43
|
+
return this.apiClient.request({
|
|
44
|
+
method: 'POST',
|
|
45
|
+
url: '/auth/logout',
|
|
46
|
+
data: { refreshToken }
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Validate if a token is valid
|
|
51
|
+
*/
|
|
52
|
+
async validateToken(token) {
|
|
53
|
+
return this.apiClient.request({
|
|
54
|
+
method: 'POST',
|
|
55
|
+
url: '/auth/validate-token',
|
|
56
|
+
data: { token }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the current user's profile
|
|
61
|
+
*/
|
|
62
|
+
async getCurrentUser(token) {
|
|
63
|
+
return this.apiClient.request({
|
|
64
|
+
method: 'GET',
|
|
65
|
+
url: '/auth/me',
|
|
66
|
+
headers: {
|
|
67
|
+
Authorization: `Bearer ${token}`
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check if a username is available
|
|
73
|
+
*/
|
|
74
|
+
async checkUsernameAvailability(username) {
|
|
75
|
+
return this.apiClient.request({
|
|
76
|
+
method: 'GET',
|
|
77
|
+
url: `/auth/check-username/${username}`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.OxyAuthBackend = OxyAuthBackend;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OxyAuthBackend } from './auth';
|
|
2
|
+
import { OxyUsersBackend } from './users';
|
|
3
|
+
import { OxyKarmaBackend } from './karma';
|
|
4
|
+
import { OxyWalletBackend } from './wallet';
|
|
5
|
+
export { OxyAuthBackend, OxyUsersBackend, OxyKarmaBackend, OxyWalletBackend };
|
|
6
|
+
export declare class OxyBackend {
|
|
7
|
+
auth: OxyAuthBackend;
|
|
8
|
+
users: OxyUsersBackend;
|
|
9
|
+
karma: OxyKarmaBackend;
|
|
10
|
+
wallet: OxyWalletBackend;
|
|
11
|
+
constructor(apiUrl: string);
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OxyBackend = exports.OxyWalletBackend = exports.OxyKarmaBackend = exports.OxyUsersBackend = exports.OxyAuthBackend = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
Object.defineProperty(exports, "OxyAuthBackend", { enumerable: true, get: function () { return auth_1.OxyAuthBackend; } });
|
|
6
|
+
const users_1 = require("./users");
|
|
7
|
+
Object.defineProperty(exports, "OxyUsersBackend", { enumerable: true, get: function () { return users_1.OxyUsersBackend; } });
|
|
8
|
+
const karma_1 = require("./karma");
|
|
9
|
+
Object.defineProperty(exports, "OxyKarmaBackend", { enumerable: true, get: function () { return karma_1.OxyKarmaBackend; } });
|
|
10
|
+
const wallet_1 = require("./wallet");
|
|
11
|
+
Object.defineProperty(exports, "OxyWalletBackend", { enumerable: true, get: function () { return wallet_1.OxyWalletBackend; } });
|
|
12
|
+
class OxyBackend {
|
|
13
|
+
constructor(apiUrl) {
|
|
14
|
+
this.auth = new auth_1.OxyAuthBackend(apiUrl);
|
|
15
|
+
this.users = new users_1.OxyUsersBackend(apiUrl);
|
|
16
|
+
this.karma = new karma_1.OxyKarmaBackend(apiUrl);
|
|
17
|
+
this.wallet = new wallet_1.OxyWalletBackend(apiUrl);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.OxyBackend = OxyBackend;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ApiResponse, KarmaAction, KarmaHistory, KarmaRule } from '../shared/types';
|
|
2
|
+
export declare class OxyKarmaBackend {
|
|
3
|
+
private apiClient;
|
|
4
|
+
constructor(apiUrl: string);
|
|
5
|
+
/**
|
|
6
|
+
* Get a user's karma total
|
|
7
|
+
*/
|
|
8
|
+
getUserKarma(userId: string): Promise<ApiResponse<{
|
|
9
|
+
karma: number;
|
|
10
|
+
}>>;
|
|
11
|
+
/**
|
|
12
|
+
* Get a user's karma history (actions that affected karma)
|
|
13
|
+
*/
|
|
14
|
+
getUserKarmaHistory(userId: string, limit?: number, offset?: number): Promise<ApiResponse<KarmaHistory>>;
|
|
15
|
+
/**
|
|
16
|
+
* Award karma points to a user for a specific action
|
|
17
|
+
*/
|
|
18
|
+
awardKarma(karmaAction: KarmaAction): Promise<ApiResponse<{
|
|
19
|
+
success: boolean;
|
|
20
|
+
newTotal: number;
|
|
21
|
+
}>>;
|
|
22
|
+
/**
|
|
23
|
+
* Deduct karma points from a user for a specific action
|
|
24
|
+
*/
|
|
25
|
+
deductKarma(karmaAction: KarmaAction): Promise<ApiResponse<{
|
|
26
|
+
success: boolean;
|
|
27
|
+
newTotal: number;
|
|
28
|
+
}>>;
|
|
29
|
+
/**
|
|
30
|
+
* Get the karma leaderboard (top users by karma)
|
|
31
|
+
*/
|
|
32
|
+
getKarmaLeaderboard(limit?: number, offset?: number): Promise<ApiResponse<Array<{
|
|
33
|
+
userId: string;
|
|
34
|
+
username: string;
|
|
35
|
+
karma: number;
|
|
36
|
+
}>>>;
|
|
37
|
+
/**
|
|
38
|
+
* Get karma rules configuration
|
|
39
|
+
*/
|
|
40
|
+
getKarmaRules(): Promise<ApiResponse<KarmaRule[]>>;
|
|
41
|
+
/**
|
|
42
|
+
* Admin only: Create or update a karma rule
|
|
43
|
+
*/
|
|
44
|
+
createOrUpdateKarmaRule(rule: KarmaRule): Promise<ApiResponse<KarmaRule>>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OxyKarmaBackend = void 0;
|
|
4
|
+
const api_client_1 = require("../shared/api-client");
|
|
5
|
+
class OxyKarmaBackend {
|
|
6
|
+
constructor(apiUrl) {
|
|
7
|
+
this.apiClient = new api_client_1.ApiClient({ apiUrl });
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get a user's karma total
|
|
11
|
+
*/
|
|
12
|
+
async getUserKarma(userId) {
|
|
13
|
+
return this.apiClient.request({
|
|
14
|
+
method: 'GET',
|
|
15
|
+
url: `/karma/${userId}/total`
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get a user's karma history (actions that affected karma)
|
|
20
|
+
*/
|
|
21
|
+
async getUserKarmaHistory(userId, limit, offset) {
|
|
22
|
+
const params = {};
|
|
23
|
+
if (limit !== undefined)
|
|
24
|
+
params.limit = limit.toString();
|
|
25
|
+
if (offset !== undefined)
|
|
26
|
+
params.offset = offset.toString();
|
|
27
|
+
return this.apiClient.request({
|
|
28
|
+
method: 'GET',
|
|
29
|
+
url: `/karma/${userId}/history`,
|
|
30
|
+
params
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Award karma points to a user for a specific action
|
|
35
|
+
*/
|
|
36
|
+
async awardKarma(karmaAction) {
|
|
37
|
+
return this.apiClient.request({
|
|
38
|
+
method: 'POST',
|
|
39
|
+
url: '/karma/award',
|
|
40
|
+
data: karmaAction
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Deduct karma points from a user for a specific action
|
|
45
|
+
*/
|
|
46
|
+
async deductKarma(karmaAction) {
|
|
47
|
+
return this.apiClient.request({
|
|
48
|
+
method: 'POST',
|
|
49
|
+
url: '/karma/deduct',
|
|
50
|
+
data: karmaAction
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the karma leaderboard (top users by karma)
|
|
55
|
+
*/
|
|
56
|
+
async getKarmaLeaderboard(limit = 10, offset = 0) {
|
|
57
|
+
return this.apiClient.request({
|
|
58
|
+
method: 'GET',
|
|
59
|
+
url: '/karma/leaderboard',
|
|
60
|
+
params: { limit, offset }
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get karma rules configuration
|
|
65
|
+
*/
|
|
66
|
+
async getKarmaRules() {
|
|
67
|
+
return this.apiClient.request({
|
|
68
|
+
method: 'GET',
|
|
69
|
+
url: '/karma/rules'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Admin only: Create or update a karma rule
|
|
74
|
+
*/
|
|
75
|
+
async createOrUpdateKarmaRule(rule) {
|
|
76
|
+
return this.apiClient.request({
|
|
77
|
+
method: 'POST',
|
|
78
|
+
url: '/karma/rules',
|
|
79
|
+
data: rule
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.OxyKarmaBackend = OxyKarmaBackend;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ApiResponse, UserProfile, PrivacySettings } from '../shared/types';
|
|
2
|
+
export declare class OxyUsersBackend {
|
|
3
|
+
private apiClient;
|
|
4
|
+
constructor(apiUrl: string);
|
|
5
|
+
/**
|
|
6
|
+
* Get a user by ID
|
|
7
|
+
*/
|
|
8
|
+
getUserById(userId: string): Promise<ApiResponse<UserProfile>>;
|
|
9
|
+
/**
|
|
10
|
+
* Get a user by username
|
|
11
|
+
*/
|
|
12
|
+
getUserByUsername(username: string): Promise<ApiResponse<UserProfile>>;
|
|
13
|
+
/**
|
|
14
|
+
* Update a user's profile
|
|
15
|
+
*/
|
|
16
|
+
updateUserProfile(userId: string, profileData: Partial<UserProfile>): Promise<ApiResponse<UserProfile>>;
|
|
17
|
+
/**
|
|
18
|
+
* Update a user's privacy settings
|
|
19
|
+
*/
|
|
20
|
+
updatePrivacySettings(userId: string, settings: Partial<PrivacySettings>): Promise<ApiResponse<PrivacySettings>>;
|
|
21
|
+
/**
|
|
22
|
+
* Get a user's privacy settings
|
|
23
|
+
*/
|
|
24
|
+
getPrivacySettings(userId: string): Promise<ApiResponse<PrivacySettings>>;
|
|
25
|
+
/**
|
|
26
|
+
* Convert username to user ID
|
|
27
|
+
*/
|
|
28
|
+
getUserIdFromUsername(username: string): Promise<ApiResponse<{
|
|
29
|
+
userId: string;
|
|
30
|
+
}>>;
|
|
31
|
+
/**
|
|
32
|
+
* Follow a user
|
|
33
|
+
*/
|
|
34
|
+
followUser(userId: string, targetUserId: string): Promise<ApiResponse<void>>;
|
|
35
|
+
/**
|
|
36
|
+
* Unfollow a user
|
|
37
|
+
*/
|
|
38
|
+
unfollowUser(userId: string, targetUserId: string): Promise<ApiResponse<void>>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OxyUsersBackend = void 0;
|
|
4
|
+
const api_client_1 = require("../shared/api-client");
|
|
5
|
+
class OxyUsersBackend {
|
|
6
|
+
constructor(apiUrl) {
|
|
7
|
+
this.apiClient = new api_client_1.ApiClient({ apiUrl });
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get a user by ID
|
|
11
|
+
*/
|
|
12
|
+
async getUserById(userId) {
|
|
13
|
+
return this.apiClient.request({
|
|
14
|
+
method: 'GET',
|
|
15
|
+
url: `/users/${userId}`
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get a user by username
|
|
20
|
+
*/
|
|
21
|
+
async getUserByUsername(username) {
|
|
22
|
+
return this.apiClient.request({
|
|
23
|
+
method: 'GET',
|
|
24
|
+
url: `/users/username/${username}`
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Update a user's profile
|
|
29
|
+
*/
|
|
30
|
+
async updateUserProfile(userId, profileData) {
|
|
31
|
+
return this.apiClient.request({
|
|
32
|
+
method: 'PUT',
|
|
33
|
+
url: `/users/${userId}`,
|
|
34
|
+
data: profileData
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Update a user's privacy settings
|
|
39
|
+
*/
|
|
40
|
+
async updatePrivacySettings(userId, settings) {
|
|
41
|
+
return this.apiClient.request({
|
|
42
|
+
method: 'PUT',
|
|
43
|
+
url: `/users/${userId}/privacy`,
|
|
44
|
+
data: settings
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get a user's privacy settings
|
|
49
|
+
*/
|
|
50
|
+
async getPrivacySettings(userId) {
|
|
51
|
+
return this.apiClient.request({
|
|
52
|
+
method: 'GET',
|
|
53
|
+
url: `/users/${userId}/privacy`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Convert username to user ID
|
|
58
|
+
*/
|
|
59
|
+
async getUserIdFromUsername(username) {
|
|
60
|
+
// This assumes the API has this endpoint, if not, we would use the getUserByUsername and extract the ID
|
|
61
|
+
return this.apiClient.request({
|
|
62
|
+
method: 'GET',
|
|
63
|
+
url: `/users/resolve/${username}`
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Follow a user
|
|
68
|
+
*/
|
|
69
|
+
async followUser(userId, targetUserId) {
|
|
70
|
+
return this.apiClient.request({
|
|
71
|
+
method: 'POST',
|
|
72
|
+
url: `/users/${userId}/follow`,
|
|
73
|
+
data: { targetUserId }
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Unfollow a user
|
|
78
|
+
*/
|
|
79
|
+
async unfollowUser(userId, targetUserId) {
|
|
80
|
+
return this.apiClient.request({
|
|
81
|
+
method: 'POST',
|
|
82
|
+
url: `/users/${userId}/unfollow`,
|
|
83
|
+
data: { targetUserId }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.OxyUsersBackend = OxyUsersBackend;
|