@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.
Files changed (144) hide show
  1. package/README.md +165 -81
  2. package/dist/backend/auth.d.ts +37 -0
  3. package/dist/backend/auth.js +81 -0
  4. package/dist/backend/index.d.ts +12 -0
  5. package/dist/backend/index.js +20 -0
  6. package/dist/backend/karma.d.ts +45 -0
  7. package/dist/backend/karma.js +83 -0
  8. package/dist/backend/users.d.ts +39 -0
  9. package/dist/backend/users.js +87 -0
  10. package/dist/backend/wallet.d.ts +29 -0
  11. package/dist/backend/wallet.js +68 -0
  12. package/dist/bundle.js +2 -0
  13. package/dist/bundle.js.LICENSE.txt +1 -0
  14. package/dist/frontend/context/OxyContext.d.ts +20 -0
  15. package/dist/frontend/context/OxyContext.js +97 -0
  16. package/dist/frontend/hooks/useAuth.d.ts +19 -0
  17. package/dist/frontend/hooks/useAuth.js +234 -0
  18. package/dist/frontend/hooks/useKarma.d.ts +27 -0
  19. package/dist/frontend/hooks/useKarma.js +187 -0
  20. package/dist/frontend/hooks/useUser.d.ts +13 -0
  21. package/dist/frontend/hooks/useUser.js +136 -0
  22. package/dist/frontend/hooks/useWallet.d.ts +14 -0
  23. package/dist/frontend/hooks/useWallet.js +174 -0
  24. package/dist/frontend/index.d.ts +6 -0
  25. package/dist/frontend/index.js +14 -0
  26. package/dist/index.d.ts +3 -7
  27. package/dist/index.js +33 -6
  28. package/dist/shared/api-client.d.ts +15 -0
  29. package/dist/shared/api-client.js +197 -0
  30. package/dist/shared/types.d.ts +135 -0
  31. package/dist/shared/types.js +2 -0
  32. package/package.json +43 -57
  33. package/dist/assets/dot-icon.d.ts +0 -3
  34. package/dist/assets/dot-icon.d.ts.map +0 -1
  35. package/dist/assets/dot-icon.js +0 -6
  36. package/dist/assets/verified-icon.d.ts +0 -3
  37. package/dist/assets/verified-icon.d.ts.map +0 -1
  38. package/dist/assets/verified-icon.js +0 -10
  39. package/dist/components/assets/oxy-logo.d.ts +0 -3
  40. package/dist/components/assets/oxy-logo.d.ts.map +0 -1
  41. package/dist/components/assets/oxy-logo.js +0 -30
  42. package/dist/components/auth/AccountSwitcherModal.d.ts +0 -7
  43. package/dist/components/auth/AccountSwitcherModal.d.ts.map +0 -1
  44. package/dist/components/auth/AccountSwitcherModal.js +0 -91
  45. package/dist/components/auth/SessionOwnerButton.d.ts +0 -3
  46. package/dist/components/auth/SessionOwnerButton.d.ts.map +0 -1
  47. package/dist/components/auth/SessionOwnerButton.js +0 -35
  48. package/dist/components/auth/SignInButton.d.ts +0 -8
  49. package/dist/components/auth/SignInButton.d.ts.map +0 -1
  50. package/dist/components/auth/SignInButton.js +0 -15
  51. package/dist/components/auth/styles/account-switcher-modal.module.css +0 -29
  52. package/dist/components/auth/styles/account-switcher-modal.module.css.map +0 -1
  53. package/dist/components/auth/styles/oavatar.module.css +0 -34
  54. package/dist/components/auth/styles/oavatar.module.css.map +0 -1
  55. package/dist/components/auth/styles/session-owner-modal.module.css +0 -35
  56. package/dist/components/auth/styles/session-owner-modal.module.css.map +0 -1
  57. package/dist/components/auth/styles/sign-in-button.module.css +0 -30
  58. package/dist/components/auth/styles/sign-in-button.module.css.map +0 -1
  59. package/dist/components/elements/button/components/button.d.ts +0 -7
  60. package/dist/components/elements/button/components/button.d.ts.map +0 -1
  61. package/dist/components/elements/button/components/button.js +0 -6
  62. package/dist/components/elements/button/components/styles/button.module.css +0 -25
  63. package/dist/components/elements/button/components/styles/button.module.css.map +0 -1
  64. package/dist/components/elements/button/index.d.ts +0 -2
  65. package/dist/components/elements/button/index.d.ts.map +0 -1
  66. package/dist/components/elements/button/index.js +0 -1
  67. package/dist/components/elements/ellipsis-wrapper/components/EllipsisWrapper.d.ts +0 -5
  68. package/dist/components/elements/ellipsis-wrapper/components/EllipsisWrapper.d.ts.map +0 -1
  69. package/dist/components/elements/ellipsis-wrapper/components/EllipsisWrapper.js +0 -4
  70. package/dist/components/elements/ellipsis-wrapper/components/ellipsis-wrapper.d.ts +0 -5
  71. package/dist/components/elements/ellipsis-wrapper/components/ellipsis-wrapper.d.ts.map +0 -1
  72. package/dist/components/elements/ellipsis-wrapper/components/ellipsis-wrapper.js +0 -4
  73. package/dist/components/elements/ellipsis-wrapper/components/styles/ellipses-wrapper.module.css +0 -11
  74. package/dist/components/elements/ellipsis-wrapper/components/styles/ellipses-wrapper.module.css.map +0 -1
  75. package/dist/components/elements/ellipsis-wrapper/index.d.ts +0 -2
  76. package/dist/components/elements/ellipsis-wrapper/index.d.ts.map +0 -1
  77. package/dist/components/elements/ellipsis-wrapper/index.js +0 -1
  78. package/dist/components/elements/modal/components/confirmation-modal.d.ts +0 -12
  79. package/dist/components/elements/modal/components/confirmation-modal.d.ts.map +0 -1
  80. package/dist/components/elements/modal/components/confirmation-modal.js +0 -21
  81. package/dist/components/elements/modal/components/modal.d.ts +0 -13
  82. package/dist/components/elements/modal/components/modal.d.ts.map +0 -1
  83. package/dist/components/elements/modal/components/modal.js +0 -111
  84. package/dist/components/elements/modal/components/styles/confirmation-modal.module.css +0 -105
  85. package/dist/components/elements/modal/components/styles/confirmation-modal.module.css.map +0 -1
  86. package/dist/components/elements/modal/components/styles/modal.module.css +0 -10
  87. package/dist/components/elements/modal/components/styles/modal.module.css.map +0 -1
  88. package/dist/components/elements/modal/hooks/use-track-position.d.ts +0 -5
  89. package/dist/components/elements/modal/hooks/use-track-position.d.ts.map +0 -1
  90. package/dist/components/elements/modal/hooks/use-track-position.js +0 -35
  91. package/dist/components/elements/modal/index.d.ts +0 -4
  92. package/dist/components/elements/modal/index.d.ts.map +0 -1
  93. package/dist/components/elements/modal/index.js +0 -3
  94. package/dist/config/index.d.ts +0 -21
  95. package/dist/config/index.d.ts.map +0 -1
  96. package/dist/config/index.js +0 -7
  97. package/dist/features/profile/components/avatar.d.ts +0 -10
  98. package/dist/features/profile/components/avatar.d.ts.map +0 -1
  99. package/dist/features/profile/components/avatar.js +0 -7
  100. package/dist/features/profile/components/styles/avatar.module.css +0 -15
  101. package/dist/features/profile/components/styles/avatar.module.css.map +0 -1
  102. package/dist/features/profile/components/styles/user-name.module.css +0 -18
  103. package/dist/features/profile/components/styles/user-name.module.css.map +0 -1
  104. package/dist/features/profile/components/styles/user-username.module.css +0 -6
  105. package/dist/features/profile/components/styles/user-username.module.css.map +0 -1
  106. package/dist/features/profile/components/user-name.d.ts +0 -7
  107. package/dist/features/profile/components/user-name.d.ts.map +0 -1
  108. package/dist/features/profile/components/user-name.js +0 -8
  109. package/dist/features/profile/components/user-username.d.ts +0 -5
  110. package/dist/features/profile/components/user-username.d.ts.map +0 -1
  111. package/dist/features/profile/components/user-username.js +0 -7
  112. package/dist/features/profile/index.d.ts +0 -4
  113. package/dist/features/profile/index.d.ts.map +0 -1
  114. package/dist/features/profile/index.js +0 -3
  115. package/dist/hooks/get-user.d.ts +0 -2
  116. package/dist/hooks/get-user.d.ts.map +0 -1
  117. package/dist/hooks/get-user.js +0 -31
  118. package/dist/hooks/getClientKey.d.ts +0 -2
  119. package/dist/hooks/getClientKey.d.ts.map +0 -1
  120. package/dist/hooks/getClientKey.js +0 -19
  121. package/dist/hooks/getUserById.d.ts +0 -11
  122. package/dist/hooks/getUserById.d.ts.map +0 -1
  123. package/dist/hooks/getUserById.js +0 -31
  124. package/dist/hooks/use-user.d.ts +0 -14
  125. package/dist/hooks/use-user.d.ts.map +0 -1
  126. package/dist/hooks/use-user.js +0 -8
  127. package/dist/hooks/useCrossDomainStorage.d.ts +0 -6
  128. package/dist/hooks/useCrossDomainStorage.d.ts.map +0 -1
  129. package/dist/hooks/useCrossDomainStorage.js +0 -24
  130. package/dist/hooks/useOxySession.d.ts +0 -30
  131. package/dist/hooks/useOxySession.d.ts.map +0 -1
  132. package/dist/hooks/useOxySession.js +0 -64
  133. package/dist/index.css +0 -5
  134. package/dist/index.css.map +0 -1
  135. package/dist/index.d.ts.map +0 -1
  136. package/dist/interfaces/index.d.ts +0 -10
  137. package/dist/interfaces/index.d.ts.map +0 -1
  138. package/dist/interfaces/index.js +0 -1
  139. package/dist/types/index.d.ts +0 -2
  140. package/dist/types/index.d.ts.map +0 -1
  141. package/dist/types/index.js +0 -1
  142. package/dist/utils/cn.d.ts +0 -3
  143. package/dist/utils/cn.d.ts.map +0 -1
  144. 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
- The Oxy Services Module is a comprehensive package designed to provide reusable services and components for building front-end applications with Oxy. It includes hooks and components for session management, user handling, and more, making it easier to integrate Oxy-based functionalities into your React applications.
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
- ## Usage Instructions
7
+ - Authentication system with JWT support
8
+ - User profile management
9
+ - Karma/reputation system
10
+ - Wallet and transaction management
11
11
 
12
- To use the OxyServicesModule, follow these steps:
12
+ ## Installation
13
13
 
14
- 1. Install the package:
15
- ```bash
16
- npm install @oxyhq/services
17
- ```
14
+ ```bash
15
+ npm install @oxyhq/services
16
+ ```
18
17
 
19
- 2. Import the necessary components and hooks in your project:
20
- ```javascript
21
- import { useOxySession, getUserById, SignInButton, AccountSwitcherModal, SessionOwnerButton } from '@oxyhq/services';
22
- ```
18
+ ## Usage
23
19
 
24
- 3. Use the components and hooks in your application. For example, to use the `SignInButton` component:
25
- ```javascript
26
- import React from 'react';
27
- import { SignInButton } from '@oxyhq/services';
20
+ ### Backend Usage
28
21
 
29
- const App = () => {
30
- return (
31
- <div>
32
- <SignInButton />
33
- </div>
34
- );
35
- };
22
+ ```typescript
23
+ import { OxyBackend } from '@oxyhq/services';
36
24
 
37
- export default App;
38
- ```
25
+ // Initialize the backend services
26
+ const oxyBackend = new OxyBackend('https://api.oxy.example.com');
39
27
 
40
- ## Examples
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
- ### Example 1: Using `useOxySession` Hook
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
- The `useOxySession` hook fetches session data and provides error handling and status management.
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
- ```javascript
47
- import React from 'react';
48
- import { useOxySession } from '@oxyhq/services';
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
- const SessionComponent = () => {
51
- const { session, status, error } = useOxySession();
65
+ ### Frontend Usage (React)
52
66
 
53
- if (status === 'loading') {
54
- return <div>Loading...</div>;
55
- }
67
+ #### Using OxyProvider (Recommended)
56
68
 
57
- if (status === 'error') {
58
- return <div>Error: {error}</div>;
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
- <h1>Welcome, {session.user.name}!</h1>
64
- <p>Email: {session.user.email}</p>
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 SessionComponent;
115
+ export default App;
70
116
  ```
71
117
 
72
- ### Example 2: Using `getUserById` Function
118
+ #### Direct Usage (Without Provider)
73
119
 
74
- The `getUserById` function fetches user data by ID and handles possible errors.
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
- ```javascript
77
- import React, { useEffect, useState } from 'react';
78
- import { getUserById } from '@oxyhq/services';
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
- const UserComponent = ({ userId }) => {
81
- const [user, setUser] = useState(null);
82
- const [error, setError] = useState(null);
175
+ export default App;
176
+ ```
83
177
 
84
- useEffect(() => {
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
- fetchUser();
95
- }, [userId]);
180
+ ### Backend Services
96
181
 
97
- if (error) {
98
- return <div>Error: {error}</div>;
99
- }
182
+ - `OxyAuthBackend` - Authentication services
183
+ - `OxyUsersBackend` - User management services
184
+ - `OxyKarmaBackend` - Karma/reputation services
185
+ - `OxyWalletBackend` - Wallet and transaction services
100
186
 
101
- if (!user) {
102
- return <div>Loading...</div>;
103
- }
187
+ ### Frontend Hooks & Context
104
188
 
105
- return (
106
- <div>
107
- <h1>{user.name}</h1>
108
- <p>Email: {user.email}</p>
109
- </div>
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
- export default UserComponent;
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;