@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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1266 -1244
  3. package/dist/__tests__/PersSDKProvider.test.js +33 -0
  4. package/dist/hooks/useBusiness.d.ts +2 -2
  5. package/dist/hooks/useBusiness.d.ts.map +1 -1
  6. package/dist/hooks/useBusiness.js +2 -2
  7. package/dist/hooks/useIPFSUrl.d.ts +3 -3
  8. package/dist/hooks/useIPFSUrl.d.ts.map +1 -1
  9. package/dist/hooks/useIPFSUrl.js +7 -7
  10. package/dist/hooks/useTransactions.d.ts.map +1 -1
  11. package/dist/hooks/useTransactions.js +13 -5
  12. package/dist/hooks/useWeb3.js +4 -4
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2412 -492
  16. package/dist/index.js.map +1 -1
  17. package/dist/providers/PersSDKProvider.d.ts +4 -0
  18. package/dist/providers/PersSDKProvider.d.ts.map +1 -1
  19. package/dist/providers/PersSDKProvider.js +14 -0
  20. package/dist/providers/react-native-http-client.d.ts +2 -0
  21. package/dist/providers/react-native-http-client.d.ts.map +1 -1
  22. package/dist/providers/react-native-http-client.js +5 -2
  23. package/dist/storage/rn-secure-storage.d.ts.map +1 -1
  24. package/dist/storage/rn-secure-storage.js +21 -8
  25. package/package.json +3 -3
  26. package/src/__tests__/PersSDKProvider.test.tsx +484 -420
  27. package/src/__tests__/setup.ts +40 -40
  28. package/src/hooks/index.ts +60 -60
  29. package/src/hooks/useAnalytics.ts +327 -327
  30. package/src/hooks/useAuth.ts +265 -265
  31. package/src/hooks/useBookings.ts +191 -191
  32. package/src/hooks/useBusiness.ts +251 -251
  33. package/src/hooks/useCampaigns.ts +500 -500
  34. package/src/hooks/useDonations.ts +66 -66
  35. package/src/hooks/useEvents.ts +372 -372
  36. package/src/hooks/useFiles.ts +155 -155
  37. package/src/hooks/useIPFSUrl.ts +192 -192
  38. package/src/hooks/usePurchases.ts +65 -65
  39. package/src/hooks/useRedemptions.ts +467 -467
  40. package/src/hooks/useTenants.ts +72 -72
  41. package/src/hooks/useTokenBalances.ts +385 -385
  42. package/src/hooks/useTokens.ts +313 -313
  43. package/src/hooks/useTransactionSigner.ts +611 -611
  44. package/src/hooks/useTransactions.ts +299 -290
  45. package/src/hooks/useTriggerSources.ts +301 -301
  46. package/src/hooks/useUserStatus.ts +61 -61
  47. package/src/hooks/useUsers.ts +167 -167
  48. package/src/hooks/useWeb3.ts +355 -355
  49. package/src/index.ts +777 -774
  50. package/src/polyfills/index.ts +160 -160
  51. package/src/polyfills/web3-polyfills.ts +97 -97
  52. package/src/providers/PersSDKProvider.tsx +393 -374
  53. package/src/providers/react-native-auth-provider.ts +110 -110
  54. package/src/providers/react-native-http-client.ts +150 -145
  55. package/src/providers/rn-dpop-provider.ts +190 -190
  56. package/src/storage/async-storage-token-storage.ts +185 -185
  57. package/src/storage/rn-secure-storage.ts +182 -170
  58. package/src/types/react-native-globals.d.ts +45 -45
  59. package/src/utils/index.ts +8 -8
  60. package/src/utils/platform-detection.ts +86 -86
  61. package/dist/index-CzLxqePZ.js +0 -7717
  62. 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>;
@@ -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>;