@explorins/pers-sdk-react-native 1.5.35 → 2.0.0

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 (55) hide show
  1. package/README.md +402 -13
  2. package/dist/hooks/index.d.ts +3 -1
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/index.js +1 -0
  5. package/dist/hooks/useBusiness.d.ts +5 -5
  6. package/dist/hooks/useBusiness.d.ts.map +1 -1
  7. package/dist/hooks/useCampaigns.d.ts +8 -8
  8. package/dist/hooks/useCampaigns.d.ts.map +1 -1
  9. package/dist/hooks/useCampaigns.js +3 -3
  10. package/dist/hooks/useDonations.d.ts +2 -2
  11. package/dist/hooks/useDonations.d.ts.map +1 -1
  12. package/dist/hooks/useEvents.d.ts +178 -0
  13. package/dist/hooks/useEvents.d.ts.map +1 -0
  14. package/dist/hooks/useEvents.js +312 -0
  15. package/dist/hooks/usePurchases.d.ts +3 -3
  16. package/dist/hooks/usePurchases.d.ts.map +1 -1
  17. package/dist/hooks/useRedemptions.d.ts +6 -5
  18. package/dist/hooks/useRedemptions.d.ts.map +1 -1
  19. package/dist/hooks/useRedemptions.js +13 -19
  20. package/dist/hooks/useTenants.d.ts +2 -2
  21. package/dist/hooks/useTenants.d.ts.map +1 -1
  22. package/dist/hooks/useTokens.d.ts +4 -4
  23. package/dist/hooks/useTokens.d.ts.map +1 -1
  24. package/dist/hooks/useTransactionSigner.d.ts +2 -0
  25. package/dist/hooks/useTransactionSigner.d.ts.map +1 -1
  26. package/dist/hooks/useTransactionSigner.js +68 -0
  27. package/dist/hooks/useTransactions.d.ts +3 -3
  28. package/dist/hooks/useTransactions.d.ts.map +1 -1
  29. package/dist/hooks/useUserStatus.d.ts +3 -3
  30. package/dist/hooks/useUserStatus.d.ts.map +1 -1
  31. package/dist/hooks/useUsers.d.ts +3 -3
  32. package/dist/hooks/useUsers.d.ts.map +1 -1
  33. package/dist/hooks/useWeb3.d.ts +5 -53
  34. package/dist/hooks/useWeb3.d.ts.map +1 -1
  35. package/dist/hooks/useWeb3.js +82 -177
  36. package/dist/index.d.ts +83 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +3227 -837
  39. package/dist/index.js.map +1 -1
  40. package/package.json +3 -3
  41. package/src/hooks/index.ts +3 -1
  42. package/src/hooks/useBusiness.ts +5 -5
  43. package/src/hooks/useCampaigns.ts +12 -11
  44. package/src/hooks/useDonations.ts +2 -2
  45. package/src/hooks/useEvents.ts +360 -0
  46. package/src/hooks/usePurchases.ts +3 -3
  47. package/src/hooks/useRedemptions.ts +16 -22
  48. package/src/hooks/useTenants.ts +2 -2
  49. package/src/hooks/useTokens.ts +4 -4
  50. package/src/hooks/useTransactionSigner.ts +73 -0
  51. package/src/hooks/useTransactions.ts +4 -3
  52. package/src/hooks/useUserStatus.ts +3 -3
  53. package/src/hooks/useUsers.ts +3 -3
  54. package/src/hooks/useWeb3.ts +98 -202
  55. package/src/index.ts +105 -2
@@ -0,0 +1,178 @@
1
+ import type { PersEvent, EventHandler, EventFilter, Unsubscribe } from '@explorins/pers-sdk/core';
2
+ export type { PersEvent, EventHandler, EventFilter, Unsubscribe };
3
+ /**
4
+ * Return interface for the useEvents hook
5
+ *
6
+ * Provides event subscription capabilities for the PERS SDK event system.
7
+ * Use this to display notifications, update UI, or trigger side effects.
8
+ *
9
+ * @interface EventsHook
10
+ * @property {Function} subscribe - Subscribe to SDK events with optional filtering
11
+ * @property {Function} once - Subscribe to a single event (auto-unsubscribes)
12
+ * @property {Function} clear - Clear all subscriptions
13
+ * @property {boolean} isAvailable - Whether the event system is available
14
+ * @property {number} subscriberCount - Current number of active subscribers
15
+ */
16
+ export interface EventsHook {
17
+ subscribe: (handler: EventHandler, filter?: EventFilter) => Unsubscribe;
18
+ once: (handler: EventHandler, filter?: EventFilter) => Unsubscribe;
19
+ clear: () => void;
20
+ isAvailable: boolean;
21
+ subscriberCount: number;
22
+ }
23
+ /**
24
+ * React Native hook for PERS SDK event system
25
+ *
26
+ * This hook provides access to the platform-agnostic event system for subscribing to
27
+ * transaction, authentication, campaign, and system events. All events include a
28
+ * `userMessage` field ready for display to end users.
29
+ *
30
+ * **Event Domains:**
31
+ * - `auth` - Authentication events (login, logout, token refresh)
32
+ * - `user` - User profile events (update, create)
33
+ * - `transaction` - Transaction events (created, completed, failed)
34
+ * - `campaign` - Campaign events (claimed, activated)
35
+ * - `redemption` - Redemption events (redeemed, expired)
36
+ * - `business` - Business events (created, updated, membership)
37
+ * - `api` - API error events (network, validation, server errors)
38
+ *
39
+ * **Notification Levels:**
40
+ * - `success` - Operation completed successfully
41
+ * - `error` - Operation failed
42
+ * - `warning` - Operation completed with warnings
43
+ * - `info` - Informational event
44
+ *
45
+ * **Cleanup:**
46
+ * All subscriptions created through this hook are automatically cleaned up when
47
+ * the component unmounts, preventing memory leaks and stale event handlers.
48
+ *
49
+ * @returns {EventsHook} Hook interface with event subscription methods
50
+ *
51
+ * @example
52
+ * **Basic Usage - Show All Notifications**
53
+ * ```typescript
54
+ * import { useEvents } from '@explorins/pers-sdk-react-native';
55
+ *
56
+ * function NotificationComponent() {
57
+ * const { subscribe, isAvailable } = useEvents();
58
+ *
59
+ * useEffect(() => {
60
+ * if (!isAvailable) return;
61
+ *
62
+ * const unsubscribe = subscribe((event) => {
63
+ * // userMessage is always present and UI-ready
64
+ * showNotification(event.userMessage, event.level);
65
+ * });
66
+ *
67
+ * return () => unsubscribe();
68
+ * }, [subscribe, isAvailable]);
69
+ *
70
+ * return <View />;
71
+ * }
72
+ * ```
73
+ *
74
+ * @example
75
+ * **Filter by Domain and Level**
76
+ * ```typescript
77
+ * function TransactionListener() {
78
+ * const { subscribe, isAvailable } = useEvents();
79
+ *
80
+ * useEffect(() => {
81
+ * if (!isAvailable) return;
82
+ *
83
+ * // Only listen to successful transactions
84
+ * const unsubscribe = subscribe(
85
+ * (event) => {
86
+ * if (event.level === 'success') {
87
+ * playSuccessSound();
88
+ * showConfetti();
89
+ * }
90
+ * },
91
+ * { domain: 'transaction' } // Filter
92
+ * );
93
+ *
94
+ * return () => unsubscribe();
95
+ * }, [subscribe, isAvailable]);
96
+ * }
97
+ * ```
98
+ *
99
+ * @example
100
+ * **Filter Errors for Logging**
101
+ * ```typescript
102
+ * function ErrorLogger() {
103
+ * const { subscribe, isAvailable } = useEvents();
104
+ *
105
+ * useEffect(() => {
106
+ * if (!isAvailable) return;
107
+ *
108
+ * const unsubscribe = subscribe(
109
+ * (event) => {
110
+ * // Log errors to crash reporting
111
+ * logToSentry({
112
+ * message: event.userMessage,
113
+ * domain: event.domain,
114
+ * type: event.type,
115
+ * });
116
+ * },
117
+ * { level: 'error' } // Only errors
118
+ * );
119
+ *
120
+ * return () => unsubscribe();
121
+ * }, [subscribe, isAvailable]);
122
+ * }
123
+ * ```
124
+ *
125
+ * @example
126
+ * **One-time Event**
127
+ * ```typescript
128
+ * function FirstTransactionHandler() {
129
+ * const { once, isAvailable } = useEvents();
130
+ *
131
+ * useEffect(() => {
132
+ * if (!isAvailable) return;
133
+ *
134
+ * // Auto-unsubscribe after first transaction event
135
+ * const unsubscribe = once(
136
+ * (event) => {
137
+ * console.log('First transaction event:', event.type);
138
+ * showOnboardingComplete();
139
+ * },
140
+ * { domain: 'transaction', level: 'success' }
141
+ * );
142
+ *
143
+ * return () => unsubscribe();
144
+ * }, [once, isAvailable]);
145
+ * }
146
+ * ```
147
+ *
148
+ * @example
149
+ * **Combined Domain and Level Filter**
150
+ * ```typescript
151
+ * function AuthErrorHandler() {
152
+ * const { subscribe, isAvailable } = useEvents();
153
+ *
154
+ * useEffect(() => {
155
+ * if (!isAvailable) return;
156
+ *
157
+ * const unsubscribe = subscribe(
158
+ * (event) => {
159
+ * Alert.alert('Authentication Error', event.userMessage);
160
+ * navigation.navigate('Login');
161
+ * },
162
+ * { domain: 'auth', level: 'error' }
163
+ * );
164
+ *
165
+ * return () => unsubscribe();
166
+ * }, [subscribe, isAvailable]);
167
+ * }
168
+ * ```
169
+ *
170
+ * @see {@link PersEvent} for event structure
171
+ * @see {@link EventFilter} for filtering options
172
+ * @see {@link EventHandler} for handler function type
173
+ *
174
+ * @since 1.6.49
175
+ */
176
+ export declare const useEvents: () => EventsHook;
177
+ export type EventsHook_ = ReturnType<typeof useEvents>;
178
+ //# sourceMappingURL=useEvents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEvents.d.ts","sourceRoot":"","sources":["../../src/hooks/useEvents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAGlC,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AAElE;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,WAAW,CAAC;IACxE,IAAI,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,WAAW,CAAC;IACnE,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwJG;AACH,eAAO,MAAM,SAAS,QAAO,UA2K5B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
@@ -0,0 +1,312 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ /**
4
+ * React Native hook for PERS SDK event system
5
+ *
6
+ * This hook provides access to the platform-agnostic event system for subscribing to
7
+ * transaction, authentication, campaign, and system events. All events include a
8
+ * `userMessage` field ready for display to end users.
9
+ *
10
+ * **Event Domains:**
11
+ * - `auth` - Authentication events (login, logout, token refresh)
12
+ * - `user` - User profile events (update, create)
13
+ * - `transaction` - Transaction events (created, completed, failed)
14
+ * - `campaign` - Campaign events (claimed, activated)
15
+ * - `redemption` - Redemption events (redeemed, expired)
16
+ * - `business` - Business events (created, updated, membership)
17
+ * - `api` - API error events (network, validation, server errors)
18
+ *
19
+ * **Notification Levels:**
20
+ * - `success` - Operation completed successfully
21
+ * - `error` - Operation failed
22
+ * - `warning` - Operation completed with warnings
23
+ * - `info` - Informational event
24
+ *
25
+ * **Cleanup:**
26
+ * All subscriptions created through this hook are automatically cleaned up when
27
+ * the component unmounts, preventing memory leaks and stale event handlers.
28
+ *
29
+ * @returns {EventsHook} Hook interface with event subscription methods
30
+ *
31
+ * @example
32
+ * **Basic Usage - Show All Notifications**
33
+ * ```typescript
34
+ * import { useEvents } from '@explorins/pers-sdk-react-native';
35
+ *
36
+ * function NotificationComponent() {
37
+ * const { subscribe, isAvailable } = useEvents();
38
+ *
39
+ * useEffect(() => {
40
+ * if (!isAvailable) return;
41
+ *
42
+ * const unsubscribe = subscribe((event) => {
43
+ * // userMessage is always present and UI-ready
44
+ * showNotification(event.userMessage, event.level);
45
+ * });
46
+ *
47
+ * return () => unsubscribe();
48
+ * }, [subscribe, isAvailable]);
49
+ *
50
+ * return <View />;
51
+ * }
52
+ * ```
53
+ *
54
+ * @example
55
+ * **Filter by Domain and Level**
56
+ * ```typescript
57
+ * function TransactionListener() {
58
+ * const { subscribe, isAvailable } = useEvents();
59
+ *
60
+ * useEffect(() => {
61
+ * if (!isAvailable) return;
62
+ *
63
+ * // Only listen to successful transactions
64
+ * const unsubscribe = subscribe(
65
+ * (event) => {
66
+ * if (event.level === 'success') {
67
+ * playSuccessSound();
68
+ * showConfetti();
69
+ * }
70
+ * },
71
+ * { domain: 'transaction' } // Filter
72
+ * );
73
+ *
74
+ * return () => unsubscribe();
75
+ * }, [subscribe, isAvailable]);
76
+ * }
77
+ * ```
78
+ *
79
+ * @example
80
+ * **Filter Errors for Logging**
81
+ * ```typescript
82
+ * function ErrorLogger() {
83
+ * const { subscribe, isAvailable } = useEvents();
84
+ *
85
+ * useEffect(() => {
86
+ * if (!isAvailable) return;
87
+ *
88
+ * const unsubscribe = subscribe(
89
+ * (event) => {
90
+ * // Log errors to crash reporting
91
+ * logToSentry({
92
+ * message: event.userMessage,
93
+ * domain: event.domain,
94
+ * type: event.type,
95
+ * });
96
+ * },
97
+ * { level: 'error' } // Only errors
98
+ * );
99
+ *
100
+ * return () => unsubscribe();
101
+ * }, [subscribe, isAvailable]);
102
+ * }
103
+ * ```
104
+ *
105
+ * @example
106
+ * **One-time Event**
107
+ * ```typescript
108
+ * function FirstTransactionHandler() {
109
+ * const { once, isAvailable } = useEvents();
110
+ *
111
+ * useEffect(() => {
112
+ * if (!isAvailable) return;
113
+ *
114
+ * // Auto-unsubscribe after first transaction event
115
+ * const unsubscribe = once(
116
+ * (event) => {
117
+ * console.log('First transaction event:', event.type);
118
+ * showOnboardingComplete();
119
+ * },
120
+ * { domain: 'transaction', level: 'success' }
121
+ * );
122
+ *
123
+ * return () => unsubscribe();
124
+ * }, [once, isAvailable]);
125
+ * }
126
+ * ```
127
+ *
128
+ * @example
129
+ * **Combined Domain and Level Filter**
130
+ * ```typescript
131
+ * function AuthErrorHandler() {
132
+ * const { subscribe, isAvailable } = useEvents();
133
+ *
134
+ * useEffect(() => {
135
+ * if (!isAvailable) return;
136
+ *
137
+ * const unsubscribe = subscribe(
138
+ * (event) => {
139
+ * Alert.alert('Authentication Error', event.userMessage);
140
+ * navigation.navigate('Login');
141
+ * },
142
+ * { domain: 'auth', level: 'error' }
143
+ * );
144
+ *
145
+ * return () => unsubscribe();
146
+ * }, [subscribe, isAvailable]);
147
+ * }
148
+ * ```
149
+ *
150
+ * @see {@link PersEvent} for event structure
151
+ * @see {@link EventFilter} for filtering options
152
+ * @see {@link EventHandler} for handler function type
153
+ *
154
+ * @since 1.6.49
155
+ */
156
+ export const useEvents = () => {
157
+ const { sdk, isInitialized } = usePersSDK();
158
+ // Track subscriptions for cleanup
159
+ const subscriptionsRef = useRef([]);
160
+ // Cleanup all subscriptions on unmount
161
+ useEffect(() => {
162
+ return () => {
163
+ subscriptionsRef.current.forEach(unsubscribe => {
164
+ try {
165
+ unsubscribe();
166
+ }
167
+ catch (e) {
168
+ // Ignore cleanup errors
169
+ }
170
+ });
171
+ subscriptionsRef.current = [];
172
+ };
173
+ }, []);
174
+ /**
175
+ * Subscribe to SDK events with optional filtering
176
+ *
177
+ * Creates a subscription that will be called for every matching event.
178
+ * The subscription is automatically tracked for cleanup when the component unmounts.
179
+ *
180
+ * @param handler - Callback function invoked for each matching event
181
+ * @param filter - Optional filter to limit events (by domain, level, or both)
182
+ * @returns Unsubscribe function to manually cancel the subscription
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * const unsubscribe = subscribe((event) => {
187
+ * console.log('Event:', event.type, event.userMessage);
188
+ * });
189
+ *
190
+ * // Later: manual cleanup
191
+ * unsubscribe();
192
+ * ```
193
+ */
194
+ const subscribe = useCallback((handler, filter) => {
195
+ if (!isInitialized || !sdk) {
196
+ console.warn('[useEvents] SDK not initialized. Cannot subscribe to events.');
197
+ return () => { }; // Return no-op unsubscribe
198
+ }
199
+ const unsubscribe = sdk.events.subscribe(handler, filter);
200
+ // Track for cleanup
201
+ subscriptionsRef.current.push(unsubscribe);
202
+ // Return wrapped unsubscribe that also removes from tracking
203
+ return () => {
204
+ unsubscribe();
205
+ const index = subscriptionsRef.current.indexOf(unsubscribe);
206
+ if (index > -1) {
207
+ subscriptionsRef.current.splice(index, 1);
208
+ }
209
+ };
210
+ }, [sdk, isInitialized]);
211
+ /**
212
+ * Subscribe to a single event (auto-unsubscribes after first match)
213
+ *
214
+ * Useful for one-time event handling, like waiting for a specific action to complete.
215
+ *
216
+ * @param handler - Callback function invoked for the first matching event
217
+ * @param filter - Optional filter to limit events (by domain, level, or both)
218
+ * @returns Unsubscribe function to manually cancel before event fires
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * once((event) => {
223
+ * console.log('First event:', event.type);
224
+ * }, { domain: 'transaction', level: 'success' });
225
+ * ```
226
+ */
227
+ const once = useCallback((handler, filter) => {
228
+ if (!isInitialized || !sdk) {
229
+ console.warn('[useEvents] SDK not initialized. Cannot subscribe to events.');
230
+ return () => { };
231
+ }
232
+ const unsubscribe = sdk.events.once(handler, filter);
233
+ // Track for cleanup
234
+ subscriptionsRef.current.push(unsubscribe);
235
+ return () => {
236
+ unsubscribe();
237
+ const index = subscriptionsRef.current.indexOf(unsubscribe);
238
+ if (index > -1) {
239
+ subscriptionsRef.current.splice(index, 1);
240
+ }
241
+ };
242
+ }, [sdk, isInitialized]);
243
+ /**
244
+ * Clear all event subscriptions from this hook instance
245
+ *
246
+ * Useful when you want to reset all event listeners without unmounting the component.
247
+ * Note: This only clears subscriptions created through this hook instance.
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * const { clear, subscribe } = useEvents();
252
+ *
253
+ * // Create some subscriptions
254
+ * subscribe((event) => console.log(event));
255
+ * subscribe((event) => logToServer(event));
256
+ *
257
+ * // Later: clear all subscriptions from this hook
258
+ * clear();
259
+ * ```
260
+ */
261
+ const clear = useCallback(() => {
262
+ subscriptionsRef.current.forEach(unsubscribe => {
263
+ try {
264
+ unsubscribe();
265
+ }
266
+ catch (e) {
267
+ // Ignore cleanup errors
268
+ }
269
+ });
270
+ subscriptionsRef.current = [];
271
+ }, []);
272
+ /**
273
+ * Get current subscriber count from the event emitter
274
+ *
275
+ * Useful for debugging or showing active listener count in dev tools.
276
+ */
277
+ const subscriberCount = sdk?.events?.subscriberCount ?? 0;
278
+ return {
279
+ /**
280
+ * Subscribe to SDK events with optional filtering
281
+ *
282
+ * @param handler - Callback function for each matching event
283
+ * @param filter - Optional filter by domain and/or level
284
+ * @returns Unsubscribe function
285
+ */
286
+ subscribe,
287
+ /**
288
+ * Subscribe to a single event (auto-unsubscribes after first match)
289
+ *
290
+ * @param handler - Callback function for the first matching event
291
+ * @param filter - Optional filter by domain and/or level
292
+ * @returns Unsubscribe function
293
+ */
294
+ once,
295
+ /**
296
+ * Clear all subscriptions created through this hook instance
297
+ */
298
+ clear,
299
+ /**
300
+ * Whether the event system is available
301
+ *
302
+ * Returns `true` when SDK is initialized and events can be subscribed to.
303
+ */
304
+ isAvailable: isInitialized && !!sdk?.events,
305
+ /**
306
+ * Current number of active subscribers across all components
307
+ *
308
+ * Useful for debugging event system usage.
309
+ */
310
+ subscriberCount,
311
+ };
312
+ };
@@ -1,8 +1,8 @@
1
- import type { PurchaseTokenDTO, PurchaseDTO } from '@explorins/pers-shared';
1
+ import type { PurchaseTokenDTO, PurchaseDTO, PaginatedResponseDTO } from '@explorins/pers-shared';
2
2
  export declare const usePurchases: () => {
3
3
  createPaymentIntent: (amount: number, currency: string, receiptEmail: string, description: string) => Promise<import("@explorins/pers-shared").PaymentIntentDTO>;
4
- getActivePurchaseTokens: () => Promise<PurchaseTokenDTO[]>;
5
- getAllUserPurchases: () => Promise<PurchaseDTO[]>;
4
+ getActivePurchaseTokens: () => Promise<PaginatedResponseDTO<PurchaseTokenDTO>>;
5
+ getAllUserPurchases: () => Promise<PaginatedResponseDTO<PurchaseDTO>>;
6
6
  isAvailable: boolean;
7
7
  };
8
8
  export type PurchaseHook = ReturnType<typeof usePurchases>;
@@ -1 +1 @@
1
- {"version":3,"file":"usePurchases.d.ts","sourceRoot":"","sources":["../../src/hooks/usePurchases.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE5E,eAAO,MAAM,YAAY;kCAIb,MAAM,YACJ,MAAM,gBACF,MAAM,eACP,MAAM;mCAeiC,QAAQ,gBAAgB,EAAE,CAAC;+BAc/B,QAAQ,WAAW,EAAE,CAAC;;CAuBzE,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC"}
1
+ {"version":3,"file":"usePurchases.d.ts","sourceRoot":"","sources":["../../src/hooks/usePurchases.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAElG,eAAO,MAAM,YAAY;kCAIb,MAAM,YACJ,MAAM,gBACF,MAAM,eACP,MAAM;mCAeiC,QAAQ,qBAAqB,gBAAgB,CAAC,CAAC;+BAcnD,QAAQ,qBAAqB,WAAW,CAAC,CAAC;;CAuB7F,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC"}
@@ -1,12 +1,13 @@
1
1
  import { OnStatusUpdateFn } from './useTransactionSigner';
2
- import type { RedemptionCreateRequestDTO, RedemptionDTO, RedemptionRedeemDTO, RedemptionRedeemRequestResponseDTO, RedemptionTypeDTO } from '@explorins/pers-shared';
2
+ import type { RedemptionCreateRequestDTO, RedemptionDTO, RedemptionRedeemDTO, RedemptionRedeemRequestResponseDTO, RedemptionTypeDTO, PaginatedResponseDTO } from '@explorins/pers-shared';
3
3
  export declare const useRedemptions: () => {
4
- getActiveRedemptions: () => Promise<RedemptionDTO[]>;
5
- getUserRedemptions: () => Promise<RedemptionRedeemDTO[]>;
4
+ getRedemptions: (options?: {
5
+ active?: boolean;
6
+ }) => Promise<PaginatedResponseDTO<RedemptionDTO>>;
7
+ getUserRedemptions: () => Promise<PaginatedResponseDTO<RedemptionRedeemDTO>>;
6
8
  redeem: (redemptionId: string, onStatusUpdate?: OnStatusUpdateFn) => Promise<RedemptionRedeemRequestResponseDTO>;
7
- getRedemptionTypes: () => Promise<RedemptionTypeDTO[]>;
9
+ getRedemptionTypes: () => Promise<PaginatedResponseDTO<RedemptionTypeDTO>>;
8
10
  createRedemption: (redemptionData: RedemptionCreateRequestDTO) => Promise<RedemptionDTO>;
9
- getAllRedemptions: (active?: boolean) => Promise<RedemptionDTO[]>;
10
11
  updateRedemption: (redemptionId: string, redemptionData: RedemptionCreateRequestDTO) => Promise<RedemptionDTO>;
11
12
  toggleRedemptionStatus: (redemptionId: string) => Promise<RedemptionDTO>;
12
13
  isAvailable: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"useRedemptions.d.ts","sourceRoot":"","sources":["../../src/hooks/useRedemptions.ts"],"names":[],"mappings":"AAEA,OAAO,EAA0C,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACb,mBAAmB,EACnB,kCAAkC,EAClC,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,cAAc;gCAI0B,QAAQ,aAAa,EAAE,CAAC;8BAc1B,QAAQ,mBAAmB,EAAE,CAAC;2BAkB/B,MAAM,mBAAmB,gBAAgB,KAAG,QAAQ,kCAAkC,CAAC;8BA0EtF,QAAQ,iBAAiB,EAAE,CAAC;uCA5BjB,0BAA0B,KAAG,QAAQ,aAAa,CAAC;iCAczD,OAAO,KAAG,QAAQ,aAAa,EAAE,CAAC;qCA4B9B,MAAM,kBAAkB,0BAA0B,KAAG,QAAQ,aAAa,CAAC;2CAcrE,MAAM,KAAG,QAAQ,aAAa,CAAC;;;;CA4BhG,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
1
+ {"version":3,"file":"useRedemptions.d.ts","sourceRoot":"","sources":["../../src/hooks/useRedemptions.ts"],"names":[],"mappings":"AAEA,OAAO,EAA0C,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACb,mBAAmB,EACnB,kCAAkC,EAClC,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,cAAc;+BAY2B;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,KAAG,QAAQ,qBAAqB,aAAa,CAAC,CAAC;8BActE,QAAQ,qBAAqB,mBAAmB,CAAC,CAAC;2BAkBnD,MAAM,mBAAmB,gBAAgB,KAAG,QAAQ,kCAAkC,CAAC;8BA4DtF,QAAQ,qBAAqB,iBAAiB,CAAC,CAAC;uCAdrC,0BAA0B,KAAG,QAAQ,aAAa,CAAC;qCA4BrD,MAAM,kBAAkB,0BAA0B,KAAG,QAAQ,aAAa,CAAC;2CAcrE,MAAM,KAAG,QAAQ,aAAa,CAAC;;;;CA2BhG,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
@@ -4,16 +4,24 @@ import { useTransactionSigner } from './useTransactionSigner';
4
4
  export const useRedemptions = () => {
5
5
  const { sdk, isInitialized, isAuthenticated } = usePersSDK();
6
6
  const { signAndSubmitTransactionWithJWT, isSignerAvailable, currentStatus, statusMessage } = useTransactionSigner();
7
- const getActiveRedemptions = useCallback(async () => {
7
+ /**
8
+ * Get redemption offers based on user permissions
9
+ *
10
+ * **Regular Users:** Automatically see only active redemptions available for purchase
11
+ * **Administrators:** Can see all redemptions and filter by active/inactive status
12
+ *
13
+ * The backend enforces permission-based filtering automatically.
14
+ */
15
+ const getRedemptions = useCallback(async (options) => {
8
16
  if (!isInitialized || !sdk) {
9
17
  throw new Error('SDK not initialized. Call initialize() first.');
10
18
  }
11
19
  try {
12
- const result = await sdk.redemptions.getActiveRedemptions();
20
+ const result = await sdk.redemptions.getRedemptions(options);
13
21
  return result;
14
22
  }
15
23
  catch (error) {
16
- console.error('Failed to fetch active redemptions:', error);
24
+ console.error('Failed to fetch redemptions:', error);
17
25
  throw error;
18
26
  }
19
27
  }, [sdk, isInitialized]);
@@ -23,7 +31,7 @@ export const useRedemptions = () => {
23
31
  }
24
32
  if (!isAuthenticated) {
25
33
  console.warn('SDK not authenticated. getUserRedemptions requires authentication.');
26
- return [];
34
+ return { data: [], pagination: { page: 1, limit: 0, total: 0, pages: 0, hasNext: false, hasPrev: false } };
27
35
  }
28
36
  try {
29
37
  const result = await sdk.redemptions.getUserRedemptions();
@@ -93,19 +101,6 @@ export const useRedemptions = () => {
93
101
  throw error;
94
102
  }
95
103
  }, [sdk, isInitialized]);
96
- const getAllRedemptions = useCallback(async (active) => {
97
- if (!isInitialized || !sdk) {
98
- throw new Error('SDK not initialized. Call initialize() first.');
99
- }
100
- try {
101
- const result = await sdk.redemptions.getAllRedemptions(active);
102
- return result;
103
- }
104
- catch (error) {
105
- console.error('Failed to fetch all redemptions:', error);
106
- throw error;
107
- }
108
- }, [sdk, isInitialized]);
109
104
  const getRedemptionTypes = useCallback(async () => {
110
105
  if (!isInitialized || !sdk) {
111
106
  throw new Error('SDK not initialized. Call initialize() first.');
@@ -146,12 +141,11 @@ export const useRedemptions = () => {
146
141
  }
147
142
  }, [sdk, isInitialized]);
148
143
  return {
149
- getActiveRedemptions,
144
+ getRedemptions,
150
145
  getUserRedemptions,
151
146
  redeem,
152
147
  getRedemptionTypes,
153
148
  createRedemption,
154
- getAllRedemptions,
155
149
  updateRedemption,
156
150
  toggleRedemptionStatus,
157
151
  isAvailable: isInitialized && !!sdk?.redemptions,
@@ -1,9 +1,9 @@
1
- import type { TenantPublicDTO, TenantClientConfigDTO, AdminDTO } from '@explorins/pers-shared';
1
+ import type { TenantPublicDTO, TenantClientConfigDTO, AdminDTO, PaginatedResponseDTO } from '@explorins/pers-shared';
2
2
  export declare const useTenants: () => {
3
3
  getTenantInfo: () => Promise<TenantPublicDTO>;
4
4
  getClientConfig: () => Promise<TenantClientConfigDTO>;
5
5
  getLoginToken: () => Promise<string>;
6
- getAdmins: () => Promise<AdminDTO[]>;
6
+ getAdmins: () => Promise<PaginatedResponseDTO<AdminDTO>>;
7
7
  isAvailable: boolean;
8
8
  };
9
9
  export type TenantHook = ReturnType<typeof useTenants>;
@@ -1 +1 @@
1
- {"version":3,"file":"useTenants.d.ts","sourceRoot":"","sources":["../../src/hooks/useTenants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAE/F,eAAO,MAAM,UAAU;yBAGuB,QAAQ,eAAe,CAAC;2BActB,QAAQ,qBAAqB,CAAC;yBAchC,QAAQ,MAAM,CAAC;qBAcnB,QAAQ,QAAQ,EAAE,CAAC;;CAqB5D,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC"}
1
+ {"version":3,"file":"useTenants.d.ts","sourceRoot":"","sources":["../../src/hooks/useTenants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAErH,eAAO,MAAM,UAAU;yBAGuB,QAAQ,eAAe,CAAC;2BActB,QAAQ,qBAAqB,CAAC;yBAchC,QAAQ,MAAM,CAAC;qBAcnB,QAAQ,qBAAqB,QAAQ,CAAC,CAAC;;CAqBhF,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { TokenDTO } from '@explorins/pers-shared';
1
+ import type { TokenDTO, PaginatedResponseDTO } from '@explorins/pers-shared';
2
2
  /**
3
3
  * React hook for token operations in the PERS SDK
4
4
  *
@@ -28,11 +28,11 @@ import type { TokenDTO } from '@explorins/pers-shared';
28
28
  * ```
29
29
  */
30
30
  export declare const useTokens: () => {
31
- getTokens: () => Promise<TokenDTO[]>;
31
+ getTokens: () => Promise<PaginatedResponseDTO<TokenDTO>>;
32
32
  getActiveCreditToken: () => Promise<TokenDTO>;
33
- getRewardTokens: () => Promise<TokenDTO[]>;
33
+ getRewardTokens: () => Promise<PaginatedResponseDTO<TokenDTO>>;
34
34
  getTokenTypes: () => Promise<any>;
35
- getStatusTokens: () => Promise<TokenDTO[]>;
35
+ getStatusTokens: () => Promise<PaginatedResponseDTO<TokenDTO>>;
36
36
  getTokenByContract: (contractAddress: string, contractTokenId?: string | null) => Promise<TokenDTO>;
37
37
  isAvailable: boolean;
38
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useTokens.d.ts","sourceRoot":"","sources":["../../src/hooks/useTokens.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,SAAS;qBAoBoB,QAAQ,QAAQ,EAAE,CAAC;gCA2BR,QAAQ,QAAQ,CAAC;2BA2BtB,QAAQ,QAAQ,EAAE,CAAC;yBA2BrB,QAAQ,GAAG,CAAC;2BA2BV,QAAQ,QAAQ,EAAE,CAAC;0CA6BF,MAAM,oBAAoB,MAAM,GAAG,IAAI,KAAG,QAAQ,QAAQ,CAAC;;CAuB3H,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"useTokens.d.ts","sourceRoot":"","sources":["../../src/hooks/useTokens.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,SAAS;qBAoBoB,QAAQ,qBAAqB,QAAQ,CAAC,CAAC;gCA2B5B,QAAQ,QAAQ,CAAC;2BA2BtB,QAAQ,qBAAqB,QAAQ,CAAC,CAAC;yBA2BzC,QAAQ,GAAG,CAAC;2BA2BV,QAAQ,qBAAqB,QAAQ,CAAC,CAAC;0CA6BtB,MAAM,oBAAoB,MAAM,GAAG,IAAI,KAAG,QAAQ,QAAQ,CAAC;;CAuB3H,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
@@ -17,6 +17,7 @@ export type OnStatusUpdateFn = (status: SigningStatus, message: string, data?: S
17
17
  *
18
18
  * @interface TransactionSignerHook
19
19
  * @property {Function} signAndSubmitTransactionWithJWT - Main method to sign and submit transactions
20
+ * @property {Function} signPersTransaction - Sign transaction without submitting (for POS flows)
20
21
  * @property {boolean} isSignerInitialized - Whether the signer SDK has been initialized
21
22
  * @property {boolean} isSignerAvailable - Whether signing functionality is fully available
22
23
  * @property {SigningStatus | null} currentStatus - Current signing status for UI feedback
@@ -24,6 +25,7 @@ export type OnStatusUpdateFn = (status: SigningStatus, message: string, data?: S
24
25
  */
25
26
  export interface TransactionSignerHook {
26
27
  signAndSubmitTransactionWithJWT: (jwt: string, onStatusUpdate?: OnStatusUpdateFn) => Promise<SubmissionResult>;
28
+ signPersTransaction: (jwt: string, onStatusUpdate?: OnStatusUpdateFn) => Promise<TransactionSigningResult>;
27
29
  isSignerInitialized: boolean;
28
30
  isSignerAvailable: boolean;
29
31
  currentStatus: SigningStatus | null;
@@ -1 +1 @@
1
- {"version":3,"file":"useTransactionSigner.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactionSigner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,aAAa,EAAkB,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI3G,KAAK,gBAAgB,GAAG,OAAO,qCAAqC,EAAE,gBAAgB,CAAC;AACvF,KAAK,iBAAiB,GAAG,OAAO,qCAAqC,EAAE,iBAAiB,CAAC;AACzF,KAAK,wBAAwB,GAAG,OAAO,qCAAqC,EAAE,wBAAwB,CAAC;AAGvG,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAczG;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,qBAAqB;IACpC,+BAA+B,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC/G,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IACpC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgLG;AACH,eAAO,MAAM,oBAAoB,QAAO,qBAoPvC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,CAAC"}
1
+ {"version":3,"file":"useTransactionSigner.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactionSigner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,aAAa,EAAkB,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI3G,KAAK,gBAAgB,GAAG,OAAO,qCAAqC,EAAE,gBAAgB,CAAC;AACvF,KAAK,iBAAiB,GAAG,OAAO,qCAAqC,EAAE,iBAAiB,CAAC;AACzF,KAAK,wBAAwB,GAAG,OAAO,qCAAqC,EAAE,wBAAwB,CAAC;AAGvG,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAczG;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,qBAAqB;IACpC,+BAA+B,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC/G,mBAAmB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC3G,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IACpC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgLG;AACH,eAAO,MAAM,oBAAoB,QAAO,qBA2TvC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,CAAC"}