@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/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useBookings.d.ts +55 -0
- package/dist/hooks/useBookings.d.ts.map +1 -0
- package/dist/hooks/useBookings.js +153 -0
- package/dist/index.js +592 -81
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/hooks/index.ts +5 -1
- package/src/hooks/useBookings.ts +191 -0
package/dist/hooks/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export { useAnalytics } from './useAnalytics';
|
|
|
17
17
|
export { useDonations } from './useDonations';
|
|
18
18
|
export { useEvents } from './useEvents';
|
|
19
19
|
export { useTriggerSources } from './useTriggerSources';
|
|
20
|
+
export { useBookings } from './useBookings';
|
|
20
21
|
export type { RawUserData } from './useAuth';
|
|
21
22
|
export type { TransactionSignerHook, SubmissionResult, AuthenticatedUser, TransactionSigningResult, StatusUpdateData, OnStatusUpdateFn, SigningStatus as SigningStatusType } from './useTransactionSigner';
|
|
22
23
|
export type { AccountOwnedTokensResult, Web3Hook } from './useWeb3';
|
|
@@ -28,4 +29,5 @@ export type { BusinessFilterOptions, BusinessHook } from './useBusiness';
|
|
|
28
29
|
export type { TransactionQueryOptions, TransactionHook } from './useTransactions';
|
|
29
30
|
export type { TriggerSourceQueryOptions, TriggerSourceHook } from './useTriggerSources';
|
|
30
31
|
export type { AnalyticsHook } from './useAnalytics';
|
|
32
|
+
export type { BookingHook, BookingQueryOptions, BookingValidationOptions } from './useBookings';
|
|
31
33
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAA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aAAa,CAAC;AACjG,YAAY,EACV,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGrH,YAAY,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGhI,YAAY,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGzE,YAAY,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGlF,YAAY,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxF,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { BookingDTO, CreateBookingDTO, UpdateBookingDTO } from '@explorins/pers-shared';
|
|
2
|
+
import type { BookingQueryOptions, BookingValidationOptions } from '@explorins/pers-sdk';
|
|
3
|
+
export type { BookingQueryOptions, BookingValidationOptions } from '@explorins/pers-sdk';
|
|
4
|
+
/**
|
|
5
|
+
* Hook interface for booking operations
|
|
6
|
+
*/
|
|
7
|
+
export interface BookingHook {
|
|
8
|
+
/** Get all bookings with optional filters */
|
|
9
|
+
getBookings: (options?: BookingQueryOptions) => Promise<BookingDTO[]>;
|
|
10
|
+
/** Get a single booking by ID */
|
|
11
|
+
getBookingById: (id: string) => Promise<BookingDTO>;
|
|
12
|
+
/** Create a new booking */
|
|
13
|
+
createBooking: (data: CreateBookingDTO) => Promise<BookingDTO>;
|
|
14
|
+
/** Update an existing booking */
|
|
15
|
+
updateBooking: (id: string, data: UpdateBookingDTO) => Promise<BookingDTO>;
|
|
16
|
+
/** Delete a booking */
|
|
17
|
+
deleteBooking: (id: string) => Promise<void>;
|
|
18
|
+
/** Check if a user has a valid booking */
|
|
19
|
+
hasValidBooking: (userId: string, options?: BookingValidationOptions) => Promise<boolean>;
|
|
20
|
+
/** Whether the SDK is initialized */
|
|
21
|
+
isInitialized: boolean;
|
|
22
|
+
/** Whether the user is authenticated */
|
|
23
|
+
isAuthenticated: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* React hook for booking management operations
|
|
27
|
+
*
|
|
28
|
+
* Provides methods to create, read, update, and delete bookings,
|
|
29
|
+
* as well as checking if a user has a valid booking for redemption eligibility.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { useBookings } from '@explorins/pers-sdk-react-native';
|
|
34
|
+
*
|
|
35
|
+
* function BookingScreen() {
|
|
36
|
+
* const { getBookings, createBooking, hasValidBooking } = useBookings();
|
|
37
|
+
*
|
|
38
|
+
* // List all bookings for a user
|
|
39
|
+
* const userBookings = await getBookings({ userId: 'user-123' });
|
|
40
|
+
*
|
|
41
|
+
* // Create a booking
|
|
42
|
+
* const newBooking = await createBooking({
|
|
43
|
+
* userId: 'user-123',
|
|
44
|
+
* locationName: 'Resort Hotel',
|
|
45
|
+
* checkInDate: '2026-06-01',
|
|
46
|
+
* checkOutDate: '2026-06-05'
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Check if user has valid booking for redemption
|
|
50
|
+
* const isEligible = await hasValidBooking('user-123', { status: 'active' });
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const useBookings: () => BookingHook;
|
|
55
|
+
//# sourceMappingURL=useBookings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBookings.d.ts","sourceRoot":"","sources":["../../src/hooks/useBookings.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC7F,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAGzF,YAAY,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEzF;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,mBAAmB,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACtE,iCAAiC;IACjC,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACpD,2BAA2B;IAC3B,aAAa,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/D,iCAAiC;IACjC,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3E,uBAAuB;IACvB,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,0CAA0C;IAC1C,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1F,qCAAqC;IACrC,aAAa,EAAE,OAAO,CAAC;IACvB,wCAAwC;IACxC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,WAAW,QAAO,WAmI9B,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
+
/**
|
|
4
|
+
* React hook for booking management operations
|
|
5
|
+
*
|
|
6
|
+
* Provides methods to create, read, update, and delete bookings,
|
|
7
|
+
* as well as checking if a user has a valid booking for redemption eligibility.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { useBookings } from '@explorins/pers-sdk-react-native';
|
|
12
|
+
*
|
|
13
|
+
* function BookingScreen() {
|
|
14
|
+
* const { getBookings, createBooking, hasValidBooking } = useBookings();
|
|
15
|
+
*
|
|
16
|
+
* // List all bookings for a user
|
|
17
|
+
* const userBookings = await getBookings({ userId: 'user-123' });
|
|
18
|
+
*
|
|
19
|
+
* // Create a booking
|
|
20
|
+
* const newBooking = await createBooking({
|
|
21
|
+
* userId: 'user-123',
|
|
22
|
+
* locationName: 'Resort Hotel',
|
|
23
|
+
* checkInDate: '2026-06-01',
|
|
24
|
+
* checkOutDate: '2026-06-05'
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Check if user has valid booking for redemption
|
|
28
|
+
* const isEligible = await hasValidBooking('user-123', { status: 'active' });
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const useBookings = () => {
|
|
33
|
+
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
34
|
+
/**
|
|
35
|
+
* Get all bookings with optional filters
|
|
36
|
+
*
|
|
37
|
+
* @param options - Query options including userId, businessId, status filters
|
|
38
|
+
* @returns Array of booking DTOs
|
|
39
|
+
*/
|
|
40
|
+
const getBookings = useCallback(async (options) => {
|
|
41
|
+
if (!isInitialized || !sdk) {
|
|
42
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return await sdk.bookings.getAll(options);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error('Failed to fetch bookings:', error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}, [sdk, isInitialized]);
|
|
52
|
+
/**
|
|
53
|
+
* Get a single booking by ID
|
|
54
|
+
*
|
|
55
|
+
* @param id - Booking UUID
|
|
56
|
+
* @returns Booking DTO
|
|
57
|
+
*/
|
|
58
|
+
const getBookingById = useCallback(async (id) => {
|
|
59
|
+
if (!isInitialized || !sdk) {
|
|
60
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return await sdk.bookings.getById(id);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error('Failed to fetch booking:', error);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}, [sdk, isInitialized]);
|
|
70
|
+
/**
|
|
71
|
+
* Create a new booking
|
|
72
|
+
*
|
|
73
|
+
* @param data - Booking data including userId, locationName, dates
|
|
74
|
+
* @returns Created booking DTO
|
|
75
|
+
*/
|
|
76
|
+
const createBooking = useCallback(async (data) => {
|
|
77
|
+
if (!isInitialized || !sdk) {
|
|
78
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return await sdk.bookings.create(data);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error('Failed to create booking:', error);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}, [sdk, isInitialized]);
|
|
88
|
+
/**
|
|
89
|
+
* Update an existing booking
|
|
90
|
+
*
|
|
91
|
+
* @param id - Booking UUID
|
|
92
|
+
* @param data - Partial booking data to update
|
|
93
|
+
* @returns Updated booking DTO
|
|
94
|
+
*/
|
|
95
|
+
const updateBooking = useCallback(async (id, data) => {
|
|
96
|
+
if (!isInitialized || !sdk) {
|
|
97
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
return await sdk.bookings.update(id, data);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error('Failed to update booking:', error);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}, [sdk, isInitialized]);
|
|
107
|
+
/**
|
|
108
|
+
* Delete a booking
|
|
109
|
+
*
|
|
110
|
+
* @param id - Booking UUID
|
|
111
|
+
*/
|
|
112
|
+
const deleteBooking = useCallback(async (id) => {
|
|
113
|
+
if (!isInitialized || !sdk) {
|
|
114
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
await sdk.bookings.delete(id);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.error('Failed to delete booking:', error);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}, [sdk, isInitialized]);
|
|
124
|
+
/**
|
|
125
|
+
* Check if a user has a valid booking
|
|
126
|
+
*
|
|
127
|
+
* @param userId - User ID to check
|
|
128
|
+
* @param options - Validation options including status filter
|
|
129
|
+
* @returns true if user has valid booking matching criteria
|
|
130
|
+
*/
|
|
131
|
+
const hasValidBooking = useCallback(async (userId, options) => {
|
|
132
|
+
if (!isInitialized || !sdk) {
|
|
133
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
return await sdk.bookings.hasValidBooking(userId, options);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.error('Failed to check booking validity:', error);
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}, [sdk, isInitialized]);
|
|
143
|
+
return {
|
|
144
|
+
getBookings,
|
|
145
|
+
getBookingById,
|
|
146
|
+
createBooking,
|
|
147
|
+
updateBooking,
|
|
148
|
+
deleteBooking,
|
|
149
|
+
hasValidBooking,
|
|
150
|
+
isInitialized,
|
|
151
|
+
isAuthenticated,
|
|
152
|
+
};
|
|
153
|
+
};
|