@explorins/pers-sdk-react-native 2.3.0-alpha.1 → 2.3.0-alpha.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explorins/pers-sdk-react-native",
3
- "version": "2.3.0-alpha.1",
3
+ "version": "2.3.0-alpha.2",
4
4
  "description": "React Native SDK for PERS Platform - Tourism Loyalty System with Blockchain Transaction Signing and WebAuthn Authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "author": "eXplorins",
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "@explorins/pers-sdk": "^2.2.0-alpha.1",
40
+ "@explorins/pers-sdk": "^2.2.0-alpha.2",
41
41
  "@explorins/pers-signer": "^1.0.34",
42
42
  "buffer": "^6.0.3",
43
43
  "ethers": "^6.15.0",
@@ -18,6 +18,7 @@ export { useAnalytics } from './useAnalytics';
18
18
  export { useDonations } from './useDonations';
19
19
  export { useEvents } from './useEvents';
20
20
  export { useTriggerSources } from './useTriggerSources';
21
+ export { useBookings } from './useBookings';
21
22
 
22
23
  // Re-export auth-related types for convenience
23
24
  export type { RawUserData } from './useAuth';
@@ -54,4 +55,7 @@ export type { TransactionQueryOptions, TransactionHook } from './useTransactions
54
55
  export type { TriggerSourceQueryOptions, TriggerSourceHook } from './useTriggerSources';
55
56
 
56
57
  // Export analytics-related types
57
- export type { AnalyticsHook } from './useAnalytics';
58
+ export type { AnalyticsHook } from './useAnalytics';
59
+
60
+ // Export booking-related types
61
+ export type { BookingHook, BookingQueryOptions, BookingValidationOptions } from './useBookings';
@@ -0,0 +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
+ };