@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,252 +1,252 @@
1
- import { useCallback } from 'react';
2
- import { usePersSDK } from '../providers/PersSDKProvider';
3
- import type { BusinessDTO, BusinessTypeDTO, BusinessUpdateRequestDTO, BusinessToggleActiveRequestDTO, PaginatedResponseDTO, BusinessFilterOptions } from '@explorins/pers-sdk';
4
-
5
- // Re-export for consumers
6
- export type { BusinessFilterOptions } from '@explorins/pers-sdk';
7
-
8
- /**
9
- * React hook for business operations in the PERS SDK
10
- *
11
- * Provides methods for fetching, creating, and managing businesses within the platform.
12
- * Includes both public business queries and administrative operations.
13
- *
14
- * @returns Business hook with methods for business management
15
- *
16
- * @example
17
- * ```typescript
18
- * function BusinessesComponent() {
19
- * const {
20
- * getActiveBusinesses,
21
- * getBusinessById,
22
- * createBusiness
23
- * } = useBusiness();
24
- *
25
- * const loadBusinesses = async () => {
26
- * try {
27
- * const businesses = await getActiveBusinesses();
28
- * console.log('Active businesses:', businesses);
29
- * } catch (error) {
30
- * console.error('Failed to load businesses:', error);
31
- * }
32
- * };
33
- *
34
- * return (
35
- * <div>
36
- * <button onClick={loadBusinesses}>Load Businesses</button>
37
- * </div>
38
- * );
39
- * }
40
- * ```
41
- */
42
- export const useBusiness = () => {
43
- const { sdk, isInitialized } = usePersSDK();
44
-
45
- /**
46
- * Retrieves all currently active businesses in the system
47
- *
48
- * @returns Promise resolving to array of active businesses
49
- * @throws Error if SDK is not initialized
50
- *
51
- * @example
52
- * ```typescript
53
- * const { getActiveBusinesses } = useBusiness();
54
- * const businesses = await getActiveBusinesses();
55
- * console.log('Active businesses:', businesses);
56
- * ```
57
- */
58
- const getActiveBusinesses = useCallback(async (): Promise<PaginatedResponseDTO<BusinessDTO>> => {
59
- if (!isInitialized || !sdk) {
60
- throw new Error('SDK not initialized. Call initialize() first.');
61
- }
62
-
63
- try {
64
- const result = await sdk.businesses.getActiveBusinesses();
65
- return result;
66
- } catch (error) {
67
- console.error('Failed to fetch active businesses:', error);
68
- throw error;
69
- }
70
- }, [sdk, isInitialized]);
71
-
72
- /**
73
- * Retrieves all available business types/categories
74
- *
75
- * @returns Promise resolving to array of business types
76
- * @throws Error if SDK is not initialized
77
- *
78
- * @example
79
- * ```typescript
80
- * const { getBusinessTypes } = useBusiness();
81
- * const types = await getBusinessTypes();
82
- * console.log('Business types:', types);
83
- * ```
84
- */
85
- const getBusinessTypes = useCallback(async (): Promise<PaginatedResponseDTO<BusinessTypeDTO>> => {
86
- if (!isInitialized || !sdk) {
87
- throw new Error('SDK not initialized. Call initialize() first.');
88
- }
89
-
90
- try {
91
- const result = await sdk.businesses.getBusinessTypes();
92
- return result;
93
- } catch (error) {
94
- console.error('Failed to fetch business types:', error);
95
- throw error;
96
- }
97
- }, [sdk, isInitialized]);
98
-
99
- const getBusinessById = useCallback(async (businessId: string): Promise<BusinessDTO | null> => {
100
- if (!isInitialized || !sdk) {
101
- throw new Error('SDK not initialized. Call initialize() first.');
102
- }
103
-
104
- try {
105
- const result = await sdk.businesses.getBusinessById(businessId);
106
- return result;
107
- } catch (error) {
108
- console.error('Failed to fetch business:', error);
109
- throw error;
110
- }
111
- }, [sdk, isInitialized]);
112
-
113
- /**
114
- * Admin: Get all businesses with optional filtering
115
- *
116
- * @param options - Filter and pagination options
117
- * @returns Promise resolving to paginated businesses
118
- *
119
- * @example
120
- * ```typescript
121
- * // Get all businesses
122
- * const { data } = await getBusinesses();
123
- *
124
- * // Filter by tag
125
- * const tagged = await getBusinesses({ tag: 'restaurant' });
126
- *
127
- * // Multiple tags (OR match)
128
- * const multiTag = await getBusinesses({ tag: ['restaurant', 'cafe'] });
129
- *
130
- * // With search and pagination
131
- * const filtered = await getBusinesses({
132
- * search: 'coffee',
133
- * active: true,
134
- * page: 1,
135
- * limit: 20
136
- * });
137
- * ```
138
- */
139
- const getBusinesses = useCallback(async (options?: BusinessFilterOptions): Promise<PaginatedResponseDTO<BusinessDTO>> => {
140
- if (!isInitialized || !sdk) {
141
- throw new Error('SDK not initialized. Call initialize() first.');
142
- }
143
-
144
- try {
145
- const result = await sdk.businesses.getBusinesses(options);
146
- return result;
147
- } catch (error) {
148
- console.error('Failed to fetch all businesses:', error);
149
- throw error;
150
- }
151
- }, [sdk, isInitialized]);
152
-
153
- const getBusinessByAccount = useCallback(async (accountAddress: string): Promise<BusinessDTO> => {
154
- if (!isInitialized || !sdk) {
155
- throw new Error('SDK not initialized. Call initialize() first.');
156
- }
157
-
158
- try {
159
- const result = await sdk.businesses.getBusinessByAccount(accountAddress);
160
- return result;
161
- } catch (error) {
162
- console.error('Failed to fetch business by account:', error);
163
- throw error;
164
- }
165
- }, [sdk, isInitialized]);
166
-
167
- const getBusinessesByType = useCallback(async (typeId: string): Promise<PaginatedResponseDTO<BusinessDTO>> => {
168
- if (!isInitialized || !sdk) {
169
- throw new Error('SDK not initialized. Call initialize() first.');
170
- }
171
-
172
- try {
173
- const result = await sdk.businesses.getBusinessesByType(typeId);
174
- return result;
175
- } catch (error) {
176
- console.error('Failed to fetch businesses by type:', error);
177
- throw error;
178
- }
179
- }, [sdk, isInitialized]);
180
-
181
- // Admin methods
182
- /**
183
- * Creates a new business (Admin operation)
184
- *
185
- * @param displayName - The display name for the new business
186
- * @returns Promise resolving to the created business data
187
- * @throws Error if SDK is not initialized or user lacks permissions
188
- *
189
- * @example
190
- * ```typescript
191
- * const { createBusiness } = useBusiness();
192
- * const business = await createBusiness('My Coffee Shop');
193
- * console.log('Business created:', business);
194
- * ```
195
- */
196
- const createBusiness = useCallback(async (displayName: string): Promise<BusinessDTO> => {
197
- if (!isInitialized || !sdk) {
198
- throw new Error('SDK not initialized. Call initialize() first.');
199
- }
200
-
201
- try {
202
- const result = await sdk.businesses.createBusiness(displayName);
203
- return result;
204
- } catch (error) {
205
- console.error('Failed to create business:', error);
206
- throw error;
207
- }
208
- }, [sdk, isInitialized]);
209
-
210
- const updateBusiness = useCallback(async (businessId: string, businessData: BusinessUpdateRequestDTO): Promise<BusinessDTO> => {
211
- if (!isInitialized || !sdk) {
212
- throw new Error('SDK not initialized. Call initialize() first.');
213
- }
214
-
215
- try {
216
- const result = await sdk.businesses.updateBusiness(businessId, businessData);
217
- return result;
218
- } catch (error) {
219
- console.error('Failed to update business:', error);
220
- throw error;
221
- }
222
- }, [sdk, isInitialized]);
223
-
224
- const toggleBusinessStatus = useCallback(async (businessId: string, toggleData: BusinessToggleActiveRequestDTO): Promise<BusinessDTO> => {
225
- if (!isInitialized || !sdk) {
226
- throw new Error('SDK not initialized. Call initialize() first.');
227
- }
228
-
229
- try {
230
- const result = await sdk.businesses.toggleBusinessStatus(businessId, toggleData);
231
- return result;
232
- } catch (error) {
233
- console.error('Failed to toggle business status:', error);
234
- throw error;
235
- }
236
- }, [sdk, isInitialized]);
237
-
238
- return {
239
- getActiveBusinesses,
240
- getBusinessTypes,
241
- getBusinesses,
242
- getBusinessById,
243
- getBusinessByAccount,
244
- getBusinessesByType,
245
- createBusiness,
246
- updateBusiness,
247
- toggleBusinessStatus,
248
- isAvailable: isInitialized && !!sdk?.businesses,
249
- };
250
- };
251
-
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import type { BusinessDTO, BusinessCreateRequestDTO, BusinessTypeDTO, BusinessUpdateRequestDTO, BusinessToggleActiveRequestDTO, PaginatedResponseDTO, BusinessFilterOptions } from '@explorins/pers-sdk';
4
+
5
+ // Re-export for consumers
6
+ export type { BusinessFilterOptions } from '@explorins/pers-sdk';
7
+
8
+ /**
9
+ * React hook for business operations in the PERS SDK
10
+ *
11
+ * Provides methods for fetching, creating, and managing businesses within the platform.
12
+ * Includes both public business queries and administrative operations.
13
+ *
14
+ * @returns Business hook with methods for business management
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * function BusinessesComponent() {
19
+ * const {
20
+ * getActiveBusinesses,
21
+ * getBusinessById,
22
+ * createBusiness
23
+ * } = useBusiness();
24
+ *
25
+ * const loadBusinesses = async () => {
26
+ * try {
27
+ * const businesses = await getActiveBusinesses();
28
+ * console.log('Active businesses:', businesses);
29
+ * } catch (error) {
30
+ * console.error('Failed to load businesses:', error);
31
+ * }
32
+ * };
33
+ *
34
+ * return (
35
+ * <div>
36
+ * <button onClick={loadBusinesses}>Load Businesses</button>
37
+ * </div>
38
+ * );
39
+ * }
40
+ * ```
41
+ */
42
+ export const useBusiness = () => {
43
+ const { sdk, isInitialized } = usePersSDK();
44
+
45
+ /**
46
+ * Retrieves all currently active businesses in the system
47
+ *
48
+ * @returns Promise resolving to array of active businesses
49
+ * @throws Error if SDK is not initialized
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const { getActiveBusinesses } = useBusiness();
54
+ * const businesses = await getActiveBusinesses();
55
+ * console.log('Active businesses:', businesses);
56
+ * ```
57
+ */
58
+ const getActiveBusinesses = useCallback(async (): Promise<PaginatedResponseDTO<BusinessDTO>> => {
59
+ if (!isInitialized || !sdk) {
60
+ throw new Error('SDK not initialized. Call initialize() first.');
61
+ }
62
+
63
+ try {
64
+ const result = await sdk.businesses.getActiveBusinesses();
65
+ return result;
66
+ } catch (error) {
67
+ console.error('Failed to fetch active businesses:', error);
68
+ throw error;
69
+ }
70
+ }, [sdk, isInitialized]);
71
+
72
+ /**
73
+ * Retrieves all available business types/categories
74
+ *
75
+ * @returns Promise resolving to array of business types
76
+ * @throws Error if SDK is not initialized
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const { getBusinessTypes } = useBusiness();
81
+ * const types = await getBusinessTypes();
82
+ * console.log('Business types:', types);
83
+ * ```
84
+ */
85
+ const getBusinessTypes = useCallback(async (): Promise<PaginatedResponseDTO<BusinessTypeDTO>> => {
86
+ if (!isInitialized || !sdk) {
87
+ throw new Error('SDK not initialized. Call initialize() first.');
88
+ }
89
+
90
+ try {
91
+ const result = await sdk.businesses.getBusinessTypes();
92
+ return result;
93
+ } catch (error) {
94
+ console.error('Failed to fetch business types:', error);
95
+ throw error;
96
+ }
97
+ }, [sdk, isInitialized]);
98
+
99
+ const getBusinessById = useCallback(async (businessId: string): Promise<BusinessDTO | null> => {
100
+ if (!isInitialized || !sdk) {
101
+ throw new Error('SDK not initialized. Call initialize() first.');
102
+ }
103
+
104
+ try {
105
+ const result = await sdk.businesses.getBusinessById(businessId);
106
+ return result;
107
+ } catch (error) {
108
+ console.error('Failed to fetch business:', error);
109
+ throw error;
110
+ }
111
+ }, [sdk, isInitialized]);
112
+
113
+ /**
114
+ * Admin: Get all businesses with optional filtering
115
+ *
116
+ * @param options - Filter and pagination options
117
+ * @returns Promise resolving to paginated businesses
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * // Get all businesses
122
+ * const { data } = await getBusinesses();
123
+ *
124
+ * // Filter by tag
125
+ * const tagged = await getBusinesses({ tag: 'restaurant' });
126
+ *
127
+ * // Multiple tags (OR match)
128
+ * const multiTag = await getBusinesses({ tag: ['restaurant', 'cafe'] });
129
+ *
130
+ * // With search and pagination
131
+ * const filtered = await getBusinesses({
132
+ * search: 'coffee',
133
+ * active: true,
134
+ * page: 1,
135
+ * limit: 20
136
+ * });
137
+ * ```
138
+ */
139
+ const getBusinesses = useCallback(async (options?: BusinessFilterOptions): Promise<PaginatedResponseDTO<BusinessDTO>> => {
140
+ if (!isInitialized || !sdk) {
141
+ throw new Error('SDK not initialized. Call initialize() first.');
142
+ }
143
+
144
+ try {
145
+ const result = await sdk.businesses.getBusinesses(options);
146
+ return result;
147
+ } catch (error) {
148
+ console.error('Failed to fetch all businesses:', error);
149
+ throw error;
150
+ }
151
+ }, [sdk, isInitialized]);
152
+
153
+ const getBusinessByAccount = useCallback(async (accountAddress: string): Promise<BusinessDTO> => {
154
+ if (!isInitialized || !sdk) {
155
+ throw new Error('SDK not initialized. Call initialize() first.');
156
+ }
157
+
158
+ try {
159
+ const result = await sdk.businesses.getBusinessByAccount(accountAddress);
160
+ return result;
161
+ } catch (error) {
162
+ console.error('Failed to fetch business by account:', error);
163
+ throw error;
164
+ }
165
+ }, [sdk, isInitialized]);
166
+
167
+ const getBusinessesByType = useCallback(async (typeId: string): Promise<PaginatedResponseDTO<BusinessDTO>> => {
168
+ if (!isInitialized || !sdk) {
169
+ throw new Error('SDK not initialized. Call initialize() first.');
170
+ }
171
+
172
+ try {
173
+ const result = await sdk.businesses.getBusinessesByType(typeId);
174
+ return result;
175
+ } catch (error) {
176
+ console.error('Failed to fetch businesses by type:', error);
177
+ throw error;
178
+ }
179
+ }, [sdk, isInitialized]);
180
+
181
+ // Admin methods
182
+ /**
183
+ * Creates a new business (Admin operation)
184
+ *
185
+ * @param displayName - The display name for the new business
186
+ * @returns Promise resolving to the created business data
187
+ * @throws Error if SDK is not initialized or user lacks permissions
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * const { createBusiness } = useBusiness();
192
+ * const business = await createBusiness('My Coffee Shop');
193
+ * console.log('Business created:', business);
194
+ * ```
195
+ */
196
+ const createBusiness = useCallback(async (dto: BusinessCreateRequestDTO): Promise<BusinessDTO> => {
197
+ if (!isInitialized || !sdk) {
198
+ throw new Error('SDK not initialized. Call initialize() first.');
199
+ }
200
+
201
+ try {
202
+ const result = await sdk.businesses.createBusiness(dto);
203
+ return result;
204
+ } catch (error) {
205
+ console.error('Failed to create business:', error);
206
+ throw error;
207
+ }
208
+ }, [sdk, isInitialized]);
209
+
210
+ const updateBusiness = useCallback(async (businessId: string, businessData: BusinessUpdateRequestDTO): Promise<BusinessDTO> => {
211
+ if (!isInitialized || !sdk) {
212
+ throw new Error('SDK not initialized. Call initialize() first.');
213
+ }
214
+
215
+ try {
216
+ const result = await sdk.businesses.updateBusiness(businessId, businessData);
217
+ return result;
218
+ } catch (error) {
219
+ console.error('Failed to update business:', error);
220
+ throw error;
221
+ }
222
+ }, [sdk, isInitialized]);
223
+
224
+ const toggleBusinessStatus = useCallback(async (businessId: string, toggleData: BusinessToggleActiveRequestDTO): Promise<BusinessDTO> => {
225
+ if (!isInitialized || !sdk) {
226
+ throw new Error('SDK not initialized. Call initialize() first.');
227
+ }
228
+
229
+ try {
230
+ const result = await sdk.businesses.toggleBusinessStatus(businessId, toggleData);
231
+ return result;
232
+ } catch (error) {
233
+ console.error('Failed to toggle business status:', error);
234
+ throw error;
235
+ }
236
+ }, [sdk, isInitialized]);
237
+
238
+ return {
239
+ getActiveBusinesses,
240
+ getBusinessTypes,
241
+ getBusinesses,
242
+ getBusinessById,
243
+ getBusinessByAccount,
244
+ getBusinessesByType,
245
+ createBusiness,
246
+ updateBusiness,
247
+ toggleBusinessStatus,
248
+ isAvailable: isInitialized && !!sdk?.businesses,
249
+ };
250
+ };
251
+
252
252
  export type BusinessHook = ReturnType<typeof useBusiness>;