@explorins/pers-sdk-react-native 2.3.7 → 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 (58) 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/useWeb3.js +4 -4
  11. package/dist/index.js +2400 -487
  12. package/dist/index.js.map +1 -1
  13. package/dist/providers/PersSDKProvider.d.ts +4 -0
  14. package/dist/providers/PersSDKProvider.d.ts.map +1 -1
  15. package/dist/providers/PersSDKProvider.js +14 -0
  16. package/dist/providers/react-native-http-client.d.ts +2 -0
  17. package/dist/providers/react-native-http-client.d.ts.map +1 -1
  18. package/dist/providers/react-native-http-client.js +5 -2
  19. package/dist/storage/rn-secure-storage.d.ts.map +1 -1
  20. package/dist/storage/rn-secure-storage.js +21 -8
  21. package/package.json +3 -3
  22. package/src/__tests__/PersSDKProvider.test.tsx +484 -420
  23. package/src/__tests__/setup.ts +40 -40
  24. package/src/hooks/index.ts +60 -60
  25. package/src/hooks/useAnalytics.ts +327 -327
  26. package/src/hooks/useAuth.ts +265 -265
  27. package/src/hooks/useBookings.ts +191 -191
  28. package/src/hooks/useBusiness.ts +251 -251
  29. package/src/hooks/useCampaigns.ts +500 -500
  30. package/src/hooks/useDonations.ts +66 -66
  31. package/src/hooks/useEvents.ts +372 -372
  32. package/src/hooks/useFiles.ts +155 -155
  33. package/src/hooks/useIPFSUrl.ts +192 -192
  34. package/src/hooks/usePurchases.ts +65 -65
  35. package/src/hooks/useRedemptions.ts +467 -467
  36. package/src/hooks/useTenants.ts +72 -72
  37. package/src/hooks/useTokenBalances.ts +385 -385
  38. package/src/hooks/useTokens.ts +313 -313
  39. package/src/hooks/useTransactionSigner.ts +611 -611
  40. package/src/hooks/useTransactions.ts +299 -299
  41. package/src/hooks/useTriggerSources.ts +301 -301
  42. package/src/hooks/useUserStatus.ts +61 -61
  43. package/src/hooks/useUsers.ts +167 -167
  44. package/src/hooks/useWeb3.ts +355 -355
  45. package/src/index.ts +777 -777
  46. package/src/polyfills/index.ts +160 -160
  47. package/src/polyfills/web3-polyfills.ts +97 -97
  48. package/src/providers/PersSDKProvider.tsx +393 -374
  49. package/src/providers/react-native-auth-provider.ts +110 -110
  50. package/src/providers/react-native-http-client.ts +150 -145
  51. package/src/providers/rn-dpop-provider.ts +190 -190
  52. package/src/storage/async-storage-token-storage.ts +185 -185
  53. package/src/storage/rn-secure-storage.ts +182 -170
  54. package/src/types/react-native-globals.d.ts +45 -45
  55. package/src/utils/index.ts +8 -8
  56. package/src/utils/platform-detection.ts +86 -86
  57. package/dist/index-CzLxqePZ.js +0 -7717
  58. package/dist/index-CzLxqePZ.js.map +0 -1
@@ -1,191 +1,191 @@
1
- import { useCallback } from 'react';
2
- import { usePersSDK } from '../providers/PersSDKProvider';
3
- import type { BookingDTO, CreateBookingDTO, UpdateBookingDTO } from '@explorins/pers-shared';
4
- import type { BookingQueryOptions, BookingValidationOptions } from '@explorins/pers-sdk';
5
-
6
- // Re-export for consumers
7
- export type { BookingQueryOptions, BookingValidationOptions } from '@explorins/pers-sdk';
8
-
9
- /**
10
- * Hook interface for booking operations
11
- */
12
- export interface BookingHook {
13
- /** Get all bookings with optional filters */
14
- getBookings: (options?: BookingQueryOptions) => Promise<BookingDTO[]>;
15
- /** Get a single booking by ID */
16
- getBookingById: (id: string) => Promise<BookingDTO>;
17
- /** Create a new booking */
18
- createBooking: (data: CreateBookingDTO) => Promise<BookingDTO>;
19
- /** Update an existing booking */
20
- updateBooking: (id: string, data: UpdateBookingDTO) => Promise<BookingDTO>;
21
- /** Delete a booking */
22
- deleteBooking: (id: string) => Promise<void>;
23
- /** Check if a user has a valid booking */
24
- hasValidBooking: (userId: string, options?: BookingValidationOptions) => Promise<boolean>;
25
- /** Whether the SDK is initialized */
26
- isInitialized: boolean;
27
- /** Whether the user is authenticated */
28
- isAuthenticated: boolean;
29
- }
30
-
31
- /**
32
- * React hook for booking management operations
33
- *
34
- * Provides methods to create, read, update, and delete bookings,
35
- * as well as checking if a user has a valid booking for redemption eligibility.
36
- *
37
- * @example
38
- * ```typescript
39
- * import { useBookings } from '@explorins/pers-sdk-react-native';
40
- *
41
- * function BookingScreen() {
42
- * const { getBookings, createBooking, hasValidBooking } = useBookings();
43
- *
44
- * // List all bookings for a user
45
- * const userBookings = await getBookings({ userId: 'user-123' });
46
- *
47
- * // Create a booking
48
- * const newBooking = await createBooking({
49
- * userId: 'user-123',
50
- * locationName: 'Resort Hotel',
51
- * checkInDate: '2026-06-01',
52
- * checkOutDate: '2026-06-05'
53
- * });
54
- *
55
- * // Check if user has valid booking for redemption
56
- * const isEligible = await hasValidBooking('user-123', { status: 'active' });
57
- * }
58
- * ```
59
- */
60
- export const useBookings = (): BookingHook => {
61
- const { sdk, isInitialized, isAuthenticated } = usePersSDK();
62
-
63
- /**
64
- * Get all bookings with optional filters
65
- *
66
- * @param options - Query options including userId, businessId, status filters
67
- * @returns Array of booking DTOs
68
- */
69
- const getBookings = useCallback(async (options?: BookingQueryOptions): Promise<BookingDTO[]> => {
70
- if (!isInitialized || !sdk) {
71
- throw new Error('SDK not initialized. Call initialize() first.');
72
- }
73
-
74
- try {
75
- return await sdk.bookings.getAll(options);
76
- } catch (error) {
77
- console.error('Failed to fetch bookings:', error);
78
- throw error;
79
- }
80
- }, [sdk, isInitialized]);
81
-
82
- /**
83
- * Get a single booking by ID
84
- *
85
- * @param id - Booking UUID
86
- * @returns Booking DTO
87
- */
88
- const getBookingById = useCallback(async (id: string): Promise<BookingDTO> => {
89
- if (!isInitialized || !sdk) {
90
- throw new Error('SDK not initialized. Call initialize() first.');
91
- }
92
-
93
- try {
94
- return await sdk.bookings.getById(id);
95
- } catch (error) {
96
- console.error('Failed to fetch booking:', error);
97
- throw error;
98
- }
99
- }, [sdk, isInitialized]);
100
-
101
- /**
102
- * Create a new booking
103
- *
104
- * @param data - Booking data including userId, locationName, dates
105
- * @returns Created booking DTO
106
- */
107
- const createBooking = useCallback(async (data: CreateBookingDTO): Promise<BookingDTO> => {
108
- if (!isInitialized || !sdk) {
109
- throw new Error('SDK not initialized. Call initialize() first.');
110
- }
111
-
112
- try {
113
- return await sdk.bookings.create(data);
114
- } catch (error) {
115
- console.error('Failed to create booking:', error);
116
- throw error;
117
- }
118
- }, [sdk, isInitialized]);
119
-
120
- /**
121
- * Update an existing booking
122
- *
123
- * @param id - Booking UUID
124
- * @param data - Partial booking data to update
125
- * @returns Updated booking DTO
126
- */
127
- const updateBooking = useCallback(async (id: string, data: UpdateBookingDTO): Promise<BookingDTO> => {
128
- if (!isInitialized || !sdk) {
129
- throw new Error('SDK not initialized. Call initialize() first.');
130
- }
131
-
132
- try {
133
- return await sdk.bookings.update(id, data);
134
- } catch (error) {
135
- console.error('Failed to update booking:', error);
136
- throw error;
137
- }
138
- }, [sdk, isInitialized]);
139
-
140
- /**
141
- * Delete a booking
142
- *
143
- * @param id - Booking UUID
144
- */
145
- const deleteBooking = useCallback(async (id: string): Promise<void> => {
146
- if (!isInitialized || !sdk) {
147
- throw new Error('SDK not initialized. Call initialize() first.');
148
- }
149
-
150
- try {
151
- await sdk.bookings.delete(id);
152
- } catch (error) {
153
- console.error('Failed to delete booking:', error);
154
- throw error;
155
- }
156
- }, [sdk, isInitialized]);
157
-
158
- /**
159
- * Check if a user has a valid booking
160
- *
161
- * @param userId - User ID to check
162
- * @param options - Validation options including status filter
163
- * @returns true if user has valid booking matching criteria
164
- */
165
- const hasValidBooking = useCallback(async (
166
- userId: string,
167
- options?: BookingValidationOptions
168
- ): Promise<boolean> => {
169
- if (!isInitialized || !sdk) {
170
- throw new Error('SDK not initialized. Call initialize() first.');
171
- }
172
-
173
- try {
174
- return await sdk.bookings.hasValidBooking(userId, options);
175
- } catch (error) {
176
- console.error('Failed to check booking validity:', error);
177
- throw error;
178
- }
179
- }, [sdk, isInitialized]);
180
-
181
- return {
182
- getBookings,
183
- getBookingById,
184
- createBooking,
185
- updateBooking,
186
- deleteBooking,
187
- hasValidBooking,
188
- isInitialized,
189
- isAuthenticated,
190
- };
191
- };
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import type { BookingDTO, CreateBookingDTO, UpdateBookingDTO } from '@explorins/pers-shared';
4
+ import type { BookingQueryOptions, BookingValidationOptions } from '@explorins/pers-sdk';
5
+
6
+ // Re-export for consumers
7
+ export type { BookingQueryOptions, BookingValidationOptions } from '@explorins/pers-sdk';
8
+
9
+ /**
10
+ * Hook interface for booking operations
11
+ */
12
+ export interface BookingHook {
13
+ /** Get all bookings with optional filters */
14
+ getBookings: (options?: BookingQueryOptions) => Promise<BookingDTO[]>;
15
+ /** Get a single booking by ID */
16
+ getBookingById: (id: string) => Promise<BookingDTO>;
17
+ /** Create a new booking */
18
+ createBooking: (data: CreateBookingDTO) => Promise<BookingDTO>;
19
+ /** Update an existing booking */
20
+ updateBooking: (id: string, data: UpdateBookingDTO) => Promise<BookingDTO>;
21
+ /** Delete a booking */
22
+ deleteBooking: (id: string) => Promise<void>;
23
+ /** Check if a user has a valid booking */
24
+ hasValidBooking: (userId: string, options?: BookingValidationOptions) => Promise<boolean>;
25
+ /** Whether the SDK is initialized */
26
+ isInitialized: boolean;
27
+ /** Whether the user is authenticated */
28
+ isAuthenticated: boolean;
29
+ }
30
+
31
+ /**
32
+ * React hook for booking management operations
33
+ *
34
+ * Provides methods to create, read, update, and delete bookings,
35
+ * as well as checking if a user has a valid booking for redemption eligibility.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { useBookings } from '@explorins/pers-sdk-react-native';
40
+ *
41
+ * function BookingScreen() {
42
+ * const { getBookings, createBooking, hasValidBooking } = useBookings();
43
+ *
44
+ * // List all bookings for a user
45
+ * const userBookings = await getBookings({ userId: 'user-123' });
46
+ *
47
+ * // Create a booking
48
+ * const newBooking = await createBooking({
49
+ * userId: 'user-123',
50
+ * locationName: 'Resort Hotel',
51
+ * checkInDate: '2026-06-01',
52
+ * checkOutDate: '2026-06-05'
53
+ * });
54
+ *
55
+ * // Check if user has valid booking for redemption
56
+ * const isEligible = await hasValidBooking('user-123', { status: 'active' });
57
+ * }
58
+ * ```
59
+ */
60
+ export const useBookings = (): BookingHook => {
61
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
62
+
63
+ /**
64
+ * Get all bookings with optional filters
65
+ *
66
+ * @param options - Query options including userId, businessId, status filters
67
+ * @returns Array of booking DTOs
68
+ */
69
+ const getBookings = useCallback(async (options?: BookingQueryOptions): Promise<BookingDTO[]> => {
70
+ if (!isInitialized || !sdk) {
71
+ throw new Error('SDK not initialized. Call initialize() first.');
72
+ }
73
+
74
+ try {
75
+ return await sdk.bookings.getAll(options);
76
+ } catch (error) {
77
+ console.error('Failed to fetch bookings:', error);
78
+ throw error;
79
+ }
80
+ }, [sdk, isInitialized]);
81
+
82
+ /**
83
+ * Get a single booking by ID
84
+ *
85
+ * @param id - Booking UUID
86
+ * @returns Booking DTO
87
+ */
88
+ const getBookingById = useCallback(async (id: string): Promise<BookingDTO> => {
89
+ if (!isInitialized || !sdk) {
90
+ throw new Error('SDK not initialized. Call initialize() first.');
91
+ }
92
+
93
+ try {
94
+ return await sdk.bookings.getById(id);
95
+ } catch (error) {
96
+ console.error('Failed to fetch booking:', error);
97
+ throw error;
98
+ }
99
+ }, [sdk, isInitialized]);
100
+
101
+ /**
102
+ * Create a new booking
103
+ *
104
+ * @param data - Booking data including userId, locationName, dates
105
+ * @returns Created booking DTO
106
+ */
107
+ const createBooking = useCallback(async (data: CreateBookingDTO): Promise<BookingDTO> => {
108
+ if (!isInitialized || !sdk) {
109
+ throw new Error('SDK not initialized. Call initialize() first.');
110
+ }
111
+
112
+ try {
113
+ return await sdk.bookings.create(data);
114
+ } catch (error) {
115
+ console.error('Failed to create booking:', error);
116
+ throw error;
117
+ }
118
+ }, [sdk, isInitialized]);
119
+
120
+ /**
121
+ * Update an existing booking
122
+ *
123
+ * @param id - Booking UUID
124
+ * @param data - Partial booking data to update
125
+ * @returns Updated booking DTO
126
+ */
127
+ const updateBooking = useCallback(async (id: string, data: UpdateBookingDTO): Promise<BookingDTO> => {
128
+ if (!isInitialized || !sdk) {
129
+ throw new Error('SDK not initialized. Call initialize() first.');
130
+ }
131
+
132
+ try {
133
+ return await sdk.bookings.update(id, data);
134
+ } catch (error) {
135
+ console.error('Failed to update booking:', error);
136
+ throw error;
137
+ }
138
+ }, [sdk, isInitialized]);
139
+
140
+ /**
141
+ * Delete a booking
142
+ *
143
+ * @param id - Booking UUID
144
+ */
145
+ const deleteBooking = useCallback(async (id: string): Promise<void> => {
146
+ if (!isInitialized || !sdk) {
147
+ throw new Error('SDK not initialized. Call initialize() first.');
148
+ }
149
+
150
+ try {
151
+ await sdk.bookings.delete(id);
152
+ } catch (error) {
153
+ console.error('Failed to delete booking:', error);
154
+ throw error;
155
+ }
156
+ }, [sdk, isInitialized]);
157
+
158
+ /**
159
+ * Check if a user has a valid booking
160
+ *
161
+ * @param userId - User ID to check
162
+ * @param options - Validation options including status filter
163
+ * @returns true if user has valid booking matching criteria
164
+ */
165
+ const hasValidBooking = useCallback(async (
166
+ userId: string,
167
+ options?: BookingValidationOptions
168
+ ): Promise<boolean> => {
169
+ if (!isInitialized || !sdk) {
170
+ throw new Error('SDK not initialized. Call initialize() first.');
171
+ }
172
+
173
+ try {
174
+ return await sdk.bookings.hasValidBooking(userId, options);
175
+ } catch (error) {
176
+ console.error('Failed to check booking validity:', error);
177
+ throw error;
178
+ }
179
+ }, [sdk, isInitialized]);
180
+
181
+ return {
182
+ getBookings,
183
+ getBookingById,
184
+ createBooking,
185
+ updateBooking,
186
+ deleteBooking,
187
+ hasValidBooking,
188
+ isInitialized,
189
+ isAuthenticated,
190
+ };
191
+ };