@explorins/pers-sdk-react-native 1.5.36 → 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 (51) hide show
  1. package/README.md +329 -0
  2. package/dist/hooks/index.d.ts +2 -0
  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/index.d.ts +83 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2979 -652
  36. package/dist/index.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/hooks/index.ts +3 -1
  39. package/src/hooks/useBusiness.ts +5 -5
  40. package/src/hooks/useCampaigns.ts +12 -11
  41. package/src/hooks/useDonations.ts +2 -2
  42. package/src/hooks/useEvents.ts +360 -0
  43. package/src/hooks/usePurchases.ts +3 -3
  44. package/src/hooks/useRedemptions.ts +16 -22
  45. package/src/hooks/useTenants.ts +2 -2
  46. package/src/hooks/useTokens.ts +4 -4
  47. package/src/hooks/useTransactionSigner.ts +73 -0
  48. package/src/hooks/useTransactions.ts +4 -3
  49. package/src/hooks/useUserStatus.ts +3 -3
  50. package/src/hooks/useUsers.ts +3 -3
  51. package/src/index.ts +105 -2
@@ -1,6 +1,6 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
- import type { TokenDTO } from '@explorins/pers-shared';
3
+ import type { TokenDTO, PaginatedResponseDTO } from '@explorins/pers-shared';
4
4
 
5
5
  /**
6
6
  * React hook for token operations in the PERS SDK
@@ -50,7 +50,7 @@ export const useTokens = () => {
50
50
  * console.log('Available tokens:', tokens);
51
51
  * ```
52
52
  */
53
- const getTokens = useCallback(async (): Promise<TokenDTO[]> => {
53
+ const getTokens = useCallback(async (): Promise<PaginatedResponseDTO<TokenDTO>> => {
54
54
  if (!isInitialized || !sdk) {
55
55
  throw new Error('SDK not initialized. Call initialize() first.');
56
56
  }
@@ -104,7 +104,7 @@ export const useTokens = () => {
104
104
  * console.log('Reward tokens:', rewardTokens);
105
105
  * ```
106
106
  */
107
- const getRewardTokens = useCallback(async (): Promise<TokenDTO[]> => {
107
+ const getRewardTokens = useCallback(async (): Promise<PaginatedResponseDTO<TokenDTO>> => {
108
108
  if (!isInitialized || !sdk) {
109
109
  throw new Error('SDK not initialized. Call initialize() first.');
110
110
  }
@@ -158,7 +158,7 @@ export const useTokens = () => {
158
158
  * console.log('Status tokens:', statusTokens);
159
159
  * ```
160
160
  */
161
- const getStatusTokens = useCallback(async (): Promise<TokenDTO[]> => {
161
+ const getStatusTokens = useCallback(async (): Promise<PaginatedResponseDTO<TokenDTO>> => {
162
162
  if (!isInitialized || !sdk) {
163
163
  throw new Error('SDK not initialized. Call initialize() first.');
164
164
  }
@@ -38,6 +38,7 @@ try {
38
38
  *
39
39
  * @interface TransactionSignerHook
40
40
  * @property {Function} signAndSubmitTransactionWithJWT - Main method to sign and submit transactions
41
+ * @property {Function} signPersTransaction - Sign transaction without submitting (for POS flows)
41
42
  * @property {boolean} isSignerInitialized - Whether the signer SDK has been initialized
42
43
  * @property {boolean} isSignerAvailable - Whether signing functionality is fully available
43
44
  * @property {SigningStatus | null} currentStatus - Current signing status for UI feedback
@@ -45,6 +46,7 @@ try {
45
46
  */
46
47
  export interface TransactionSignerHook {
47
48
  signAndSubmitTransactionWithJWT: (jwt: string, onStatusUpdate?: OnStatusUpdateFn) => Promise<SubmissionResult>;
49
+ signPersTransaction: (jwt: string, onStatusUpdate?: OnStatusUpdateFn) => Promise<TransactionSigningResult>;
48
50
  isSignerInitialized: boolean;
49
51
  isSignerAvailable: boolean;
50
52
  currentStatus: SigningStatus | null;
@@ -386,6 +388,65 @@ export const useTransactionSigner = (): TransactionSignerHook => {
386
388
  }
387
389
  }, [isSignerInitialized]);
388
390
 
391
+ /**
392
+ * Sign a PERS transaction without submitting (for POS flows with QR codes)
393
+ *
394
+ * This method signs the transaction but does NOT submit it to the blockchain.
395
+ * Instead, it returns the signature which can be displayed as a QR code for
396
+ * the business to scan and submit.
397
+ *
398
+ * **Use Case:** Point-of-Sale (POS) flows where:
399
+ * 1. User signs the transaction
400
+ * 2. App generates QR code with signature
401
+ * 3. Business scans QR code
402
+ * 4. Business submits transaction to blockchain
403
+ *
404
+ * @param {string} jwt - JWT token with transaction and user data
405
+ * @param {StatusCallback} [onStatusUpdate] - Optional callback for status updates
406
+ * @returns {Promise<TransactionSigningResult>} Signing result with signature for QR code
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * const { signPersTransaction } = useTransactionSigner();
411
+ *
412
+ * const result = await signPersTransaction(jwtToken);
413
+ * if (result.success) {
414
+ * const qrData = {
415
+ * transactionId: result.transactionId,
416
+ * signature: result.signature,
417
+ * transactionFormat: result.signingData.format,
418
+ * txType: 'PENDING_SUBMISSION'
419
+ * };
420
+ * // Display QR code with qrData
421
+ * }
422
+ * ```
423
+ */
424
+ const signPersTransaction = useCallback(async (jwt: string, onStatusUpdate?: OnStatusUpdateFn): Promise<TransactionSigningResult> => {
425
+ if (!isSignerInitialized || !signerSDKRef.current) {
426
+ throw new Error('Signer SDK not initialized');
427
+ }
428
+
429
+ // Create status callback wrapper
430
+ const statusCallback: StatusCallback = {
431
+ onStatusUpdate: (status: SigningStatus, message: string, data?: StatusUpdateData) => {
432
+ setCurrentStatus(status);
433
+ setStatusMessage(message);
434
+ onStatusUpdate?.(status, message, data);
435
+ }
436
+ };
437
+
438
+ try {
439
+ // Use the SDK's sign-only method
440
+ const signingResult = await signerSDKRef.current.signPersTransaction(jwt, statusCallback);
441
+ return signingResult;
442
+ } catch (error) {
443
+ console.error('[useTransactionSigner] Sign-only transaction failed:', error);
444
+ setCurrentStatus(SigningStatus.ERROR);
445
+ setStatusMessage(error instanceof Error ? error.message : 'Signing failed');
446
+ throw error;
447
+ }
448
+ }, [isSignerInitialized]);
449
+
389
450
  return {
390
451
  /**
391
452
  * Sign and submit a blockchain transaction using JWT token
@@ -398,6 +459,18 @@ export const useTransactionSigner = (): TransactionSignerHook => {
398
459
  * @returns {Promise<SubmissionResult>} Transaction result with hash and status
399
460
  */
400
461
  signAndSubmitTransactionWithJWT,
462
+
463
+ /**
464
+ * Sign a transaction without submitting (for POS flows)
465
+ *
466
+ * Signs the transaction and returns the signature without submitting to blockchain.
467
+ * Use this for Point-of-Sale flows where the business scans a QR code and submits.
468
+ *
469
+ * @param {string} jwt - JWT token with transaction and user data
470
+ * @param {StatusCallback} [onStatusUpdate] - Optional callback for status updates
471
+ * @returns {Promise<TransactionSigningResult>} Signing result with signature for QR code
472
+ */
473
+ signPersTransaction,
401
474
 
402
475
  /**
403
476
  * Whether the transaction signer SDK has been successfully initialized
@@ -6,7 +6,8 @@ import type {
6
6
  TransactionRequestResponseDTO,
7
7
  TransactionDTO,
8
8
  TransactionRole,
9
- TransactionPaginationRequestDTO
9
+ TransactionPaginationRequestDTO,
10
+ PaginatedResponseDTO
10
11
  } from '@explorins/pers-shared';
11
12
 
12
13
  /**
@@ -164,7 +165,7 @@ export const useTransactions = () => {
164
165
  * const allTransactions = await getUserTransactionHistory(); // No filter
165
166
  * ```
166
167
  */
167
- const getUserTransactionHistory = useCallback(async (role?: TransactionRole): Promise<TransactionDTO[]> => {
168
+ const getUserTransactionHistory = useCallback(async (role?: TransactionRole): Promise<PaginatedResponseDTO<TransactionDTO>> => {
168
169
 
169
170
  if (!isInitialized || !sdk) {
170
171
  throw new Error('SDK not initialized. Call initialize() first.');
@@ -179,7 +180,7 @@ export const useTransactions = () => {
179
180
  }
180
181
  }, [sdk, isInitialized]);
181
182
 
182
- const getTenantTransactions = useCallback(async (): Promise<TransactionDTO[]> => {
183
+ const getTenantTransactions = useCallback(async (): Promise<PaginatedResponseDTO<TransactionDTO>> => {
183
184
  if (!isInitialized || !sdk) {
184
185
  throw new Error('SDK not initialized. Call initialize() first.');
185
186
  }
@@ -1,11 +1,11 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
- import type { UserStatusTypeDTO } from '@explorins/pers-shared';
3
+ import type { UserStatusTypeDTO, PaginatedResponseDTO } from '@explorins/pers-shared';
4
4
 
5
5
  export const useUserStatus = () => {
6
6
  const { sdk, isInitialized, isAuthenticated } = usePersSDK();
7
7
 
8
- const getUserStatusTypes = useCallback(async (): Promise<UserStatusTypeDTO[]> => {
8
+ const getUserStatusTypes = useCallback(async (): Promise<PaginatedResponseDTO<UserStatusTypeDTO>> => {
9
9
  if (!isInitialized || !sdk) {
10
10
  throw new Error('SDK not initialized. Call initialize() first.');
11
11
  }
@@ -19,7 +19,7 @@ export const useUserStatus = () => {
19
19
  }
20
20
  }, [sdk, isInitialized]);
21
21
 
22
- const getEarnedUserStatus = useCallback(async (): Promise<UserStatusTypeDTO[]> => {
22
+ const getEarnedUserStatus = useCallback(async (): Promise<PaginatedResponseDTO<UserStatusTypeDTO>> => {
23
23
  if (!isInitialized || !sdk) {
24
24
  throw new Error('SDK not initialized. Call initialize() first.');
25
25
  }
@@ -1,6 +1,6 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
- import type { UserDTO, UserCreateRequestDTO } from '@explorins/pers-shared';
3
+ import type { UserDTO, UserCreateRequestDTO, PaginatedResponseDTO } from '@explorins/pers-shared';
4
4
  import type { UserPublicProfileDTO } from '@explorins/pers-sdk/user';
5
5
 
6
6
  export const useUsers = () => {
@@ -54,7 +54,7 @@ export const useUsers = () => {
54
54
  }
55
55
  }, [sdk, isInitialized]);
56
56
 
57
- const getAllUsersPublic = useCallback(async (filter?: { key: string; value: string }): Promise<UserPublicProfileDTO[]> => {
57
+ const getAllUsersPublic = useCallback(async (filter?: { key: string; value: string }): Promise<PaginatedResponseDTO<UserPublicProfileDTO>> => {
58
58
  if (!isInitialized || !sdk) {
59
59
  throw new Error('SDK not initialized. Call initialize() first.');
60
60
  }
@@ -69,7 +69,7 @@ export const useUsers = () => {
69
69
  }, [sdk, isInitialized]);
70
70
 
71
71
  // Admin methods
72
- const getAllUsers = useCallback(async (): Promise<UserDTO[]> => {
72
+ const getAllUsers = useCallback(async (): Promise<PaginatedResponseDTO<UserDTO>> => {
73
73
  if (!isInitialized || !sdk) {
74
74
  throw new Error('SDK not initialized. Call initialize() first.');
75
75
  }
package/src/index.ts CHANGED
@@ -182,6 +182,7 @@ export {
182
182
  * - `useAnalytics` - Usage analytics and reporting
183
183
  * - `useFiles` - File upload and management
184
184
  * - `useWeb3` - Blockchain integration and wallet operations
185
+ * - `useEvents` - ** SDK event subscriptions for notifications**
185
186
  *
186
187
  * @example
187
188
  * **Token Operations:**
@@ -222,6 +223,26 @@ export {
222
223
  * };
223
224
  * }
224
225
  * ```
226
+ *
227
+ * @example
228
+ * **Event Subscriptions:**
229
+ * ```typescript
230
+ * import { useEvents, useEffect } from '@explorins/pers-sdk-react-native';
231
+ *
232
+ * function NotificationHandler() {
233
+ * const { subscribe, isAvailable } = useEvents();
234
+ *
235
+ * useEffect(() => {
236
+ * if (!isAvailable) return;
237
+ *
238
+ * const unsubscribe = subscribe((event) => {
239
+ * showNotification(event.userMessage, event.level);
240
+ * });
241
+ *
242
+ * return () => unsubscribe();
243
+ * }, [subscribe, isAvailable]);
244
+ * }
245
+ * ```
225
246
  */
226
247
  export {
227
248
  useAuth,
@@ -239,12 +260,16 @@ export {
239
260
  useUserStatus,
240
261
  useFiles,
241
262
  useAnalytics,
242
- useDonations
263
+ useDonations,
264
+ useEvents
243
265
  } from './hooks';
244
266
 
245
267
  // Re-export signing status types for convenience
246
268
  export type { OnStatusUpdateFn, StatusUpdateData, SigningStatusType } from './hooks';
247
269
 
270
+ // Re-export event types for convenience
271
+ export type { EventsHook, PersEvent, EventHandler, EventFilter, Unsubscribe } from './hooks';
272
+
248
273
  // ==============================================================================
249
274
  // PLATFORM ADAPTERS
250
275
  // ==============================================================================
@@ -317,4 +342,82 @@ export type {
317
342
  TokenMetadata,
318
343
  TokenCollection,
319
344
  TokenCollectionRequest
320
- } from '@explorins/pers-sdk/web3';
345
+ } from '@explorins/pers-sdk/web3';
346
+
347
+ // ==============================================================================
348
+ // TRANSACTION REQUEST FACTORY FUNCTIONS
349
+ // ==============================================================================
350
+
351
+ /**
352
+ * Transaction Request Factory Functions
353
+ *
354
+ * Factory functions for creating properly structured transaction DTOs.
355
+ * Prioritizes accountId/accountType over raw addresses for security and consistency.
356
+ *
357
+ * @example
358
+ * ```typescript
359
+ * import {
360
+ * buildMintRequest,
361
+ * buildTransferRequest,
362
+ * buildBurnRequest,
363
+ * useTransactions,
364
+ * AccountOwnerType
365
+ * } from '@explorins/pers-sdk-react-native';
366
+ *
367
+ * function TokenOperations() {
368
+ * const { createTransaction } = useTransactions();
369
+ *
370
+ * const handleMint = async () => {
371
+ * const request = buildMintRequest({
372
+ * amount: 100,
373
+ * contractAddress: '0x...',
374
+ * chainId: 137,
375
+ * recipientAccountType: AccountOwnerType.USER,
376
+ * recipientAccountId: 'user-123'
377
+ * });
378
+ * await createTransaction(request);
379
+ * };
380
+ * }
381
+ * ```
382
+ *
383
+ * @see {@link buildMintRequest} - Create mint transaction requests
384
+ * @see {@link buildBurnRequest} - Create burn transaction requests
385
+ * @see {@link buildTransferRequest} - Create transfer transaction requests
386
+ * @see {@link buildPOSTransferRequest} - Create POS transfer requests (business submits on behalf of user)
387
+ * @see {@link buildPOSBurnRequest} - Create POS burn requests (business submits burn on behalf of user)
388
+ * @see {@link buildSubmissionRequest} - Create submission requests from QR/signature data
389
+ */
390
+ export {
391
+ buildMintRequest,
392
+ buildBurnRequest,
393
+ buildTransferRequest,
394
+ buildPOSTransferRequest,
395
+ buildPOSBurnRequest,
396
+ buildSubmissionRequest
397
+ } from '@explorins/pers-sdk/transaction';
398
+
399
+ export type { POSAuthorizationOptions } from '@explorins/pers-sdk/transaction';
400
+
401
+ // ==============================================================================
402
+ // ERROR CLASSES (for instanceof checks)
403
+ // ==============================================================================
404
+
405
+ /**
406
+ * SDK Error classes for type checking in catch blocks
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * import { PersApiError } from '@explorins/pers-sdk-react-native';
411
+ *
412
+ * try {
413
+ * await sdk.campaigns.claimCampaign({ campaignId });
414
+ * } catch (error) {
415
+ * if (error instanceof PersApiError) {
416
+ * console.log(error.message); // Clean backend message
417
+ * console.log(error.code); // e.g., 'CAMPAIGN_BUSINESS_REQUIRED'
418
+ * console.log(error.status); // e.g., 400
419
+ * }
420
+ * }
421
+ * ```
422
+ */
423
+ export { PersApiError, AuthenticationError } from '@explorins/pers-sdk/core';