@explorins/pers-sdk-react-native 2.3.6 → 2.3.8
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/LICENSE +21 -0
- package/README.md +1266 -1244
- package/dist/__tests__/PersSDKProvider.test.js +33 -0
- package/dist/hooks/useBusiness.d.ts +2 -2
- package/dist/hooks/useBusiness.d.ts.map +1 -1
- package/dist/hooks/useBusiness.js +2 -2
- package/dist/hooks/useIPFSUrl.d.ts +3 -3
- package/dist/hooks/useIPFSUrl.d.ts.map +1 -1
- package/dist/hooks/useIPFSUrl.js +7 -7
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +13 -5
- package/dist/hooks/useWeb3.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2412 -492
- package/dist/index.js.map +1 -1
- package/dist/providers/PersSDKProvider.d.ts +4 -0
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +14 -0
- package/dist/providers/react-native-http-client.d.ts +2 -0
- package/dist/providers/react-native-http-client.d.ts.map +1 -1
- package/dist/providers/react-native-http-client.js +5 -2
- package/dist/storage/rn-secure-storage.d.ts.map +1 -1
- package/dist/storage/rn-secure-storage.js +21 -8
- package/package.json +3 -3
- package/src/__tests__/PersSDKProvider.test.tsx +484 -420
- package/src/__tests__/setup.ts +40 -40
- package/src/hooks/index.ts +60 -60
- package/src/hooks/useAnalytics.ts +327 -327
- package/src/hooks/useAuth.ts +265 -265
- package/src/hooks/useBookings.ts +191 -191
- package/src/hooks/useBusiness.ts +251 -251
- package/src/hooks/useCampaigns.ts +500 -500
- package/src/hooks/useDonations.ts +66 -66
- package/src/hooks/useEvents.ts +372 -372
- package/src/hooks/useFiles.ts +155 -155
- package/src/hooks/useIPFSUrl.ts +192 -192
- package/src/hooks/usePurchases.ts +65 -65
- package/src/hooks/useRedemptions.ts +467 -467
- package/src/hooks/useTenants.ts +72 -72
- package/src/hooks/useTokenBalances.ts +385 -385
- package/src/hooks/useTokens.ts +313 -313
- package/src/hooks/useTransactionSigner.ts +611 -611
- package/src/hooks/useTransactions.ts +299 -290
- package/src/hooks/useTriggerSources.ts +301 -301
- package/src/hooks/useUserStatus.ts +61 -61
- package/src/hooks/useUsers.ts +167 -167
- package/src/hooks/useWeb3.ts +355 -355
- package/src/index.ts +777 -774
- package/src/polyfills/index.ts +160 -160
- package/src/polyfills/web3-polyfills.ts +97 -97
- package/src/providers/PersSDKProvider.tsx +393 -374
- package/src/providers/react-native-auth-provider.ts +110 -110
- package/src/providers/react-native-http-client.ts +150 -145
- package/src/providers/rn-dpop-provider.ts +190 -190
- package/src/storage/async-storage-token-storage.ts +185 -185
- package/src/storage/rn-secure-storage.ts +182 -170
- package/src/types/react-native-globals.d.ts +45 -45
- package/src/utils/index.ts +8 -8
- package/src/utils/platform-detection.ts +86 -86
- package/dist/index-CzLxqePZ.js +0 -7717
- package/dist/index-CzLxqePZ.js.map +0 -1
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import type { UserStatusTypeDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
|
-
|
|
5
|
-
export const useUserStatus = () => {
|
|
6
|
-
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
7
|
-
|
|
8
|
-
const getUserStatusTypes = useCallback(async (): Promise<PaginatedResponseDTO<UserStatusTypeDTO>> => {
|
|
9
|
-
if (!isInitialized || !sdk) {
|
|
10
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const result = await sdk.userStatus.getUserStatusTypes();
|
|
15
|
-
return result;
|
|
16
|
-
} catch (error) {
|
|
17
|
-
console.error('Failed to fetch user status types:', error);
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
}, [sdk, isInitialized]);
|
|
21
|
-
|
|
22
|
-
const getEarnedUserStatus = useCallback(async (): Promise<PaginatedResponseDTO<UserStatusTypeDTO>> => {
|
|
23
|
-
if (!isInitialized || !sdk) {
|
|
24
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
25
|
-
}
|
|
26
|
-
if (!isAuthenticated) {
|
|
27
|
-
throw new Error('SDK not authenticated. getEarnedUserStatus requires authentication.');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
const result = await sdk.userStatus.getEarnedUserStatus();
|
|
32
|
-
return result;
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error('Failed to fetch earned user status:', error);
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
}, [sdk, isInitialized, isAuthenticated]);
|
|
38
|
-
|
|
39
|
-
// Admin methods
|
|
40
|
-
const createUserStatusType = useCallback(async (userStatusType: UserStatusTypeDTO): Promise<UserStatusTypeDTO> => {
|
|
41
|
-
if (!isInitialized || !sdk) {
|
|
42
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
const result = await sdk.userStatus.createUserStatusType(userStatusType);
|
|
47
|
-
return result;
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error('Failed to create user status type:', error);
|
|
50
|
-
throw error;
|
|
51
|
-
}
|
|
52
|
-
}, [sdk, isInitialized]);
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
getUserStatusTypes,
|
|
56
|
-
getEarnedUserStatus,
|
|
57
|
-
createUserStatusType,
|
|
58
|
-
isAvailable: isInitialized && !!sdk?.userStatus,
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
+
import type { UserStatusTypeDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
|
+
|
|
5
|
+
export const useUserStatus = () => {
|
|
6
|
+
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
7
|
+
|
|
8
|
+
const getUserStatusTypes = useCallback(async (): Promise<PaginatedResponseDTO<UserStatusTypeDTO>> => {
|
|
9
|
+
if (!isInitialized || !sdk) {
|
|
10
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const result = await sdk.userStatus.getUserStatusTypes();
|
|
15
|
+
return result;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error('Failed to fetch user status types:', error);
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}, [sdk, isInitialized]);
|
|
21
|
+
|
|
22
|
+
const getEarnedUserStatus = useCallback(async (): Promise<PaginatedResponseDTO<UserStatusTypeDTO>> => {
|
|
23
|
+
if (!isInitialized || !sdk) {
|
|
24
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
25
|
+
}
|
|
26
|
+
if (!isAuthenticated) {
|
|
27
|
+
throw new Error('SDK not authenticated. getEarnedUserStatus requires authentication.');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const result = await sdk.userStatus.getEarnedUserStatus();
|
|
32
|
+
return result;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('Failed to fetch earned user status:', error);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}, [sdk, isInitialized, isAuthenticated]);
|
|
38
|
+
|
|
39
|
+
// Admin methods
|
|
40
|
+
const createUserStatusType = useCallback(async (userStatusType: UserStatusTypeDTO): Promise<UserStatusTypeDTO> => {
|
|
41
|
+
if (!isInitialized || !sdk) {
|
|
42
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const result = await sdk.userStatus.createUserStatusType(userStatusType);
|
|
47
|
+
return result;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error('Failed to create user status type:', error);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}, [sdk, isInitialized]);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
getUserStatusTypes,
|
|
56
|
+
getEarnedUserStatus,
|
|
57
|
+
createUserStatusType,
|
|
58
|
+
isAvailable: isInitialized && !!sdk?.userStatus,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
62
|
export type UserStatusHook = ReturnType<typeof useUserStatus>;
|
package/src/hooks/useUsers.ts
CHANGED
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import type { UserDTO, UserCreateRequestDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
|
-
import type { UserPublicProfileDTO, UserQueryOptions } from '@explorins/pers-sdk/user';
|
|
5
|
-
|
|
6
|
-
// Re-export for consumers
|
|
7
|
-
export type { UserQueryOptions } from '@explorins/pers-sdk/user';
|
|
8
|
-
|
|
9
|
-
export const useUsers = () => {
|
|
10
|
-
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Get the current authenticated user with optional include relations
|
|
14
|
-
*
|
|
15
|
-
* @param options - Query options including include relations
|
|
16
|
-
* @returns Current user data
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // Basic
|
|
21
|
-
* const user = await getCurrentUser();
|
|
22
|
-
*
|
|
23
|
-
* // With wallets included
|
|
24
|
-
* const userWithWallets = await getCurrentUser({ include: ['wallets'] });
|
|
25
|
-
* console.log('Wallets:', userWithWallets.included?.wallets);
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
const getCurrentUser = useCallback(async (options?: UserQueryOptions): Promise<UserDTO> => {
|
|
29
|
-
if (!isInitialized || !sdk) {
|
|
30
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
31
|
-
}
|
|
32
|
-
if (!isAuthenticated) {
|
|
33
|
-
throw new Error('SDK not authenticated. getCurrentUser requires authentication.');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
const result = await sdk.users.getCurrentUser(options);
|
|
38
|
-
return result;
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.error('Failed to fetch current user:', error);
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
}, [sdk, isInitialized, isAuthenticated]);
|
|
44
|
-
|
|
45
|
-
const updateCurrentUser = useCallback(async (userData: UserCreateRequestDTO): Promise<UserDTO> => {
|
|
46
|
-
if (!isInitialized || !sdk) {
|
|
47
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
48
|
-
}
|
|
49
|
-
if (!isAuthenticated) {
|
|
50
|
-
throw new Error('SDK not authenticated. updateCurrentUser requires authentication.');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
const result = await sdk.users.updateCurrentUser(userData);
|
|
55
|
-
return result;
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error('Failed to update current user:', error);
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
}, [sdk, isInitialized, isAuthenticated]);
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Get user by ID with optional include relations
|
|
64
|
-
*
|
|
65
|
-
* @param userId - User identifier (id, email, externalId, etc.)
|
|
66
|
-
* @param options - Query options including include relations
|
|
67
|
-
* @returns User data
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* // Basic
|
|
72
|
-
* const user = await getUserById('user-123');
|
|
73
|
-
*
|
|
74
|
-
* // With wallets included
|
|
75
|
-
* const userWithWallets = await getUserById('user-123', { include: ['wallets'] });
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
const getUserById = useCallback(async (userId: string, options?: UserQueryOptions): Promise<UserDTO> => {
|
|
79
|
-
if (!isInitialized || !sdk) {
|
|
80
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
const result = await sdk.users.getUserById(userId, options);
|
|
85
|
-
return result;
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error('Failed to fetch user:', error);
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
}, [sdk, isInitialized]);
|
|
91
|
-
|
|
92
|
-
const getAllUsersPublic = useCallback(async (filter?: { key: string; value: string }): Promise<PaginatedResponseDTO<UserPublicProfileDTO>> => {
|
|
93
|
-
if (!isInitialized || !sdk) {
|
|
94
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
const result = await sdk.users.getAllUsersPublic(filter);
|
|
99
|
-
return result;
|
|
100
|
-
} catch (error) {
|
|
101
|
-
console.error('Failed to fetch public users:', error);
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
}, [sdk, isInitialized]);
|
|
105
|
-
|
|
106
|
-
// Admin methods
|
|
107
|
-
const getAllUsers = useCallback(async (): Promise<PaginatedResponseDTO<UserDTO>> => {
|
|
108
|
-
if (!isInitialized || !sdk) {
|
|
109
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
const result = await sdk.users.getAllUsers();
|
|
114
|
-
return result;
|
|
115
|
-
} catch (error) {
|
|
116
|
-
console.error('Failed to fetch all users:', error);
|
|
117
|
-
throw error;
|
|
118
|
-
}
|
|
119
|
-
}, [sdk, isInitialized]);
|
|
120
|
-
|
|
121
|
-
const updateUser = useCallback(async (userId: string, userData: UserCreateRequestDTO): Promise<UserDTO> => {
|
|
122
|
-
if (!isInitialized || !sdk) {
|
|
123
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
const result = await sdk.users.updateUser(userId, userData);
|
|
128
|
-
return result;
|
|
129
|
-
} catch (error) {
|
|
130
|
-
console.error('Failed to update user:', error);
|
|
131
|
-
throw error;
|
|
132
|
-
}
|
|
133
|
-
}, [sdk, isInitialized]);
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Toggle or set a user's active status (admin only)
|
|
137
|
-
*
|
|
138
|
-
* @param userId - User ID to update
|
|
139
|
-
* @param isActive - Optional explicit status. If omitted, toggles current status.
|
|
140
|
-
* @returns Updated user
|
|
141
|
-
*/
|
|
142
|
-
const setUserActiveStatus = useCallback(async (userId: string, isActive?: boolean): Promise<UserDTO> => {
|
|
143
|
-
if (!isInitialized || !sdk) {
|
|
144
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
try {
|
|
148
|
-
const result = await sdk.users.setUserActiveStatus(userId, isActive);
|
|
149
|
-
return result;
|
|
150
|
-
} catch (error) {
|
|
151
|
-
console.error('Failed to set user active status:', error);
|
|
152
|
-
throw error;
|
|
153
|
-
}
|
|
154
|
-
}, [sdk, isInitialized]);
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
getCurrentUser,
|
|
158
|
-
updateCurrentUser,
|
|
159
|
-
getUserById,
|
|
160
|
-
getAllUsersPublic,
|
|
161
|
-
getAllUsers,
|
|
162
|
-
updateUser,
|
|
163
|
-
setUserActiveStatus,
|
|
164
|
-
isAvailable: isInitialized && !!sdk?.users,
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
+
import type { UserDTO, UserCreateRequestDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
|
+
import type { UserPublicProfileDTO, UserQueryOptions } from '@explorins/pers-sdk/user';
|
|
5
|
+
|
|
6
|
+
// Re-export for consumers
|
|
7
|
+
export type { UserQueryOptions } from '@explorins/pers-sdk/user';
|
|
8
|
+
|
|
9
|
+
export const useUsers = () => {
|
|
10
|
+
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Get the current authenticated user with optional include relations
|
|
14
|
+
*
|
|
15
|
+
* @param options - Query options including include relations
|
|
16
|
+
* @returns Current user data
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Basic
|
|
21
|
+
* const user = await getCurrentUser();
|
|
22
|
+
*
|
|
23
|
+
* // With wallets included
|
|
24
|
+
* const userWithWallets = await getCurrentUser({ include: ['wallets'] });
|
|
25
|
+
* console.log('Wallets:', userWithWallets.included?.wallets);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const getCurrentUser = useCallback(async (options?: UserQueryOptions): Promise<UserDTO> => {
|
|
29
|
+
if (!isInitialized || !sdk) {
|
|
30
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
31
|
+
}
|
|
32
|
+
if (!isAuthenticated) {
|
|
33
|
+
throw new Error('SDK not authenticated. getCurrentUser requires authentication.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const result = await sdk.users.getCurrentUser(options);
|
|
38
|
+
return result;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Failed to fetch current user:', error);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}, [sdk, isInitialized, isAuthenticated]);
|
|
44
|
+
|
|
45
|
+
const updateCurrentUser = useCallback(async (userData: UserCreateRequestDTO): Promise<UserDTO> => {
|
|
46
|
+
if (!isInitialized || !sdk) {
|
|
47
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
48
|
+
}
|
|
49
|
+
if (!isAuthenticated) {
|
|
50
|
+
throw new Error('SDK not authenticated. updateCurrentUser requires authentication.');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const result = await sdk.users.updateCurrentUser(userData);
|
|
55
|
+
return result;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('Failed to update current user:', error);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}, [sdk, isInitialized, isAuthenticated]);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get user by ID with optional include relations
|
|
64
|
+
*
|
|
65
|
+
* @param userId - User identifier (id, email, externalId, etc.)
|
|
66
|
+
* @param options - Query options including include relations
|
|
67
|
+
* @returns User data
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // Basic
|
|
72
|
+
* const user = await getUserById('user-123');
|
|
73
|
+
*
|
|
74
|
+
* // With wallets included
|
|
75
|
+
* const userWithWallets = await getUserById('user-123', { include: ['wallets'] });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
const getUserById = useCallback(async (userId: string, options?: UserQueryOptions): Promise<UserDTO> => {
|
|
79
|
+
if (!isInitialized || !sdk) {
|
|
80
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const result = await sdk.users.getUserById(userId, options);
|
|
85
|
+
return result;
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('Failed to fetch user:', error);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}, [sdk, isInitialized]);
|
|
91
|
+
|
|
92
|
+
const getAllUsersPublic = useCallback(async (filter?: { key: string; value: string }): Promise<PaginatedResponseDTO<UserPublicProfileDTO>> => {
|
|
93
|
+
if (!isInitialized || !sdk) {
|
|
94
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const result = await sdk.users.getAllUsersPublic(filter);
|
|
99
|
+
return result;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error('Failed to fetch public users:', error);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}, [sdk, isInitialized]);
|
|
105
|
+
|
|
106
|
+
// Admin methods
|
|
107
|
+
const getAllUsers = useCallback(async (): Promise<PaginatedResponseDTO<UserDTO>> => {
|
|
108
|
+
if (!isInitialized || !sdk) {
|
|
109
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const result = await sdk.users.getAllUsers();
|
|
114
|
+
return result;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error('Failed to fetch all users:', error);
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}, [sdk, isInitialized]);
|
|
120
|
+
|
|
121
|
+
const updateUser = useCallback(async (userId: string, userData: UserCreateRequestDTO): Promise<UserDTO> => {
|
|
122
|
+
if (!isInitialized || !sdk) {
|
|
123
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const result = await sdk.users.updateUser(userId, userData);
|
|
128
|
+
return result;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Failed to update user:', error);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}, [sdk, isInitialized]);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Toggle or set a user's active status (admin only)
|
|
137
|
+
*
|
|
138
|
+
* @param userId - User ID to update
|
|
139
|
+
* @param isActive - Optional explicit status. If omitted, toggles current status.
|
|
140
|
+
* @returns Updated user
|
|
141
|
+
*/
|
|
142
|
+
const setUserActiveStatus = useCallback(async (userId: string, isActive?: boolean): Promise<UserDTO> => {
|
|
143
|
+
if (!isInitialized || !sdk) {
|
|
144
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const result = await sdk.users.setUserActiveStatus(userId, isActive);
|
|
149
|
+
return result;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error('Failed to set user active status:', error);
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}, [sdk, isInitialized]);
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
getCurrentUser,
|
|
158
|
+
updateCurrentUser,
|
|
159
|
+
getUserById,
|
|
160
|
+
getAllUsersPublic,
|
|
161
|
+
getAllUsers,
|
|
162
|
+
updateUser,
|
|
163
|
+
setUserActiveStatus,
|
|
164
|
+
isAvailable: isInitialized && !!sdk?.users,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
168
|
export type UserHook = ReturnType<typeof useUsers>;
|