@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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ApiResponse, WalletInfo, TransactionInfo, TransferRequest, PurchaseRequest, WithdrawalRequest } from '../shared/types';
|
|
2
|
+
export declare class OxyWalletBackend {
|
|
3
|
+
private apiClient;
|
|
4
|
+
constructor(apiUrl: string);
|
|
5
|
+
/**
|
|
6
|
+
* Get wallet information for a user
|
|
7
|
+
*/
|
|
8
|
+
getWallet(userId: string): Promise<ApiResponse<WalletInfo>>;
|
|
9
|
+
/**
|
|
10
|
+
* Get transaction history for a user
|
|
11
|
+
*/
|
|
12
|
+
getTransactionHistory(userId: string, limit?: number, offset?: number): Promise<ApiResponse<TransactionInfo[]>>;
|
|
13
|
+
/**
|
|
14
|
+
* Transfer funds to another user
|
|
15
|
+
*/
|
|
16
|
+
transferFunds(transferRequest: TransferRequest): Promise<ApiResponse<TransactionInfo>>;
|
|
17
|
+
/**
|
|
18
|
+
* Process a purchase
|
|
19
|
+
*/
|
|
20
|
+
processPurchase(purchaseRequest: PurchaseRequest): Promise<ApiResponse<TransactionInfo>>;
|
|
21
|
+
/**
|
|
22
|
+
* Request a withdrawal
|
|
23
|
+
*/
|
|
24
|
+
requestWithdrawal(withdrawalRequest: WithdrawalRequest): Promise<ApiResponse<TransactionInfo>>;
|
|
25
|
+
/**
|
|
26
|
+
* Get a specific transaction
|
|
27
|
+
*/
|
|
28
|
+
getTransaction(transactionId: string): Promise<ApiResponse<TransactionInfo>>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OxyWalletBackend = void 0;
|
|
4
|
+
const api_client_1 = require("../shared/api-client");
|
|
5
|
+
class OxyWalletBackend {
|
|
6
|
+
constructor(apiUrl) {
|
|
7
|
+
this.apiClient = new api_client_1.ApiClient({ apiUrl });
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get wallet information for a user
|
|
11
|
+
*/
|
|
12
|
+
async getWallet(userId) {
|
|
13
|
+
return this.apiClient.request({
|
|
14
|
+
method: 'GET',
|
|
15
|
+
url: `/wallet/${userId}`
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get transaction history for a user
|
|
20
|
+
*/
|
|
21
|
+
async getTransactionHistory(userId, limit = 10, offset = 0) {
|
|
22
|
+
return this.apiClient.request({
|
|
23
|
+
method: 'GET',
|
|
24
|
+
url: `/wallet/transactions/${userId}`,
|
|
25
|
+
params: { limit, offset }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Transfer funds to another user
|
|
30
|
+
*/
|
|
31
|
+
async transferFunds(transferRequest) {
|
|
32
|
+
return this.apiClient.request({
|
|
33
|
+
method: 'POST',
|
|
34
|
+
url: '/wallet/transfer',
|
|
35
|
+
data: transferRequest
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Process a purchase
|
|
40
|
+
*/
|
|
41
|
+
async processPurchase(purchaseRequest) {
|
|
42
|
+
return this.apiClient.request({
|
|
43
|
+
method: 'POST',
|
|
44
|
+
url: '/wallet/purchase',
|
|
45
|
+
data: purchaseRequest
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Request a withdrawal
|
|
50
|
+
*/
|
|
51
|
+
async requestWithdrawal(withdrawalRequest) {
|
|
52
|
+
return this.apiClient.request({
|
|
53
|
+
method: 'POST',
|
|
54
|
+
url: '/wallet/withdraw',
|
|
55
|
+
data: withdrawalRequest
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get a specific transaction
|
|
60
|
+
*/
|
|
61
|
+
async getTransaction(transactionId) {
|
|
62
|
+
return this.apiClient.request({
|
|
63
|
+
method: 'GET',
|
|
64
|
+
url: `/wallet/transaction/${transactionId}`
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.OxyWalletBackend = OxyWalletBackend;
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see bundle.js.LICENSE.txt */
|
|
2
|
+
(()=>{"use strict";var e={109:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OxyAuthBackend=void 0;const n=r(442);t.OxyAuthBackend=class{constructor(e){this.apiClient=new n.ApiClient({apiUrl:e})}async login(e){return this.apiClient.request({method:"POST",url:"/auth/login",data:e})}async register(e){return this.apiClient.request({method:"POST",url:"/auth/signup",data:e})}async refreshToken(e){return this.apiClient.request({method:"POST",url:"/auth/refresh-token",data:{refreshToken:e}})}async logout(e){return this.apiClient.request({method:"POST",url:"/auth/logout",data:{refreshToken:e}})}async validateToken(e){return this.apiClient.request({method:"POST",url:"/auth/validate-token",data:{token:e}})}async getCurrentUser(e){return this.apiClient.request({method:"GET",url:"/auth/me",headers:{Authorization:`Bearer ${e}`}})}async checkUsernameAvailability(e){return this.apiClient.request({method:"GET",url:`/auth/check-username/${e}`})}}},156:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,s)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),s=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.useOxyContext=t.OxyProvider=t.useWallet=t.useKarma=t.useUser=t.useAuth=t.OxyWalletBackend=t.OxyKarmaBackend=t.OxyUsersBackend=t.OxyAuthBackend=void 0,s(r(817),t);var o=r(467);Object.defineProperty(t,"OxyAuthBackend",{enumerable:!0,get:function(){return o.OxyAuthBackend}}),Object.defineProperty(t,"OxyUsersBackend",{enumerable:!0,get:function(){return o.OxyUsersBackend}}),Object.defineProperty(t,"OxyKarmaBackend",{enumerable:!0,get:function(){return o.OxyKarmaBackend}}),Object.defineProperty(t,"OxyWalletBackend",{enumerable:!0,get:function(){return o.OxyWalletBackend}});var a=r(881);Object.defineProperty(t,"useAuth",{enumerable:!0,get:function(){return a.useAuth}}),Object.defineProperty(t,"useUser",{enumerable:!0,get:function(){return a.useUser}}),Object.defineProperty(t,"useKarma",{enumerable:!0,get:function(){return a.useKarma}}),Object.defineProperty(t,"useWallet",{enumerable:!0,get:function(){return a.useWallet}}),Object.defineProperty(t,"OxyProvider",{enumerable:!0,get:function(){return a.OxyProvider}}),Object.defineProperty(t,"useOxyContext",{enumerable:!0,get:function(){return a.useOxyContext}})},182:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useUser=void 0;const n=r(953),s=r(442),o=r(772);t.useUser=e=>{const t=(0,o.useOxyContext)(),r=(null==e?void 0:e.apiUrl)||t.apiUrl,a=(null==e?void 0:e.getToken)||t.getToken;if(!r)throw new Error("API URL is required. Provide it either through options or OxyProvider.");const[i]=(0,n.useState)((()=>new s.ApiClient({apiUrl:r})));return{getUserById:(0,n.useCallback)((async e=>{try{return await i.request({method:"GET",url:`/users/${e}`,headers:a?{Authorization:`Bearer ${a()||""}`}:void 0})}catch(e){return{success:!1,error:e.message||"Failed to get user profile"}}}),[i,a]),updateUserProfile:(0,n.useCallback)((async(e,t)=>{try{return a?await i.request({method:"PATCH",url:`/users/${e}`,data:t,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to update user profile"}}}),[i,a]),getPrivacySettings:(0,n.useCallback)((async e=>{try{return a?await i.request({method:"GET",url:`/privacy/${e}`,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to get privacy settings"}}}),[i,a]),updatePrivacySettings:(0,n.useCallback)((async(e,t)=>{try{return a?await i.request({method:"PATCH",url:`/privacy/${e}`,data:t,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to update privacy settings"}}}),[i,a]),searchUsers:(0,n.useCallback)((async(e,t=10)=>{try{return await i.request({method:"GET",url:"/users/search",params:{query:e,limit:t},headers:a?{Authorization:`Bearer ${a()||""}`}:void 0})}catch(e){return{success:!1,error:e.message||"Failed to search users"}}}),[i,a])}}},223:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OxyUsersBackend=void 0;const n=r(442);t.OxyUsersBackend=class{constructor(e){this.apiClient=new n.ApiClient({apiUrl:e})}async getUserById(e){return this.apiClient.request({method:"GET",url:`/users/${e}`})}async getUserByUsername(e){return this.apiClient.request({method:"GET",url:`/users/username/${e}`})}async updateUserProfile(e,t){return this.apiClient.request({method:"PUT",url:`/users/${e}`,data:t})}async updatePrivacySettings(e,t){return this.apiClient.request({method:"PUT",url:`/users/${e}/privacy`,data:t})}async getPrivacySettings(e){return this.apiClient.request({method:"GET",url:`/users/${e}/privacy`})}async getUserIdFromUsername(e){return this.apiClient.request({method:"GET",url:`/users/resolve/${e}`})}async followUser(e,t){return this.apiClient.request({method:"POST",url:`/users/${e}/follow`,data:{targetUserId:t}})}async unfollowUser(e,t){return this.apiClient.request({method:"POST",url:`/users/${e}/unfollow`,data:{targetUserId:t}})}}},317:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useKarma=void 0;const n=r(953),s=r(442),o=r(772);t.useKarma=e=>{const t=(0,o.useOxyContext)(),r=(null==e?void 0:e.apiUrl)||t.apiUrl,a=(null==e?void 0:e.getToken)||t.getToken;if(!r)throw new Error("API URL is required. Provide it either through options or OxyProvider.");const[i]=(0,n.useState)((()=>new s.ApiClient({apiUrl:r})));return{getUserKarma:(0,n.useCallback)((async e=>{try{return await i.request({method:"GET",url:`/karma/${e}/total`,headers:a?{Authorization:`Bearer ${a()||""}`}:void 0})}catch(e){return{success:!1,error:e.message||"Failed to get karma"}}}),[i,a]),getUserKarmaHistory:(0,n.useCallback)((async(e,t,r)=>{try{if(!a)return{success:!1,error:"Authentication token is required"};const n={};return void 0!==t&&(n.limit=t.toString()),void 0!==r&&(n.offset=r.toString()),await i.request({method:"GET",url:`/karma/${e}/history`,params:n,headers:{Authorization:`Bearer ${a()||""}`}})}catch(e){return{success:!1,error:e.message||"Failed to get karma history"}}}),[i,a]),awardKarma:(0,n.useCallback)((async e=>{try{return a?await i.request({method:"POST",url:"/karma/award",data:e,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to award karma"}}}),[i,a]),deductKarma:(0,n.useCallback)((async e=>{try{return a?await i.request({method:"POST",url:"/karma/deduct",data:e,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to deduct karma"}}}),[i,a]),getKarmaLeaderboard:(0,n.useCallback)((async(e=10,t=0)=>{try{return await i.request({method:"GET",url:"/karma/leaderboard",params:{limit:e,offset:t},headers:a?{Authorization:`Bearer ${a()||""}`}:void 0})}catch(e){return{success:!1,error:e.message||"Failed to get karma leaderboard"}}}),[i,a]),getKarmaRules:(0,n.useCallback)((async()=>{try{return await i.request({method:"GET",url:"/karma/rules",headers:a?{Authorization:`Bearer ${a()||""}`}:void 0})}catch(e){return{success:!1,error:e.message||"Failed to get karma rules"}}}),[i,a]),createOrUpdateKarmaRule:(0,n.useCallback)((async e=>{try{return a?await i.request({method:"POST",url:"/karma/rules",data:e,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to create or update karma rule"}}}),[i,a])}}},425:(e,t,r)=>{function n(e,t){return function(){return e.apply(t,arguments)}}const{toString:s}=Object.prototype,{getPrototypeOf:o}=Object,a=(i=Object.create(null),e=>{const t=s.call(e);return i[t]||(i[t]=t.slice(8,-1).toLowerCase())});var i;const c=e=>(e=e.toLowerCase(),t=>a(t)===e),u=e=>t=>typeof t===e,{isArray:l}=Array,d=u("undefined"),h=c("ArrayBuffer"),f=u("string"),p=u("function"),m=u("number"),y=e=>null!==e&&"object"==typeof e,g=e=>{if("object"!==a(e))return!1;const t=o(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)},b=c("Date"),w=c("File"),O=c("Blob"),k=c("FileList"),T=c("URLSearchParams"),[v,S,E,x]=["ReadableStream","Request","Response","Headers"].map(c);function A(e,t,{allOwnKeys:r=!1}={}){if(null==e)return;let n,s;if("object"!=typeof e&&(e=[e]),l(e))for(n=0,s=e.length;n<s;n++)t.call(null,e[n],n,e);else{const s=r?Object.getOwnPropertyNames(e):Object.keys(e),o=s.length;let a;for(n=0;n<o;n++)a=s[n],t.call(null,e[a],a,e)}}function R(e,t){t=t.toLowerCase();const r=Object.keys(e);let n,s=r.length;for(;s-- >0;)if(n=r[s],t===n.toLowerCase())return n;return null}const C="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:r.g,P=e=>!d(e)&&e!==C,_=(U="undefined"!=typeof Uint8Array&&o(Uint8Array),e=>U&&e instanceof U);var U;const j=c("HTMLFormElement"),B=(({hasOwnProperty:e})=>(t,r)=>e.call(t,r))(Object.prototype),q=c("RegExp"),F=(e,t)=>{const r=Object.getOwnPropertyDescriptors(e),n={};A(r,((r,s)=>{let o;!1!==(o=t(r,s,e))&&(n[s]=o||r)})),Object.defineProperties(e,n)},N=c("AsyncFunction"),L=(I="function"==typeof setImmediate,D=p(C.postMessage),I?setImmediate:D?($=`axios@${Math.random()}`,z=[],C.addEventListener("message",(({source:e,data:t})=>{e===C&&t===$&&z.length&&z.shift()()}),!1),e=>{z.push(e),C.postMessage($,"*")}):e=>setTimeout(e));var I,D,$,z;const M="undefined"!=typeof queueMicrotask?queueMicrotask.bind(C):"undefined"!=typeof process&&process.nextTick||L;var K={isArray:l,isArrayBuffer:h,isBuffer:function(e){return null!==e&&!d(e)&&null!==e.constructor&&!d(e.constructor)&&p(e.constructor.isBuffer)&&e.constructor.isBuffer(e)},isFormData:e=>{let t;return e&&("function"==typeof FormData&&e instanceof FormData||p(e.append)&&("formdata"===(t=a(e))||"object"===t&&p(e.toString)&&"[object FormData]"===e.toString()))},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&h(e.buffer),t},isString:f,isNumber:m,isBoolean:e=>!0===e||!1===e,isObject:y,isPlainObject:g,isReadableStream:v,isRequest:S,isResponse:E,isHeaders:x,isUndefined:d,isDate:b,isFile:w,isBlob:O,isRegExp:q,isFunction:p,isStream:e=>y(e)&&p(e.pipe),isURLSearchParams:T,isTypedArray:_,isFileList:k,forEach:A,merge:function e(){const{caseless:t}=P(this)&&this||{},r={},n=(n,s)=>{const o=t&&R(r,s)||s;g(r[o])&&g(n)?r[o]=e(r[o],n):g(n)?r[o]=e({},n):l(n)?r[o]=n.slice():r[o]=n};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&A(arguments[e],n);return r},extend:(e,t,r,{allOwnKeys:s}={})=>(A(t,((t,s)=>{r&&p(t)?e[s]=n(t,r):e[s]=t}),{allOwnKeys:s}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,r,n)=>{e.prototype=Object.create(t.prototype,n),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),r&&Object.assign(e.prototype,r)},toFlatObject:(e,t,r,n)=>{let s,a,i;const c={};if(t=t||{},null==e)return t;do{for(s=Object.getOwnPropertyNames(e),a=s.length;a-- >0;)i=s[a],n&&!n(i,e,t)||c[i]||(t[i]=e[i],c[i]=!0);e=!1!==r&&o(e)}while(e&&(!r||r(e,t))&&e!==Object.prototype);return t},kindOf:a,kindOfTest:c,endsWith:(e,t,r)=>{e=String(e),(void 0===r||r>e.length)&&(r=e.length),r-=t.length;const n=e.indexOf(t,r);return-1!==n&&n===r},toArray:e=>{if(!e)return null;if(l(e))return e;let t=e.length;if(!m(t))return null;const r=new Array(t);for(;t-- >0;)r[t]=e[t];return r},forEachEntry:(e,t)=>{const r=(e&&e[Symbol.iterator]).call(e);let n;for(;(n=r.next())&&!n.done;){const r=n.value;t.call(e,r[0],r[1])}},matchAll:(e,t)=>{let r;const n=[];for(;null!==(r=e.exec(t));)n.push(r);return n},isHTMLForm:j,hasOwnProperty:B,hasOwnProp:B,reduceDescriptors:F,freezeMethods:e=>{F(e,((t,r)=>{if(p(e)&&-1!==["arguments","caller","callee"].indexOf(r))return!1;const n=e[r];p(n)&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+r+"'")}))}))},toObjectSet:(e,t)=>{const r={},n=e=>{e.forEach((e=>{r[e]=!0}))};return l(e)?n(e):n(String(e).split(t)),r},toCamelCase:e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,(function(e,t,r){return t.toUpperCase()+r})),noop:()=>{},toFiniteNumber:(e,t)=>null!=e&&Number.isFinite(e=+e)?e:t,findKey:R,global:C,isContextDefined:P,isSpecCompliantForm:function(e){return!!(e&&p(e.append)&&"FormData"===e[Symbol.toStringTag]&&e[Symbol.iterator])},toJSONObject:e=>{const t=new Array(10),r=(e,n)=>{if(y(e)){if(t.indexOf(e)>=0)return;if(!("toJSON"in e)){t[n]=e;const s=l(e)?[]:{};return A(e,((e,t)=>{const o=r(e,n+1);!d(o)&&(s[t]=o)})),t[n]=void 0,s}}return e};return r(e,0)},isAsyncFn:N,isThenable:e=>e&&(y(e)||p(e))&&p(e.then)&&p(e.catch),setImmediate:L,asap:M};function W(e,t,r,n,s){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),r&&(this.config=r),n&&(this.request=n),s&&(this.response=s,this.status=s.status?s.status:null)}K.inherits(W,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:K.toJSONObject(this.config),code:this.code,status:this.status}}});const G=W.prototype,H={};function J(e){return K.isPlainObject(e)||K.isArray(e)}function V(e){return K.endsWith(e,"[]")?e.slice(0,-2):e}function X(e,t,r){return e?e.concat(t).map((function(e,t){return e=V(e),!r&&t?"["+e+"]":e})).join(r?".":""):t}["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach((e=>{H[e]={value:e}})),Object.defineProperties(W,H),Object.defineProperty(G,"isAxiosError",{value:!0}),W.from=(e,t,r,n,s,o)=>{const a=Object.create(G);return K.toFlatObject(e,a,(function(e){return e!==Error.prototype}),(e=>"isAxiosError"!==e)),W.call(a,e.message,t,r,n,s),a.cause=e,a.name=e.name,o&&Object.assign(a,o),a};const Q=K.toFlatObject(K,{},null,(function(e){return/^is[A-Z]/.test(e)}));function Z(e,t,r){if(!K.isObject(e))throw new TypeError("target must be an object");t=t||new FormData;const n=(r=K.toFlatObject(r,{metaTokens:!0,dots:!1,indexes:!1},!1,(function(e,t){return!K.isUndefined(t[e])}))).metaTokens,s=r.visitor||u,o=r.dots,a=r.indexes,i=(r.Blob||"undefined"!=typeof Blob&&Blob)&&K.isSpecCompliantForm(t);if(!K.isFunction(s))throw new TypeError("visitor must be a function");function c(e){if(null===e)return"";if(K.isDate(e))return e.toISOString();if(!i&&K.isBlob(e))throw new W("Blob is not supported. Use a Buffer instead.");return K.isArrayBuffer(e)||K.isTypedArray(e)?i&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function u(e,r,s){let i=e;if(e&&!s&&"object"==typeof e)if(K.endsWith(r,"{}"))r=n?r:r.slice(0,-2),e=JSON.stringify(e);else if(K.isArray(e)&&function(e){return K.isArray(e)&&!e.some(J)}(e)||(K.isFileList(e)||K.endsWith(r,"[]"))&&(i=K.toArray(e)))return r=V(r),i.forEach((function(e,n){!K.isUndefined(e)&&null!==e&&t.append(!0===a?X([r],n,o):null===a?r:r+"[]",c(e))})),!1;return!!J(e)||(t.append(X(s,r,o),c(e)),!1)}const l=[],d=Object.assign(Q,{defaultVisitor:u,convertValue:c,isVisitable:J});if(!K.isObject(e))throw new TypeError("data must be an object");return function e(r,n){if(!K.isUndefined(r)){if(-1!==l.indexOf(r))throw Error("Circular reference detected in "+n.join("."));l.push(r),K.forEach(r,(function(r,o){!0===(!(K.isUndefined(r)||null===r)&&s.call(t,r,K.isString(o)?o.trim():o,n,d))&&e(r,n?n.concat(o):[o])})),l.pop()}}(e),t}function Y(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,(function(e){return t[e]}))}function ee(e,t){this._pairs=[],e&&Z(e,this,t)}const te=ee.prototype;function re(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function ne(e,t,r){if(!t)return e;const n=r&&r.encode||re;K.isFunction(r)&&(r={serialize:r});const s=r&&r.serialize;let o;if(o=s?s(t,r):K.isURLSearchParams(t)?t.toString():new ee(t,r).toString(n),o){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+o}return e}te.append=function(e,t){this._pairs.push([e,t])},te.toString=function(e){const t=e?function(t){return e.call(this,t,Y)}:Y;return this._pairs.map((function(e){return t(e[0])+"="+t(e[1])}),"").join("&")};var se=class{constructor(){this.handlers=[]}use(e,t,r){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!r&&r.synchronous,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){K.forEach(this.handlers,(function(t){null!==t&&e(t)}))}},oe={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ae={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:ee,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const ie="undefined"!=typeof window&&"undefined"!=typeof document,ce="object"==typeof navigator&&navigator||void 0,ue=ie&&(!ce||["ReactNative","NativeScript","NS"].indexOf(ce.product)<0),le="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,de=ie&&window.location.href||"http://localhost";var he={...Object.freeze({__proto__:null,hasBrowserEnv:ie,hasStandardBrowserWebWorkerEnv:le,hasStandardBrowserEnv:ue,navigator:ce,origin:de}),...ae};function fe(e){function t(e,r,n,s){let o=e[s++];if("__proto__"===o)return!0;const a=Number.isFinite(+o),i=s>=e.length;return o=!o&&K.isArray(n)?n.length:o,i?(K.hasOwnProp(n,o)?n[o]=[n[o],r]:n[o]=r,!a):(n[o]&&K.isObject(n[o])||(n[o]=[]),t(e,r,n[o],s)&&K.isArray(n[o])&&(n[o]=function(e){const t={},r=Object.keys(e);let n;const s=r.length;let o;for(n=0;n<s;n++)o=r[n],t[o]=e[o];return t}(n[o])),!a)}if(K.isFormData(e)&&K.isFunction(e.entries)){const r={};return K.forEachEntry(e,((e,n)=>{t(function(e){return K.matchAll(/\w+|\[(\w*)]/g,e).map((e=>"[]"===e[0]?"":e[1]||e[0]))}(e),n,r,0)})),r}return null}const pe={transitional:oe,adapter:["xhr","http","fetch"],transformRequest:[function(e,t){const r=t.getContentType()||"",n=r.indexOf("application/json")>-1,s=K.isObject(e);if(s&&K.isHTMLForm(e)&&(e=new FormData(e)),K.isFormData(e))return n?JSON.stringify(fe(e)):e;if(K.isArrayBuffer(e)||K.isBuffer(e)||K.isStream(e)||K.isFile(e)||K.isBlob(e)||K.isReadableStream(e))return e;if(K.isArrayBufferView(e))return e.buffer;if(K.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let o;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return Z(e,new he.classes.URLSearchParams,Object.assign({visitor:function(e,t,r,n){return he.isNode&&K.isBuffer(e)?(this.append(t,e.toString("base64")),!1):n.defaultVisitor.apply(this,arguments)}},t))}(e,this.formSerializer).toString();if((o=K.isFileList(e))||r.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return Z(o?{"files[]":e}:e,t&&new t,this.formSerializer)}}return s||n?(t.setContentType("application/json",!1),function(e){if(K.isString(e))try{return(0,JSON.parse)(e),K.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(0,JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||pe.transitional,r=t&&t.forcedJSONParsing,n="json"===this.responseType;if(K.isResponse(e)||K.isReadableStream(e))return e;if(e&&K.isString(e)&&(r&&!this.responseType||n)){const r=!(t&&t.silentJSONParsing)&&n;try{return JSON.parse(e)}catch(e){if(r){if("SyntaxError"===e.name)throw W.from(e,W.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:he.classes.FormData,Blob:he.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};K.forEach(["delete","get","head","post","put","patch"],(e=>{pe.headers[e]={}}));var me=pe;const ye=K.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),ge=Symbol("internals");function be(e){return e&&String(e).trim().toLowerCase()}function we(e){return!1===e||null==e?e:K.isArray(e)?e.map(we):String(e)}function Oe(e,t,r,n,s){return K.isFunction(n)?n.call(this,t,r):(s&&(t=r),K.isString(t)?K.isString(n)?-1!==t.indexOf(n):K.isRegExp(n)?n.test(t):void 0:void 0)}class ke{constructor(e){e&&this.set(e)}set(e,t,r){const n=this;function s(e,t,r){const s=be(t);if(!s)throw new Error("header name must be a non-empty string");const o=K.findKey(n,s);(!o||void 0===n[o]||!0===r||void 0===r&&!1!==n[o])&&(n[o||t]=we(e))}const o=(e,t)=>K.forEach(e,((e,r)=>s(e,r,t)));if(K.isPlainObject(e)||e instanceof this.constructor)o(e,t);else if(K.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim()))o((e=>{const t={};let r,n,s;return e&&e.split("\n").forEach((function(e){s=e.indexOf(":"),r=e.substring(0,s).trim().toLowerCase(),n=e.substring(s+1).trim(),!r||t[r]&&ye[r]||("set-cookie"===r?t[r]?t[r].push(n):t[r]=[n]:t[r]=t[r]?t[r]+", "+n:n)})),t})(e),t);else if(K.isHeaders(e))for(const[t,n]of e.entries())s(n,t,r);else null!=e&&s(t,e,r);return this}get(e,t){if(e=be(e)){const r=K.findKey(this,e);if(r){const e=this[r];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),r=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let n;for(;n=r.exec(e);)t[n[1]]=n[2];return t}(e);if(K.isFunction(t))return t.call(this,e,r);if(K.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=be(e)){const r=K.findKey(this,e);return!(!r||void 0===this[r]||t&&!Oe(0,this[r],r,t))}return!1}delete(e,t){const r=this;let n=!1;function s(e){if(e=be(e)){const s=K.findKey(r,e);!s||t&&!Oe(0,r[s],s,t)||(delete r[s],n=!0)}}return K.isArray(e)?e.forEach(s):s(e),n}clear(e){const t=Object.keys(this);let r=t.length,n=!1;for(;r--;){const s=t[r];e&&!Oe(0,this[s],s,e,!0)||(delete this[s],n=!0)}return n}normalize(e){const t=this,r={};return K.forEach(this,((n,s)=>{const o=K.findKey(r,s);if(o)return t[o]=we(n),void delete t[s];const a=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,((e,t,r)=>t.toUpperCase()+r))}(s):String(s).trim();a!==s&&delete t[s],t[a]=we(n),r[a]=!0})),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return K.forEach(this,((r,n)=>{null!=r&&!1!==r&&(t[n]=e&&K.isArray(r)?r.join(", "):r)})),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map((([e,t])=>e+": "+t)).join("\n")}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const r=new this(e);return t.forEach((e=>r.set(e))),r}static accessor(e){const t=(this[ge]=this[ge]={accessors:{}}).accessors,r=this.prototype;function n(e){const n=be(e);t[n]||(function(e,t){const r=K.toCamelCase(" "+t);["get","set","has"].forEach((n=>{Object.defineProperty(e,n+r,{value:function(e,r,s){return this[n].call(this,t,e,r,s)},configurable:!0})}))}(r,e),t[n]=!0)}return K.isArray(e)?e.forEach(n):n(e),this}}ke.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),K.reduceDescriptors(ke.prototype,(({value:e},t)=>{let r=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(e){this[r]=e}}})),K.freezeMethods(ke);var Te=ke;function ve(e,t){const r=this||me,n=t||r,s=Te.from(n.headers);let o=n.data;return K.forEach(e,(function(e){o=e.call(r,o,s.normalize(),t?t.status:void 0)})),s.normalize(),o}function Se(e){return!(!e||!e.__CANCEL__)}function Ee(e,t,r){W.call(this,null==e?"canceled":e,W.ERR_CANCELED,t,r),this.name="CanceledError"}function xe(e,t,r){const n=r.config.validateStatus;r.status&&n&&!n(r.status)?t(new W("Request failed with status code "+r.status,[W.ERR_BAD_REQUEST,W.ERR_BAD_RESPONSE][Math.floor(r.status/100)-4],r.config,r.request,r)):e(r)}K.inherits(Ee,W,{__CANCEL__:!0});const Ae=(e,t,r=3)=>{let n=0;const s=function(e,t){e=e||10;const r=new Array(e),n=new Array(e);let s,o=0,a=0;return t=void 0!==t?t:1e3,function(i){const c=Date.now(),u=n[a];s||(s=c),r[o]=i,n[o]=c;let l=a,d=0;for(;l!==o;)d+=r[l++],l%=e;if(o=(o+1)%e,o===a&&(a=(a+1)%e),c-s<t)return;const h=u&&c-u;return h?Math.round(1e3*d/h):void 0}}(50,250);return function(e,t){let r,n,s=0,o=1e3/t;const a=(t,o=Date.now())=>{s=o,r=null,n&&(clearTimeout(n),n=null),e.apply(null,t)};return[(...e)=>{const t=Date.now(),i=t-s;i>=o?a(e,t):(r=e,n||(n=setTimeout((()=>{n=null,a(r)}),o-i)))},()=>r&&a(r)]}((r=>{const o=r.loaded,a=r.lengthComputable?r.total:void 0,i=o-n,c=s(i);n=o,e({loaded:o,total:a,progress:a?o/a:void 0,bytes:i,rate:c||void 0,estimated:c&&a&&o<=a?(a-o)/c:void 0,event:r,lengthComputable:null!=a,[t?"download":"upload"]:!0})}),r)},Re=(e,t)=>{const r=null!=e;return[n=>t[0]({lengthComputable:r,total:e,loaded:n}),t[1]]},Ce=e=>(...t)=>K.asap((()=>e(...t)));var Pe=he.hasStandardBrowserEnv?((e,t)=>r=>(r=new URL(r,he.origin),e.protocol===r.protocol&&e.host===r.host&&(t||e.port===r.port)))(new URL(he.origin),he.navigator&&/(msie|trident)/i.test(he.navigator.userAgent)):()=>!0,_e=he.hasStandardBrowserEnv?{write(e,t,r,n,s,o){const a=[e+"="+encodeURIComponent(t)];K.isNumber(r)&&a.push("expires="+new Date(r).toGMTString()),K.isString(n)&&a.push("path="+n),K.isString(s)&&a.push("domain="+s),!0===o&&a.push("secure"),document.cookie=a.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read:()=>null,remove(){}};function Ue(e,t,r){let n=!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t);return e&&n||0==r?function(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}const je=e=>e instanceof Te?{...e}:e;function Be(e,t){t=t||{};const r={};function n(e,t,r,n){return K.isPlainObject(e)&&K.isPlainObject(t)?K.merge.call({caseless:n},e,t):K.isPlainObject(t)?K.merge({},t):K.isArray(t)?t.slice():t}function s(e,t,r,s){return K.isUndefined(t)?K.isUndefined(e)?void 0:n(void 0,e,0,s):n(e,t,0,s)}function o(e,t){if(!K.isUndefined(t))return n(void 0,t)}function a(e,t){return K.isUndefined(t)?K.isUndefined(e)?void 0:n(void 0,e):n(void 0,t)}function i(r,s,o){return o in t?n(r,s):o in e?n(void 0,r):void 0}const c={url:o,method:o,data:o,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,withXSRFToken:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:i,headers:(e,t,r)=>s(je(e),je(t),0,!0)};return K.forEach(Object.keys(Object.assign({},e,t)),(function(n){const o=c[n]||s,a=o(e[n],t[n],n);K.isUndefined(a)&&o!==i||(r[n]=a)})),r}var qe=e=>{const t=Be({},e);let r,{data:n,withXSRFToken:s,xsrfHeaderName:o,xsrfCookieName:a,headers:i,auth:c}=t;if(t.headers=i=Te.from(i),t.url=ne(Ue(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&i.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):""))),K.isFormData(n))if(he.hasStandardBrowserEnv||he.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(!1!==(r=i.getContentType())){const[e,...t]=r?r.split(";").map((e=>e.trim())).filter(Boolean):[];i.setContentType([e||"multipart/form-data",...t].join("; "))}if(he.hasStandardBrowserEnv&&(s&&K.isFunction(s)&&(s=s(t)),s||!1!==s&&Pe(t.url))){const e=o&&a&&_e.read(a);e&&i.set(o,e)}return t},Fe="undefined"!=typeof XMLHttpRequest&&function(e){return new Promise((function(t,r){const n=qe(e);let s=n.data;const o=Te.from(n.headers).normalize();let a,i,c,u,l,{responseType:d,onUploadProgress:h,onDownloadProgress:f}=n;function p(){u&&u(),l&&l(),n.cancelToken&&n.cancelToken.unsubscribe(a),n.signal&&n.signal.removeEventListener("abort",a)}let m=new XMLHttpRequest;function y(){if(!m)return;const n=Te.from("getAllResponseHeaders"in m&&m.getAllResponseHeaders());xe((function(e){t(e),p()}),(function(e){r(e),p()}),{data:d&&"text"!==d&&"json"!==d?m.response:m.responseText,status:m.status,statusText:m.statusText,headers:n,config:e,request:m}),m=null}m.open(n.method.toUpperCase(),n.url,!0),m.timeout=n.timeout,"onloadend"in m?m.onloadend=y:m.onreadystatechange=function(){m&&4===m.readyState&&(0!==m.status||m.responseURL&&0===m.responseURL.indexOf("file:"))&&setTimeout(y)},m.onabort=function(){m&&(r(new W("Request aborted",W.ECONNABORTED,e,m)),m=null)},m.onerror=function(){r(new W("Network Error",W.ERR_NETWORK,e,m)),m=null},m.ontimeout=function(){let t=n.timeout?"timeout of "+n.timeout+"ms exceeded":"timeout exceeded";const s=n.transitional||oe;n.timeoutErrorMessage&&(t=n.timeoutErrorMessage),r(new W(t,s.clarifyTimeoutError?W.ETIMEDOUT:W.ECONNABORTED,e,m)),m=null},void 0===s&&o.setContentType(null),"setRequestHeader"in m&&K.forEach(o.toJSON(),(function(e,t){m.setRequestHeader(t,e)})),K.isUndefined(n.withCredentials)||(m.withCredentials=!!n.withCredentials),d&&"json"!==d&&(m.responseType=n.responseType),f&&([c,l]=Ae(f,!0),m.addEventListener("progress",c)),h&&m.upload&&([i,u]=Ae(h),m.upload.addEventListener("progress",i),m.upload.addEventListener("loadend",u)),(n.cancelToken||n.signal)&&(a=t=>{m&&(r(!t||t.type?new Ee(null,e,m):t),m.abort(),m=null)},n.cancelToken&&n.cancelToken.subscribe(a),n.signal&&(n.signal.aborted?a():n.signal.addEventListener("abort",a)));const g=function(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}(n.url);g&&-1===he.protocols.indexOf(g)?r(new W("Unsupported protocol "+g+":",W.ERR_BAD_REQUEST,e)):m.send(s||null)}))},Ne=(e,t)=>{const{length:r}=e=e?e.filter(Boolean):[];if(t||r){let r,n=new AbortController;const s=function(e){if(!r){r=!0,a();const t=e instanceof Error?e:this.reason;n.abort(t instanceof W?t:new Ee(t instanceof Error?t.message:t))}};let o=t&&setTimeout((()=>{o=null,s(new W(`timeout ${t} of ms exceeded`,W.ETIMEDOUT))}),t);const a=()=>{e&&(o&&clearTimeout(o),o=null,e.forEach((e=>{e.unsubscribe?e.unsubscribe(s):e.removeEventListener("abort",s)})),e=null)};e.forEach((e=>e.addEventListener("abort",s)));const{signal:i}=n;return i.unsubscribe=()=>K.asap(a),i}};const Le=function*(e,t){let r=e.byteLength;if(!t||r<t)return void(yield e);let n,s=0;for(;s<r;)n=s+t,yield e.slice(s,n),s=n},Ie=(e,t,r,n)=>{const s=async function*(e,t){for await(const r of async function*(e){if(e[Symbol.asyncIterator])return void(yield*e);const t=e.getReader();try{for(;;){const{done:e,value:r}=await t.read();if(e)break;yield r}}finally{await t.cancel()}}(e))yield*Le(r,t)}(e,t);let o,a=0,i=e=>{o||(o=!0,n&&n(e))};return new ReadableStream({async pull(e){try{const{done:t,value:n}=await s.next();if(t)return i(),void e.close();let o=n.byteLength;if(r){let e=a+=o;r(e)}e.enqueue(new Uint8Array(n))}catch(e){throw i(e),e}},cancel:e=>(i(e),s.return())},{highWaterMark:2})},De="function"==typeof fetch&&"function"==typeof Request&&"function"==typeof Response,$e=De&&"function"==typeof ReadableStream,ze=De&&("function"==typeof TextEncoder?(Me=new TextEncoder,e=>Me.encode(e)):async e=>new Uint8Array(await new Response(e).arrayBuffer()));var Me;const Ke=(e,...t)=>{try{return!!e(...t)}catch(e){return!1}},We=$e&&Ke((()=>{let e=!1;const t=new Request(he.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t})),Ge=$e&&Ke((()=>K.isReadableStream(new Response("").body))),He={stream:Ge&&(e=>e.body)};var Je;De&&(Je=new Response,["text","arrayBuffer","blob","formData","stream"].forEach((e=>{!He[e]&&(He[e]=K.isFunction(Je[e])?t=>t[e]():(t,r)=>{throw new W(`Response type '${e}' is not supported`,W.ERR_NOT_SUPPORT,r)})})));const Ve={http:null,xhr:Fe,fetch:De&&(async e=>{let{url:t,method:r,data:n,signal:s,cancelToken:o,timeout:a,onDownloadProgress:i,onUploadProgress:c,responseType:u,headers:l,withCredentials:d="same-origin",fetchOptions:h}=qe(e);u=u?(u+"").toLowerCase():"text";let f,p=Ne([s,o&&o.toAbortSignal()],a);const m=p&&p.unsubscribe&&(()=>{p.unsubscribe()});let y;try{if(c&&We&&"get"!==r&&"head"!==r&&0!==(y=await(async(e,t)=>{const r=K.toFiniteNumber(e.getContentLength());return null==r?(async e=>{if(null==e)return 0;if(K.isBlob(e))return e.size;if(K.isSpecCompliantForm(e)){const t=new Request(he.origin,{method:"POST",body:e});return(await t.arrayBuffer()).byteLength}return K.isArrayBufferView(e)||K.isArrayBuffer(e)?e.byteLength:(K.isURLSearchParams(e)&&(e+=""),K.isString(e)?(await ze(e)).byteLength:void 0)})(t):r})(l,n))){let e,r=new Request(t,{method:"POST",body:n,duplex:"half"});if(K.isFormData(n)&&(e=r.headers.get("content-type"))&&l.setContentType(e),r.body){const[e,t]=Re(y,Ae(Ce(c)));n=Ie(r.body,65536,e,t)}}K.isString(d)||(d=d?"include":"omit");const s="credentials"in Request.prototype;f=new Request(t,{...h,signal:p,method:r.toUpperCase(),headers:l.normalize().toJSON(),body:n,duplex:"half",credentials:s?d:void 0});let o=await fetch(f);const a=Ge&&("stream"===u||"response"===u);if(Ge&&(i||a&&m)){const e={};["status","statusText","headers"].forEach((t=>{e[t]=o[t]}));const t=K.toFiniteNumber(o.headers.get("content-length")),[r,n]=i&&Re(t,Ae(Ce(i),!0))||[];o=new Response(Ie(o.body,65536,r,(()=>{n&&n(),m&&m()})),e)}u=u||"text";let g=await He[K.findKey(He,u)||"text"](o,e);return!a&&m&&m(),await new Promise(((t,r)=>{xe(t,r,{data:g,headers:Te.from(o.headers),status:o.status,statusText:o.statusText,config:e,request:f})}))}catch(t){if(m&&m(),t&&"TypeError"===t.name&&/fetch/i.test(t.message))throw Object.assign(new W("Network Error",W.ERR_NETWORK,e,f),{cause:t.cause||t});throw W.from(t,t&&t.code,e,f)}})};K.forEach(Ve,((e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}}));const Xe=e=>`- ${e}`,Qe=e=>K.isFunction(e)||null===e||!1===e;var Ze=e=>{e=K.isArray(e)?e:[e];const{length:t}=e;let r,n;const s={};for(let o=0;o<t;o++){let t;if(r=e[o],n=r,!Qe(r)&&(n=Ve[(t=String(r)).toLowerCase()],void 0===n))throw new W(`Unknown adapter '${t}'`);if(n)break;s[t||"#"+o]=n}if(!n){const e=Object.entries(s).map((([e,t])=>`adapter ${e} `+(!1===t?"is not supported by the environment":"is not available in the build")));throw new W("There is no suitable adapter to dispatch the request "+(t?e.length>1?"since :\n"+e.map(Xe).join("\n"):" "+Xe(e[0]):"as no adapter specified"),"ERR_NOT_SUPPORT")}return n};function Ye(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Ee(null,e)}function et(e){return Ye(e),e.headers=Te.from(e.headers),e.data=ve.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Ze(e.adapter||me.adapter)(e).then((function(t){return Ye(e),t.data=ve.call(e,e.transformResponse,t),t.headers=Te.from(t.headers),t}),(function(t){return Se(t)||(Ye(e),t&&t.response&&(t.response.data=ve.call(e,e.transformResponse,t.response),t.response.headers=Te.from(t.response.headers))),Promise.reject(t)}))}const tt={};["object","boolean","number","function","string","symbol"].forEach(((e,t)=>{tt[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}}));const rt={};tt.transitional=function(e,t,r){function n(e,t){return"[Axios v1.8.3] Transitional option '"+e+"'"+t+(r?". "+r:"")}return(r,s,o)=>{if(!1===e)throw new W(n(s," has been removed"+(t?" in "+t:"")),W.ERR_DEPRECATED);return t&&!rt[s]&&(rt[s]=!0,console.warn(n(s," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(r,s,o)}},tt.spelling=function(e){return(t,r)=>(console.warn(`${r} is likely a misspelling of ${e}`),!0)};var nt={assertOptions:function(e,t,r){if("object"!=typeof e)throw new W("options must be an object",W.ERR_BAD_OPTION_VALUE);const n=Object.keys(e);let s=n.length;for(;s-- >0;){const o=n[s],a=t[o];if(a){const t=e[o],r=void 0===t||a(t,o,e);if(!0!==r)throw new W("option "+o+" must be "+r,W.ERR_BAD_OPTION_VALUE)}else if(!0!==r)throw new W("Unknown option "+o,W.ERR_BAD_OPTION)}},validators:tt};const st=nt.validators;class ot{constructor(e){this.defaults=e,this.interceptors={request:new se,response:new se}}async request(e,t){try{return await this._request(e,t)}catch(e){if(e instanceof Error){let t={};Error.captureStackTrace?Error.captureStackTrace(t):t=new Error;const r=t.stack?t.stack.replace(/^.+\n/,""):"";try{e.stack?r&&!String(e.stack).endsWith(r.replace(/^.+\n.+\n/,""))&&(e.stack+="\n"+r):e.stack=r}catch(e){}}throw e}}_request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=Be(this.defaults,t);const{transitional:r,paramsSerializer:n,headers:s}=t;void 0!==r&&nt.assertOptions(r,{silentJSONParsing:st.transitional(st.boolean),forcedJSONParsing:st.transitional(st.boolean),clarifyTimeoutError:st.transitional(st.boolean)},!1),null!=n&&(K.isFunction(n)?t.paramsSerializer={serialize:n}:nt.assertOptions(n,{encode:st.function,serialize:st.function},!0)),void 0!==t.allowAbsoluteUrls||(void 0!==this.defaults.allowAbsoluteUrls?t.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:t.allowAbsoluteUrls=!0),nt.assertOptions(t,{baseUrl:st.spelling("baseURL"),withXsrfToken:st.spelling("withXSRFToken")},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase();let o=s&&K.merge(s.common,s[t.method]);s&&K.forEach(["delete","get","head","post","put","patch","common"],(e=>{delete s[e]})),t.headers=Te.concat(o,s);const a=[];let i=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(i=i&&e.synchronous,a.unshift(e.fulfilled,e.rejected))}));const c=[];let u;this.interceptors.response.forEach((function(e){c.push(e.fulfilled,e.rejected)}));let l,d=0;if(!i){const e=[et.bind(this),void 0];for(e.unshift.apply(e,a),e.push.apply(e,c),l=e.length,u=Promise.resolve(t);d<l;)u=u.then(e[d++],e[d++]);return u}l=a.length;let h=t;for(d=0;d<l;){const e=a[d++],t=a[d++];try{h=e(h)}catch(e){t.call(this,e);break}}try{u=et.call(this,h)}catch(e){return Promise.reject(e)}for(d=0,l=c.length;d<l;)u=u.then(c[d++],c[d++]);return u}getUri(e){return ne(Ue((e=Be(this.defaults,e)).baseURL,e.url,e.allowAbsoluteUrls),e.params,e.paramsSerializer)}}K.forEach(["delete","get","head","options"],(function(e){ot.prototype[e]=function(t,r){return this.request(Be(r||{},{method:e,url:t,data:(r||{}).data}))}})),K.forEach(["post","put","patch"],(function(e){function t(t){return function(r,n,s){return this.request(Be(s||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:r,data:n}))}}ot.prototype[e]=t(),ot.prototype[e+"Form"]=t(!0)}));var at=ot;class it{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((function(e){t=e}));const r=this;this.promise.then((e=>{if(!r._listeners)return;let t=r._listeners.length;for(;t-- >0;)r._listeners[t](e);r._listeners=null})),this.promise.then=e=>{let t;const n=new Promise((e=>{r.subscribe(e),t=e})).then(e);return n.cancel=function(){r.unsubscribe(t)},n},e((function(e,n,s){r.reason||(r.reason=new Ee(e,n,s),t(r.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}toAbortSignal(){const e=new AbortController,t=t=>{e.abort(t)};return this.subscribe(t),e.signal.unsubscribe=()=>this.unsubscribe(t),e.signal}static source(){let e;return{token:new it((function(t){e=t})),cancel:e}}}var ct=it;const ut={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(ut).forEach((([e,t])=>{ut[t]=e}));var lt=ut;const dt=function e(t){const r=new at(t),s=n(at.prototype.request,r);return K.extend(s,at.prototype,r,{allOwnKeys:!0}),K.extend(s,r,null,{allOwnKeys:!0}),s.create=function(r){return e(Be(t,r))},s}(me);dt.Axios=at,dt.CanceledError=Ee,dt.CancelToken=ct,dt.isCancel=Se,dt.VERSION="1.8.3",dt.toFormData=Z,dt.AxiosError=W,dt.Cancel=dt.CanceledError,dt.all=function(e){return Promise.all(e)},dt.spread=function(e){return function(t){return e.apply(null,t)}},dt.isAxiosError=function(e){return K.isObject(e)&&!0===e.isAxiosError},dt.mergeConfig=Be,dt.AxiosHeaders=Te,dt.formToJSON=e=>fe(K.isHTMLForm(e)?new FormData(e):e),dt.getAdapter=Ze,dt.HttpStatusCode=lt,dt.default=dt,e.exports=dt},442:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.ApiClient=void 0;const s=n(r(425));t.ApiClient=class{constructor(e){this.config=e,this.axiosInstance=s.default.create({baseURL:e.apiUrl,headers:{"Content-Type":"application/json"}}),this.axiosInstance.interceptors.request.use((e=>{const t=this.getAccessToken();return t&&(e.headers.Authorization=`Bearer ${t}`),e}),(e=>Promise.reject(e))),this.axiosInstance.interceptors.response.use((e=>e),(async e=>{var t;const r=e.config;if(401===(null===(t=e.response)||void 0===t?void 0:t.status)&&!r._retry){r._retry=!0;try{const e=await this.refreshToken();if(e)return this.storeTokens(e),r.headers.Authorization=`Bearer ${e.accessToken}`,this.axiosInstance(r)}catch(e){return this.clearTokens(),Promise.reject(e)}}return Promise.reject(e)})),e.tokenRefreshInterval&&this.setupTokenRefresh(e.tokenRefreshInterval)}async request(e){var t;try{return(await this.axiosInstance.request(e)).data}catch(e){return(null===(t=e.response)||void 0===t?void 0:t.data)?e.response.data:{success:!1,error:e.message||"Network error"}}}getAccessToken(){if("undefined"==typeof window||"none"===this.config.storage)return null;switch(this.config.storage){case"local":default:return localStorage.getItem("oxy_access_token");case"session":return sessionStorage.getItem("oxy_access_token");case"cookie":const e=document.cookie.match(/(^|;)\s*oxy_access_token=([^;]+)/);return e?e[2]:null}}getRefreshToken(){if("undefined"==typeof window||"none"===this.config.storage)return null;switch(this.config.storage){case"local":default:return localStorage.getItem("oxy_refresh_token");case"session":return sessionStorage.getItem("oxy_refresh_token");case"cookie":const e=document.cookie.match(/(^|;)\s*oxy_refresh_token=([^;]+)/);return e?e[2]:null}}storeTokens(e){if("undefined"!=typeof window&&"none"!==this.config.storage)switch(this.config.storage){case"local":default:localStorage.setItem("oxy_access_token",e.accessToken),localStorage.setItem("oxy_refresh_token",e.refreshToken);break;case"session":sessionStorage.setItem("oxy_access_token",e.accessToken),sessionStorage.setItem("oxy_refresh_token",e.refreshToken);break;case"cookie":document.cookie=`oxy_access_token=${e.accessToken}; path=/;`,document.cookie=`oxy_refresh_token=${e.refreshToken}; path=/;`}}clearTokens(){if("undefined"!=typeof window&&"none"!==this.config.storage){switch(this.config.storage){case"local":default:localStorage.removeItem("oxy_access_token"),localStorage.removeItem("oxy_refresh_token");break;case"session":sessionStorage.removeItem("oxy_access_token"),sessionStorage.removeItem("oxy_refresh_token");break;case"cookie":document.cookie="oxy_access_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",document.cookie="oxy_refresh_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"}this.tokenRefreshTimeout&&(clearTimeout(this.tokenRefreshTimeout),this.tokenRefreshTimeout=void 0)}}async refreshToken(){const e=this.getRefreshToken();if(!e)return null;try{const t=await s.default.post(`${this.config.apiUrl}/auth/refresh-token`,{refreshToken:e});return t.data.success&&t.data.data?t.data.data:null}catch(e){return null}}setupTokenRefresh(e){"undefined"!=typeof window&&(this.tokenRefreshTimeout=setTimeout((async()=>{try{const e=await this.refreshToken();e&&this.storeTokens(e)}finally{this.setupTokenRefresh(e)}}),e))}}},467:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OxyBackend=t.OxyWalletBackend=t.OxyKarmaBackend=t.OxyUsersBackend=t.OxyAuthBackend=void 0;const n=r(109);Object.defineProperty(t,"OxyAuthBackend",{enumerable:!0,get:function(){return n.OxyAuthBackend}});const s=r(223);Object.defineProperty(t,"OxyUsersBackend",{enumerable:!0,get:function(){return s.OxyUsersBackend}});const o=r(947);Object.defineProperty(t,"OxyKarmaBackend",{enumerable:!0,get:function(){return o.OxyKarmaBackend}});const a=r(790);Object.defineProperty(t,"OxyWalletBackend",{enumerable:!0,get:function(){return a.OxyWalletBackend}}),t.OxyBackend=class{constructor(e){this.auth=new n.OxyAuthBackend(e),this.users=new s.OxyUsersBackend(e),this.karma=new o.OxyKarmaBackend(e),this.wallet=new a.OxyWalletBackend(e)}}},475:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useAuth=void 0;const n=r(953),s=r(442),o=r(772);t.useAuth=e=>{const t=(0,o.useOxyContext)(),r=(null==e?void 0:e.apiUrl)||t.apiUrl;if(!r)throw new Error("API URL is required. Provide it either through options or OxyProvider.");const[a]=(0,n.useState)((()=>new s.ApiClient({apiUrl:r}))),[i,c]=(0,n.useState)(null),[u,l]=(0,n.useState)(!1),[d,h]=(0,n.useState)(null),f=(0,n.useCallback)((()=>(null==e?void 0:e.storage)?"local"===e.storage?localStorage.getItem("accessToken"):"session"===e.storage?sessionStorage.getItem("accessToken"):null:t.getToken()),[t,null==e?void 0:e.storage]),p=(0,n.useCallback)((r=>{const n=(null==e?void 0:e.storage)||"local";(null==e?void 0:e.storage)||!t.setAuthTokens?"local"===n?(localStorage.setItem("accessToken",r.accessToken),localStorage.setItem("refreshToken",r.refreshToken)):"session"===n&&(sessionStorage.setItem("accessToken",r.accessToken),sessionStorage.setItem("refreshToken",r.refreshToken)):t.setAuthTokens(r)}),[t,null==e?void 0:e.storage]),m=(0,n.useCallback)((()=>{const r=(null==e?void 0:e.storage)||"local";(null==e?void 0:e.storage)||!t.clearAuth?"local"===r?(localStorage.removeItem("accessToken"),localStorage.removeItem("refreshToken")):"session"===r&&(sessionStorage.removeItem("accessToken"),sessionStorage.removeItem("refreshToken")):t.clearAuth()}),[t,null==e?void 0:e.storage]),y=(0,n.useCallback)((async e=>{l(!0),h(null);try{const t=await a.request({method:"POST",url:"/auth/login",data:e});if(t.success&&t.data){p(t.data);const e=await a.request({method:"GET",url:"/auth/me",headers:{Authorization:`Bearer ${t.data.accessToken}`}});e.success&&e.data&&c(e.data)}else h(t.error||"Login failed");return l(!1),t}catch(e){return h(e.message||"Login failed"),l(!1),{success:!1,error:e.message||"Login failed"}}}),[a,p]),g=(0,n.useCallback)((async e=>{l(!0),h(null);try{const t=await a.request({method:"POST",url:"/auth/register",data:e});if(t.success&&t.data){p(t.data);const e=await a.request({method:"GET",url:"/auth/me",headers:{Authorization:`Bearer ${t.data.accessToken}`}});e.success&&e.data&&c(e.data)}else h(t.error||"Registration failed");return l(!1),t}catch(e){return h(e.message||"Registration failed"),l(!1),{success:!1,error:e.message||"Registration failed"}}}),[a,p]),b=(0,n.useCallback)((()=>{m(),c(null)}),[m]),w=(0,n.useCallback)((()=>!!f()),[f]),O=(0,n.useCallback)((async()=>{const e=f();if(!e)return{success:!1,error:"Not authenticated"};l(!0);try{const t=await a.request({method:"GET",url:"/auth/me",headers:{Authorization:`Bearer ${e}`}});return t.success&&t.data&&c(t.data),l(!1),t}catch(e){return l(!1),{success:!1,error:e.message||"Failed to get user profile"}}}),[a,f]),k=(0,n.useCallback)((async()=>{const t=(null==e?void 0:e.storage)||"local";let r=null;if("local"===t?r=localStorage.getItem("refreshToken"):"session"===t&&(r=sessionStorage.getItem("refreshToken")),!r)return{success:!1,error:"No refresh token available"};try{const e=await a.request({method:"POST",url:"/auth/refresh",data:{refreshToken:r}});return e.success&&e.data&&p(e.data),e}catch(e){return{success:!1,error:e.message||"Failed to refresh token"}}}),[a,null==e?void 0:e.storage,p]);return{user:i,loading:u,error:d,login:y,register:g,logout:b,isAuthenticated:w(),getCurrentUser:O,refreshToken:k,getToken:f}}},592:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useWallet=void 0;const n=r(953),s=r(442),o=r(772);t.useWallet=e=>{const t=(0,o.useOxyContext)(),r=(null==e?void 0:e.apiUrl)||t.apiUrl,a=(null==e?void 0:e.getToken)||t.getToken;if(!r)throw new Error("API URL is required. Provide it either through options or OxyProvider.");const[i]=(0,n.useState)((()=>new s.ApiClient({apiUrl:r})));return{getWallet:(0,n.useCallback)((async e=>{try{return a?await i.request({method:"GET",url:`/wallet/${e}`,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to get wallet information"}}}),[i,a]),getTransactionHistory:(0,n.useCallback)((async(e,t=10,r=0)=>{try{return a?await i.request({method:"GET",url:`/wallet/transactions/${e}`,params:{limit:t,offset:r},headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to get transaction history"}}}),[i,a]),transferFunds:(0,n.useCallback)((async e=>{try{return a?await i.request({method:"POST",url:"/wallet/transfer",data:e,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to transfer funds"}}}),[i,a]),processPurchase:(0,n.useCallback)((async e=>{try{return a?await i.request({method:"POST",url:"/wallet/purchase",data:e,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to process purchase"}}}),[i,a]),requestWithdrawal:(0,n.useCallback)((async e=>{try{return a?await i.request({method:"POST",url:"/wallet/withdraw",data:e,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to request withdrawal"}}}),[i,a]),getTransaction:(0,n.useCallback)((async e=>{try{return a?await i.request({method:"GET",url:`/wallet/transaction/${e}`,headers:{Authorization:`Bearer ${a()||""}`}}):{success:!1,error:"Authentication token is required"}}catch(e){return{success:!1,error:e.message||"Failed to get transaction"}}}),[i,a])}}},772:function(e,t,r){var n,s=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,s)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||(n=function(e){return n=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},n(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=n(e),a=0;a<r.length;a++)"default"!==r[a]&&s(t,e,r[a]);return o(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.OxyProvider=t.useOxyContext=void 0;const i=a(r(953)),c=(0,i.createContext)({apiUrl:"",getToken:()=>null,isAuthenticated:!1,setAuthTokens:()=>{},clearAuth:()=>{}});t.useOxyContext=()=>(0,i.useContext)(c),t.OxyProvider=({children:e,apiUrl:t,storage:r="local",tokenRefreshInterval:n})=>{const[s,o]=(0,i.useState)(!1);(0,i.useEffect)((()=>{const e=a();o(!!e)}),[]);const a=()=>"local"===r?localStorage.getItem("accessToken"):"session"===r?sessionStorage.getItem("accessToken"):null,u={apiUrl:t,getToken:a,isAuthenticated:s,setAuthTokens:e=>{"local"===r?(localStorage.setItem("accessToken",e.accessToken),localStorage.setItem("refreshToken",e.refreshToken)):"session"===r&&(sessionStorage.setItem("accessToken",e.accessToken),sessionStorage.setItem("refreshToken",e.refreshToken)),o(!0)},clearAuth:()=>{"local"===r?(localStorage.removeItem("accessToken"),localStorage.removeItem("refreshToken")):"session"===r&&(sessionStorage.removeItem("accessToken"),sessionStorage.removeItem("refreshToken")),o(!1)}};return i.default.createElement(c.Provider,{value:u},e)}},790:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OxyWalletBackend=void 0;const n=r(442);t.OxyWalletBackend=class{constructor(e){this.apiClient=new n.ApiClient({apiUrl:e})}async getWallet(e){return this.apiClient.request({method:"GET",url:`/wallet/${e}`})}async getTransactionHistory(e,t=10,r=0){return this.apiClient.request({method:"GET",url:`/wallet/transactions/${e}`,params:{limit:t,offset:r}})}async transferFunds(e){return this.apiClient.request({method:"POST",url:"/wallet/transfer",data:e})}async processPurchase(e){return this.apiClient.request({method:"POST",url:"/wallet/purchase",data:e})}async requestWithdrawal(e){return this.apiClient.request({method:"POST",url:"/wallet/withdraw",data:e})}async getTransaction(e){return this.apiClient.request({method:"GET",url:`/wallet/transaction/${e}`})}}},817:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},881:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useOxyContext=t.OxyProvider=t.useWallet=t.useKarma=t.useUser=t.useAuth=void 0;const n=r(475);Object.defineProperty(t,"useAuth",{enumerable:!0,get:function(){return n.useAuth}});const s=r(182);Object.defineProperty(t,"useUser",{enumerable:!0,get:function(){return s.useUser}});const o=r(317);Object.defineProperty(t,"useKarma",{enumerable:!0,get:function(){return o.useKarma}});const a=r(592);Object.defineProperty(t,"useWallet",{enumerable:!0,get:function(){return a.useWallet}});const i=r(772);Object.defineProperty(t,"OxyProvider",{enumerable:!0,get:function(){return i.OxyProvider}}),Object.defineProperty(t,"useOxyContext",{enumerable:!0,get:function(){return i.useOxyContext}})},947:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OxyKarmaBackend=void 0;const n=r(442);t.OxyKarmaBackend=class{constructor(e){this.apiClient=new n.ApiClient({apiUrl:e})}async getUserKarma(e){return this.apiClient.request({method:"GET",url:`/karma/${e}/total`})}async getUserKarmaHistory(e,t,r){const n={};return void 0!==t&&(n.limit=t.toString()),void 0!==r&&(n.offset=r.toString()),this.apiClient.request({method:"GET",url:`/karma/${e}/history`,params:n})}async awardKarma(e){return this.apiClient.request({method:"POST",url:"/karma/award",data:e})}async deductKarma(e){return this.apiClient.request({method:"POST",url:"/karma/deduct",data:e})}async getKarmaLeaderboard(e=10,t=0){return this.apiClient.request({method:"GET",url:"/karma/leaderboard",params:{limit:e,offset:t}})}async getKarmaRules(){return this.apiClient.request({method:"GET",url:"/karma/rules"})}async createOrUpdateKarmaRule(e){return this.apiClient.request({method:"POST",url:"/karma/rules",data:e})}}},953:e=>{e.exports=require("react")}},t={};function r(n){var s=t[n];if(void 0!==s)return s.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}();var n=r(156);module.exports=n})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! Axios v1.8.3 Copyright (c) 2025 Matt Zabriskie and contributors */
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
interface OxyContextType {
|
|
3
|
+
apiUrl: string;
|
|
4
|
+
getToken: () => string | null;
|
|
5
|
+
isAuthenticated: boolean;
|
|
6
|
+
setAuthTokens: (tokens: {
|
|
7
|
+
accessToken: string;
|
|
8
|
+
refreshToken: string;
|
|
9
|
+
}) => void;
|
|
10
|
+
clearAuth: () => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const useOxyContext: () => OxyContextType;
|
|
13
|
+
interface OxyProviderProps {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
apiUrl: string;
|
|
16
|
+
storage?: 'local' | 'session' | 'cookie' | 'none';
|
|
17
|
+
tokenRefreshInterval?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const OxyProvider: React.FC<OxyProviderProps>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.OxyProvider = exports.useOxyContext = void 0;
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const defaultContext = {
|
|
39
|
+
apiUrl: '',
|
|
40
|
+
getToken: () => null,
|
|
41
|
+
isAuthenticated: false,
|
|
42
|
+
setAuthTokens: () => { },
|
|
43
|
+
clearAuth: () => { }
|
|
44
|
+
};
|
|
45
|
+
const OxyContext = (0, react_1.createContext)(defaultContext);
|
|
46
|
+
const useOxyContext = () => (0, react_1.useContext)(OxyContext);
|
|
47
|
+
exports.useOxyContext = useOxyContext;
|
|
48
|
+
const OxyProvider = ({ children, apiUrl, storage = 'local', tokenRefreshInterval }) => {
|
|
49
|
+
const [isAuthenticated, setIsAuthenticated] = (0, react_1.useState)(false);
|
|
50
|
+
// Check for existing tokens on mount
|
|
51
|
+
(0, react_1.useEffect)(() => {
|
|
52
|
+
const token = getToken();
|
|
53
|
+
setIsAuthenticated(!!token);
|
|
54
|
+
}, []);
|
|
55
|
+
const setAuthTokens = (tokens) => {
|
|
56
|
+
if (storage === 'local') {
|
|
57
|
+
localStorage.setItem('accessToken', tokens.accessToken);
|
|
58
|
+
localStorage.setItem('refreshToken', tokens.refreshToken);
|
|
59
|
+
}
|
|
60
|
+
else if (storage === 'session') {
|
|
61
|
+
sessionStorage.setItem('accessToken', tokens.accessToken);
|
|
62
|
+
sessionStorage.setItem('refreshToken', tokens.refreshToken);
|
|
63
|
+
}
|
|
64
|
+
// Note: Cookie storage would need to be handled differently
|
|
65
|
+
// We're not implementing cookie storage in this example
|
|
66
|
+
setIsAuthenticated(true);
|
|
67
|
+
};
|
|
68
|
+
const clearAuth = () => {
|
|
69
|
+
if (storage === 'local') {
|
|
70
|
+
localStorage.removeItem('accessToken');
|
|
71
|
+
localStorage.removeItem('refreshToken');
|
|
72
|
+
}
|
|
73
|
+
else if (storage === 'session') {
|
|
74
|
+
sessionStorage.removeItem('accessToken');
|
|
75
|
+
sessionStorage.removeItem('refreshToken');
|
|
76
|
+
}
|
|
77
|
+
setIsAuthenticated(false);
|
|
78
|
+
};
|
|
79
|
+
const getToken = () => {
|
|
80
|
+
if (storage === 'local') {
|
|
81
|
+
return localStorage.getItem('accessToken');
|
|
82
|
+
}
|
|
83
|
+
else if (storage === 'session') {
|
|
84
|
+
return sessionStorage.getItem('accessToken');
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
};
|
|
88
|
+
const contextValue = {
|
|
89
|
+
apiUrl,
|
|
90
|
+
getToken,
|
|
91
|
+
isAuthenticated,
|
|
92
|
+
setAuthTokens,
|
|
93
|
+
clearAuth
|
|
94
|
+
};
|
|
95
|
+
return (react_1.default.createElement(OxyContext.Provider, { value: contextValue }, children));
|
|
96
|
+
};
|
|
97
|
+
exports.OxyProvider = OxyProvider;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ApiResponse, AuthTokens, UserCredentials, UserRegistration, UserProfile } from '../../shared/types';
|
|
2
|
+
interface UseAuthOptions {
|
|
3
|
+
apiUrl?: string;
|
|
4
|
+
storage?: 'local' | 'session' | 'cookie' | 'none';
|
|
5
|
+
tokenRefreshInterval?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const useAuth: (options?: UseAuthOptions) => {
|
|
8
|
+
user: UserProfile | null;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
error: string | null;
|
|
11
|
+
login: (credentials: UserCredentials) => Promise<ApiResponse<AuthTokens>>;
|
|
12
|
+
register: (userData: UserRegistration) => Promise<ApiResponse<AuthTokens>>;
|
|
13
|
+
logout: () => void;
|
|
14
|
+
isAuthenticated: boolean;
|
|
15
|
+
getCurrentUser: () => Promise<ApiResponse<UserProfile>>;
|
|
16
|
+
refreshToken: () => Promise<ApiResponse<AuthTokens>>;
|
|
17
|
+
getToken: () => string | null;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAuth = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const api_client_1 = require("../../shared/api-client");
|
|
6
|
+
const OxyContext_1 = require("../context/OxyContext");
|
|
7
|
+
const useAuth = (options) => {
|
|
8
|
+
const context = (0, OxyContext_1.useOxyContext)();
|
|
9
|
+
const apiUrl = (options === null || options === void 0 ? void 0 : options.apiUrl) || context.apiUrl;
|
|
10
|
+
if (!apiUrl) {
|
|
11
|
+
throw new Error('API URL is required. Provide it either through options or OxyProvider.');
|
|
12
|
+
}
|
|
13
|
+
const [apiClient] = (0, react_1.useState)(() => new api_client_1.ApiClient({
|
|
14
|
+
apiUrl,
|
|
15
|
+
}));
|
|
16
|
+
const [user, setUser] = (0, react_1.useState)(null);
|
|
17
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
18
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
19
|
+
// Use the token getter from context or implement it locally based on options
|
|
20
|
+
const getToken = (0, react_1.useCallback)(() => {
|
|
21
|
+
// If we're using the context for auth
|
|
22
|
+
if (!(options === null || options === void 0 ? void 0 : options.storage)) {
|
|
23
|
+
return context.getToken();
|
|
24
|
+
}
|
|
25
|
+
// Otherwise use the storage option provided in options
|
|
26
|
+
if (options.storage === 'local') {
|
|
27
|
+
return localStorage.getItem('accessToken');
|
|
28
|
+
}
|
|
29
|
+
else if (options.storage === 'session') {
|
|
30
|
+
return sessionStorage.getItem('accessToken');
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}, [context, options === null || options === void 0 ? void 0 : options.storage]);
|
|
34
|
+
// Set tokens in storage and context if available
|
|
35
|
+
const setTokens = (0, react_1.useCallback)((tokens) => {
|
|
36
|
+
const storage = (options === null || options === void 0 ? void 0 : options.storage) || 'local';
|
|
37
|
+
// If we're using the context for auth
|
|
38
|
+
if (!(options === null || options === void 0 ? void 0 : options.storage) && context.setAuthTokens) {
|
|
39
|
+
context.setAuthTokens(tokens);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (storage === 'local') {
|
|
43
|
+
localStorage.setItem('accessToken', tokens.accessToken);
|
|
44
|
+
localStorage.setItem('refreshToken', tokens.refreshToken);
|
|
45
|
+
}
|
|
46
|
+
else if (storage === 'session') {
|
|
47
|
+
sessionStorage.setItem('accessToken', tokens.accessToken);
|
|
48
|
+
sessionStorage.setItem('refreshToken', tokens.refreshToken);
|
|
49
|
+
}
|
|
50
|
+
}, [context, options === null || options === void 0 ? void 0 : options.storage]);
|
|
51
|
+
// Clear tokens from storage and context if available
|
|
52
|
+
const clearTokens = (0, react_1.useCallback)(() => {
|
|
53
|
+
const storage = (options === null || options === void 0 ? void 0 : options.storage) || 'local';
|
|
54
|
+
// If we're using the context for auth
|
|
55
|
+
if (!(options === null || options === void 0 ? void 0 : options.storage) && context.clearAuth) {
|
|
56
|
+
context.clearAuth();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (storage === 'local') {
|
|
60
|
+
localStorage.removeItem('accessToken');
|
|
61
|
+
localStorage.removeItem('refreshToken');
|
|
62
|
+
}
|
|
63
|
+
else if (storage === 'session') {
|
|
64
|
+
sessionStorage.removeItem('accessToken');
|
|
65
|
+
sessionStorage.removeItem('refreshToken');
|
|
66
|
+
}
|
|
67
|
+
}, [context, options === null || options === void 0 ? void 0 : options.storage]);
|
|
68
|
+
// Login a user with credentials
|
|
69
|
+
const login = (0, react_1.useCallback)(async (credentials) => {
|
|
70
|
+
setLoading(true);
|
|
71
|
+
setError(null);
|
|
72
|
+
try {
|
|
73
|
+
const response = await apiClient.request({
|
|
74
|
+
method: 'POST',
|
|
75
|
+
url: '/auth/login',
|
|
76
|
+
data: credentials
|
|
77
|
+
});
|
|
78
|
+
if (response.success && response.data) {
|
|
79
|
+
setTokens(response.data);
|
|
80
|
+
// Get user profile after successful login
|
|
81
|
+
const userResponse = await apiClient.request({
|
|
82
|
+
method: 'GET',
|
|
83
|
+
url: '/auth/me',
|
|
84
|
+
headers: {
|
|
85
|
+
Authorization: `Bearer ${response.data.accessToken}`
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
if (userResponse.success && userResponse.data) {
|
|
89
|
+
setUser(userResponse.data);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
setError(response.error || 'Login failed');
|
|
94
|
+
}
|
|
95
|
+
setLoading(false);
|
|
96
|
+
return response;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
setError(error.message || 'Login failed');
|
|
100
|
+
setLoading(false);
|
|
101
|
+
return {
|
|
102
|
+
success: false,
|
|
103
|
+
error: error.message || 'Login failed'
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}, [apiClient, setTokens]);
|
|
107
|
+
// Register a new user
|
|
108
|
+
const register = (0, react_1.useCallback)(async (userData) => {
|
|
109
|
+
setLoading(true);
|
|
110
|
+
setError(null);
|
|
111
|
+
try {
|
|
112
|
+
const response = await apiClient.request({
|
|
113
|
+
method: 'POST',
|
|
114
|
+
url: '/auth/register',
|
|
115
|
+
data: userData
|
|
116
|
+
});
|
|
117
|
+
if (response.success && response.data) {
|
|
118
|
+
setTokens(response.data);
|
|
119
|
+
// Get user profile after successful registration
|
|
120
|
+
const userResponse = await apiClient.request({
|
|
121
|
+
method: 'GET',
|
|
122
|
+
url: '/auth/me',
|
|
123
|
+
headers: {
|
|
124
|
+
Authorization: `Bearer ${response.data.accessToken}`
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
if (userResponse.success && userResponse.data) {
|
|
128
|
+
setUser(userResponse.data);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
setError(response.error || 'Registration failed');
|
|
133
|
+
}
|
|
134
|
+
setLoading(false);
|
|
135
|
+
return response;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
setError(error.message || 'Registration failed');
|
|
139
|
+
setLoading(false);
|
|
140
|
+
return {
|
|
141
|
+
success: false,
|
|
142
|
+
error: error.message || 'Registration failed'
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}, [apiClient, setTokens]);
|
|
146
|
+
// Logout the current user
|
|
147
|
+
const logout = (0, react_1.useCallback)(() => {
|
|
148
|
+
clearTokens();
|
|
149
|
+
setUser(null);
|
|
150
|
+
}, [clearTokens]);
|
|
151
|
+
// Check if the user is authenticated
|
|
152
|
+
const isAuthenticated = (0, react_1.useCallback)(() => {
|
|
153
|
+
return !!getToken();
|
|
154
|
+
}, [getToken]);
|
|
155
|
+
// Get the current user's profile
|
|
156
|
+
const getCurrentUser = (0, react_1.useCallback)(async () => {
|
|
157
|
+
const token = getToken();
|
|
158
|
+
if (!token) {
|
|
159
|
+
return {
|
|
160
|
+
success: false,
|
|
161
|
+
error: 'Not authenticated'
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
setLoading(true);
|
|
165
|
+
try {
|
|
166
|
+
const response = await apiClient.request({
|
|
167
|
+
method: 'GET',
|
|
168
|
+
url: '/auth/me',
|
|
169
|
+
headers: {
|
|
170
|
+
Authorization: `Bearer ${token}`
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
if (response.success && response.data) {
|
|
174
|
+
setUser(response.data);
|
|
175
|
+
}
|
|
176
|
+
setLoading(false);
|
|
177
|
+
return response;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
setLoading(false);
|
|
181
|
+
return {
|
|
182
|
+
success: false,
|
|
183
|
+
error: error.message || 'Failed to get user profile'
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}, [apiClient, getToken]);
|
|
187
|
+
// Refresh the access token using the refresh token
|
|
188
|
+
const refreshToken = (0, react_1.useCallback)(async () => {
|
|
189
|
+
const storage = (options === null || options === void 0 ? void 0 : options.storage) || 'local';
|
|
190
|
+
let refreshToken = null;
|
|
191
|
+
if (storage === 'local') {
|
|
192
|
+
refreshToken = localStorage.getItem('refreshToken');
|
|
193
|
+
}
|
|
194
|
+
else if (storage === 'session') {
|
|
195
|
+
refreshToken = sessionStorage.getItem('refreshToken');
|
|
196
|
+
}
|
|
197
|
+
if (!refreshToken) {
|
|
198
|
+
return {
|
|
199
|
+
success: false,
|
|
200
|
+
error: 'No refresh token available'
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const response = await apiClient.request({
|
|
205
|
+
method: 'POST',
|
|
206
|
+
url: '/auth/refresh',
|
|
207
|
+
data: { refreshToken }
|
|
208
|
+
});
|
|
209
|
+
if (response.success && response.data) {
|
|
210
|
+
setTokens(response.data);
|
|
211
|
+
}
|
|
212
|
+
return response;
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
return {
|
|
216
|
+
success: false,
|
|
217
|
+
error: error.message || 'Failed to refresh token'
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}, [apiClient, options === null || options === void 0 ? void 0 : options.storage, setTokens]);
|
|
221
|
+
return {
|
|
222
|
+
user,
|
|
223
|
+
loading,
|
|
224
|
+
error,
|
|
225
|
+
login,
|
|
226
|
+
register,
|
|
227
|
+
logout,
|
|
228
|
+
isAuthenticated: isAuthenticated(),
|
|
229
|
+
getCurrentUser,
|
|
230
|
+
refreshToken,
|
|
231
|
+
getToken
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
exports.useAuth = useAuth;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ApiResponse, KarmaAction, KarmaHistory, KarmaRule } from '../../shared/types';
|
|
2
|
+
interface UseKarmaOptions {
|
|
3
|
+
apiUrl?: string;
|
|
4
|
+
getToken?: () => string | null;
|
|
5
|
+
}
|
|
6
|
+
export declare const useKarma: (options?: UseKarmaOptions) => {
|
|
7
|
+
getUserKarma: (userId: string) => Promise<ApiResponse<{
|
|
8
|
+
karma: number;
|
|
9
|
+
}>>;
|
|
10
|
+
getUserKarmaHistory: (userId: string, limit?: number, offset?: number) => Promise<ApiResponse<KarmaHistory>>;
|
|
11
|
+
awardKarma: (karmaAction: KarmaAction) => Promise<ApiResponse<{
|
|
12
|
+
success: boolean;
|
|
13
|
+
newTotal: number;
|
|
14
|
+
}>>;
|
|
15
|
+
deductKarma: (karmaAction: KarmaAction) => Promise<ApiResponse<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
newTotal: number;
|
|
18
|
+
}>>;
|
|
19
|
+
getKarmaLeaderboard: (limit?: number, offset?: number) => Promise<ApiResponse<Array<{
|
|
20
|
+
userId: string;
|
|
21
|
+
username: string;
|
|
22
|
+
karma: number;
|
|
23
|
+
}>>>;
|
|
24
|
+
getKarmaRules: () => Promise<ApiResponse<KarmaRule[]>>;
|
|
25
|
+
createOrUpdateKarmaRule: (rule: KarmaRule) => Promise<ApiResponse<KarmaRule>>;
|
|
26
|
+
};
|
|
27
|
+
export {};
|