@explorins/pers-sdk-react-native 1.3.2 → 1.5.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.
Files changed (94) hide show
  1. package/README.md +276 -123
  2. package/dist/hooks/index.d.ts +10 -0
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/index.js +8 -0
  5. package/dist/hooks/useAnalytics.d.ts +96 -0
  6. package/dist/hooks/useAnalytics.d.ts.map +1 -0
  7. package/dist/hooks/useAnalytics.js +73 -0
  8. package/dist/hooks/useAuth.d.ts +52 -7
  9. package/dist/hooks/useAuth.d.ts.map +1 -1
  10. package/dist/hooks/useAuth.js +250 -3
  11. package/dist/hooks/useBusiness.d.ts +45 -3
  12. package/dist/hooks/useBusiness.d.ts.map +1 -1
  13. package/dist/hooks/useBusiness.js +182 -28
  14. package/dist/hooks/useCampaigns.d.ts +11 -4
  15. package/dist/hooks/useCampaigns.d.ts.map +1 -1
  16. package/dist/hooks/useCampaigns.js +101 -39
  17. package/dist/hooks/useDonations.d.ts +33 -0
  18. package/dist/hooks/useDonations.d.ts.map +1 -0
  19. package/dist/hooks/useDonations.js +62 -0
  20. package/dist/hooks/useFiles.d.ts +50 -0
  21. package/dist/hooks/useFiles.d.ts.map +1 -0
  22. package/dist/hooks/useFiles.js +140 -0
  23. package/dist/hooks/usePurchases.d.ts +9 -0
  24. package/dist/hooks/usePurchases.d.ts.map +1 -0
  25. package/dist/hooks/usePurchases.js +56 -0
  26. package/dist/hooks/useRedemptions.d.ts +10 -5
  27. package/dist/hooks/useRedemptions.d.ts.map +1 -1
  28. package/dist/hooks/useRedemptions.js +118 -66
  29. package/dist/hooks/useTenants.d.ts +10 -0
  30. package/dist/hooks/useTenants.d.ts.map +1 -0
  31. package/dist/hooks/useTenants.js +68 -0
  32. package/dist/hooks/useTokens.d.ts +36 -2
  33. package/dist/hooks/useTokens.d.ts.map +1 -1
  34. package/dist/hooks/useTokens.js +180 -19
  35. package/dist/hooks/useTransactionSigner.d.ts +73 -0
  36. package/dist/hooks/useTransactionSigner.d.ts.map +1 -0
  37. package/dist/hooks/useTransactionSigner.js +216 -0
  38. package/dist/hooks/useTransactions.d.ts +45 -3
  39. package/dist/hooks/useTransactions.d.ts.map +1 -1
  40. package/dist/hooks/useTransactions.js +149 -39
  41. package/dist/hooks/useUserStatus.d.ts +9 -0
  42. package/dist/hooks/useUserStatus.d.ts.map +1 -0
  43. package/dist/hooks/useUserStatus.js +57 -0
  44. package/dist/hooks/useUsers.d.ts +17 -0
  45. package/dist/hooks/useUsers.d.ts.map +1 -0
  46. package/dist/hooks/useUsers.js +120 -0
  47. package/dist/hooks/useWeb3.d.ts +69 -6
  48. package/dist/hooks/useWeb3.d.ts.map +1 -1
  49. package/dist/hooks/useWeb3.js +177 -17
  50. package/dist/index.d.ts +6 -4
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +31540 -794
  53. package/dist/index.js.map +1 -1
  54. package/dist/polyfills/index.d.ts +1 -1
  55. package/dist/polyfills/index.d.ts.map +1 -1
  56. package/dist/polyfills/index.js +155 -9
  57. package/dist/polyfills/web3-polyfills.d.ts +7 -0
  58. package/dist/polyfills/web3-polyfills.d.ts.map +1 -0
  59. package/dist/polyfills/web3-polyfills.js +85 -0
  60. package/dist/providers/PersSDKProvider.d.ts +28 -18
  61. package/dist/providers/PersSDKProvider.d.ts.map +1 -1
  62. package/dist/providers/PersSDKProvider.js +63 -129
  63. package/dist/providers/react-native-auth-provider.d.ts +19 -64
  64. package/dist/providers/react-native-auth-provider.d.ts.map +1 -1
  65. package/dist/providers/react-native-auth-provider.js +57 -175
  66. package/package.json +177 -157
  67. package/src/hooks/index.ts +13 -1
  68. package/src/hooks/useAnalytics.ts +150 -0
  69. package/src/hooks/useAuth.ts +286 -27
  70. package/src/hooks/useBusiness.ts +193 -30
  71. package/src/hooks/useCampaigns.ts +121 -43
  72. package/src/hooks/useDonations.ts +68 -0
  73. package/src/hooks/useFiles.ts +160 -0
  74. package/src/hooks/usePurchases.ts +69 -0
  75. package/src/hooks/useRedemptions.ts +135 -68
  76. package/src/hooks/useTenants.ts +77 -0
  77. package/src/hooks/useTokens.ts +189 -21
  78. package/src/hooks/useTransactionSigner.ts +287 -0
  79. package/src/hooks/useTransactions.ts +163 -41
  80. package/src/hooks/useUserStatus.ts +65 -0
  81. package/src/hooks/useUsers.ts +133 -0
  82. package/src/hooks/useWeb3.ts +201 -21
  83. package/src/index.ts +22 -17
  84. package/src/polyfills/index.ts +163 -10
  85. package/src/polyfills/web3-polyfills.ts +98 -0
  86. package/src/providers/PersSDKProvider.tsx +114 -178
  87. package/src/providers/react-native-auth-provider.ts +65 -208
  88. package/dist/index.esm.js +0 -1057
  89. package/dist/index.esm.js.map +0 -1
  90. package/dist/polyfills/index.simple.d.ts +0 -2
  91. package/dist/polyfills/index.simple.d.ts.map +0 -1
  92. package/dist/polyfills/index.simple.js +0 -17
  93. package/src/polyfills/index.simple.ts +0 -22
  94. package/src/types/external-modules.d.ts +0 -13
@@ -0,0 +1,140 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ /**
4
+ * React hook for file operations in the PERS SDK
5
+ *
6
+ * Provides methods for generating signed URLs for file uploads and downloads,
7
+ * media optimization, and secure file access. Supports various entity types
8
+ * and customizable expiration times.
9
+ *
10
+ * @returns File hook with methods for file management
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * function FileUploadComponent() {
15
+ * const { getSignedPutUrl, getSignedGetUrl, optimizeMedia } = useFiles();
16
+ *
17
+ * const uploadFile = async (entityId: string, file: File) => {
18
+ * try {
19
+ * const uploadUrl = await getSignedPutUrl(
20
+ * entityId,
21
+ * 'profile',
22
+ * 'jpg'
23
+ * );
24
+ *
25
+ * // Upload file to the signed URL
26
+ * await fetch(uploadUrl, {
27
+ * method: 'PUT',
28
+ * body: file
29
+ * });
30
+ *
31
+ * // Get download URL
32
+ * const downloadUrl = await getSignedGetUrl(entityId, 'profile');
33
+ * console.log('File uploaded, download URL:', downloadUrl);
34
+ * } catch (error) {
35
+ * console.error('File upload failed:', error);
36
+ * }
37
+ * };
38
+ *
39
+ * return <input type="file" onChange={(e) => uploadFile('user-123', e.target.files[0])} />;
40
+ * }
41
+ * ```
42
+ */
43
+ export const useFiles = () => {
44
+ const { sdk, isInitialized } = usePersSDK();
45
+ /**
46
+ * Generates a signed URL for uploading files to cloud storage
47
+ *
48
+ * @param entityId - Unique identifier of the entity the file belongs to
49
+ * @param entityType - Type of entity ('profile', 'business', 'campaign', etc.)
50
+ * @param fileExtension - File extension without the dot (e.g., 'jpg', 'png')
51
+ * @returns Promise resolving to signed upload URL
52
+ * @throws Error if SDK is not initialized
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const { getSignedPutUrl } = useFiles();
57
+ * const uploadUrl = await getSignedPutUrl('user-123', 'profile', 'jpg');
58
+ * // Use uploadUrl with PUT request to upload file
59
+ * ```
60
+ */
61
+ const getSignedPutUrl = useCallback(async (entityId, entityType, fileExtension) => {
62
+ if (!isInitialized || !sdk) {
63
+ throw new Error('SDK not initialized. Call initialize() first.');
64
+ }
65
+ try {
66
+ const result = await sdk.files.getSignedPutUrl(entityId, entityType, fileExtension);
67
+ console.log('Signed put URL generated successfully:', result);
68
+ return result;
69
+ }
70
+ catch (error) {
71
+ console.error('Failed to generate signed put URL:', error);
72
+ throw error;
73
+ }
74
+ }, [sdk, isInitialized]);
75
+ /**
76
+ * Generates a signed URL for downloading files from cloud storage
77
+ *
78
+ * @param entityId - Unique identifier of the entity the file belongs to
79
+ * @param entityType - Type of entity ('profile', 'business', 'campaign', etc.)
80
+ * @param expireSeconds - Optional expiration time in seconds (default varies by implementation)
81
+ * @returns Promise resolving to signed download URL
82
+ * @throws Error if SDK is not initialized
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const { getSignedGetUrl } = useFiles();
87
+ * const downloadUrl = await getSignedGetUrl('user-123', 'profile', 3600); // 1 hour expiry
88
+ * // Use downloadUrl to display or download the file
89
+ * ```
90
+ */
91
+ const getSignedGetUrl = useCallback(async (entityId, entityType, expireSeconds) => {
92
+ if (!isInitialized || !sdk) {
93
+ throw new Error('SDK not initialized. Call initialize() first.');
94
+ }
95
+ try {
96
+ const result = await sdk.files.getSignedGetUrl(entityId, entityType, expireSeconds);
97
+ console.log('Signed get URL generated successfully:', result);
98
+ return result;
99
+ }
100
+ catch (error) {
101
+ console.error('Failed to generate signed get URL:', error);
102
+ throw error;
103
+ }
104
+ }, [sdk, isInitialized]);
105
+ const getSignedUrl = useCallback(async (request) => {
106
+ if (!isInitialized || !sdk) {
107
+ throw new Error('SDK not initialized. Call initialize() first.');
108
+ }
109
+ try {
110
+ const result = await sdk.files.getSignedUrl(request);
111
+ console.log('Signed URL generated successfully:', result);
112
+ return result;
113
+ }
114
+ catch (error) {
115
+ console.error('Failed to generate signed URL:', error);
116
+ throw error;
117
+ }
118
+ }, [sdk, isInitialized]);
119
+ const optimizeMedia = useCallback(async (url, width, height) => {
120
+ if (!isInitialized || !sdk) {
121
+ throw new Error('SDK not initialized. Call initialize() first.');
122
+ }
123
+ try {
124
+ const result = await sdk.files.optimizeMedia(url, width, height);
125
+ console.log('Media optimized successfully:', result);
126
+ return result;
127
+ }
128
+ catch (error) {
129
+ console.error('Failed to optimize media:', error);
130
+ throw error;
131
+ }
132
+ }, [sdk, isInitialized]);
133
+ return {
134
+ getSignedPutUrl,
135
+ getSignedGetUrl,
136
+ getSignedUrl,
137
+ optimizeMedia,
138
+ isAvailable: isInitialized && !!sdk?.files,
139
+ };
140
+ };
@@ -0,0 +1,9 @@
1
+ import type { PurchaseTokenDTO, PurchaseDTO } from '@explorins/pers-shared';
2
+ export declare const usePurchases: () => {
3
+ createPaymentIntent: (amount: number, currency: string, receiptEmail: string, description: string) => Promise<import("@explorins/pers-shared").PaymentIntentDTO>;
4
+ getActivePurchaseTokens: () => Promise<PurchaseTokenDTO[]>;
5
+ getAllUserPurchases: () => Promise<PurchaseDTO[]>;
6
+ isAvailable: boolean;
7
+ };
8
+ export type PurchaseHook = ReturnType<typeof usePurchases>;
9
+ //# sourceMappingURL=usePurchases.d.ts.map
@@ -0,0 +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;mCAgBiC,QAAQ,gBAAgB,EAAE,CAAC;+BAe/B,QAAQ,WAAW,EAAE,CAAC;;CAwBzE,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ export const usePurchases = () => {
4
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
5
+ const createPaymentIntent = useCallback(async (amount, currency, receiptEmail, description) => {
6
+ if (!isInitialized || !sdk) {
7
+ throw new Error('SDK not initialized. Call initialize() first.');
8
+ }
9
+ try {
10
+ const result = await sdk.purchases.createPaymentIntent(amount, currency, receiptEmail, description);
11
+ console.log('Payment intent created successfully:', result);
12
+ return result;
13
+ }
14
+ catch (error) {
15
+ console.error('Failed to create payment intent:', error);
16
+ throw error;
17
+ }
18
+ }, [sdk, isInitialized]);
19
+ const getActivePurchaseTokens = useCallback(async () => {
20
+ if (!isInitialized || !sdk) {
21
+ throw new Error('SDK not initialized. Call initialize() first.');
22
+ }
23
+ try {
24
+ const result = await sdk.purchases.getActivePurchaseTokens();
25
+ console.log('Active purchase tokens fetched successfully:', result);
26
+ return result;
27
+ }
28
+ catch (error) {
29
+ console.error('Failed to fetch active purchase tokens:', error);
30
+ throw error;
31
+ }
32
+ }, [sdk, isInitialized]);
33
+ const getAllUserPurchases = useCallback(async () => {
34
+ if (!isInitialized || !sdk) {
35
+ throw new Error('SDK not initialized. Call initialize() first.');
36
+ }
37
+ if (!isAuthenticated) {
38
+ throw new Error('SDK not authenticated. getAllUserPurchases requires authentication.');
39
+ }
40
+ try {
41
+ const result = await sdk.purchases.getAllUserPurchases();
42
+ console.log('User purchases fetched successfully:', result);
43
+ return result;
44
+ }
45
+ catch (error) {
46
+ console.error('Failed to fetch user purchases:', error);
47
+ throw error;
48
+ }
49
+ }, [sdk, isInitialized, isAuthenticated]);
50
+ return {
51
+ createPaymentIntent,
52
+ getActivePurchaseTokens,
53
+ getAllUserPurchases,
54
+ isAvailable: isInitialized && !!sdk?.purchases,
55
+ };
56
+ };
@@ -1,9 +1,14 @@
1
+ import type { RedemptionCreateRequestDTO, RedemptionDTO, RedemptionRedeemDTO, RedemptionRedeemRequestResponseDTO, RedemptionTypeDTO } from '@explorins/pers-shared';
1
2
  export declare const useRedemptions: () => {
2
- createRedemption: (redemptionData: any) => Promise<any>;
3
- getActiveRedemptions: () => Promise<any>;
4
- getUserRedeems: () => Promise<any>;
5
- redeemRedemption: (redemptionId: string) => Promise<any>;
6
- getRedemptionById: (redemptionId: string) => Promise<any>;
3
+ getActiveRedemptions: () => Promise<RedemptionDTO[]>;
4
+ getUserRedemptions: () => Promise<RedemptionRedeemDTO[]>;
5
+ redeemOffer: (redemptionId: string) => Promise<RedemptionRedeemRequestResponseDTO>;
6
+ getRedemptionTypes: () => Promise<RedemptionTypeDTO[]>;
7
+ createRedemption: (redemptionData: RedemptionCreateRequestDTO) => Promise<RedemptionDTO>;
8
+ getAllRedemptions: (active?: boolean) => Promise<RedemptionDTO[]>;
9
+ updateRedemption: (redemptionId: string, redemptionData: RedemptionCreateRequestDTO) => Promise<RedemptionDTO>;
10
+ toggleRedemptionStatus: (redemptionId: string) => Promise<RedemptionDTO>;
7
11
  isAvailable: boolean;
8
12
  };
13
+ export type RedemptionHook = ReturnType<typeof useRedemptions>;
9
14
  //# sourceMappingURL=useRedemptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useRedemptions.d.ts","sourceRoot":"","sources":["../../src/hooks/useRedemptions.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc;uCAImC,GAAG;;;qCA6DL,MAAM;sCAkCL,MAAM;;CA0BlE,CAAC"}
1
+ {"version":3,"file":"useRedemptions.d.ts","sourceRoot":"","sources":["../../src/hooks/useRedemptions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACb,mBAAmB,EACnB,kCAAkC,EAClC,iBAAiB,EAElB,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,cAAc;gCAI0B,QAAQ,aAAa,EAAE,CAAC;8BAe1B,QAAQ,mBAAmB,EAAE,CAAC;gCAmB1B,MAAM,KAAG,QAAQ,kCAAkC,CAAC;8BAsFxD,QAAQ,iBAAiB,EAAE,CAAC;uCA/BjB,0BAA0B,KAAG,QAAQ,aAAa,CAAC;iCAgBzD,OAAO,KAAG,QAAQ,aAAa,EAAE,CAAC;qCA8B9B,MAAM,kBAAkB,0BAA0B,KAAG,QAAQ,aAAa,CAAC;2CAerE,MAAM,KAAG,QAAQ,aAAa,CAAC;;CA0BhG,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC"}
@@ -1,121 +1,173 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import { useTransactionSigner } from './useTransactionSigner';
3
4
  export const useRedemptions = () => {
4
- const { redemptions, isInitialized, isAuthenticated } = usePersSDK();
5
- // Admin method: Create new redemption offers
6
- const createRedemption = useCallback(async (redemptionData) => {
7
- if (!isInitialized) {
5
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
6
+ const { signTransaction, isSignerAvailable } = useTransactionSigner();
7
+ const getActiveRedemptions = useCallback(async () => {
8
+ if (!isInitialized || !sdk) {
8
9
  throw new Error('SDK not initialized. Call initialize() first.');
9
10
  }
10
- if (!redemptions?.createRedemption) {
11
- throw new Error('createRedemption method not available - admin access required');
12
- }
13
11
  try {
14
- console.log('🔄 Creating redemption offer with data:', redemptionData);
15
- const result = await redemptions.createRedemption(redemptionData);
16
- console.log('✅ Redemption offer created successfully:', result);
12
+ const result = await sdk.redemptions.getActiveRedemptions();
13
+ console.log('Active redemptions fetched successfully:', result);
17
14
  return result;
18
15
  }
19
16
  catch (error) {
20
- console.error('Failed to create redemption offer:', error);
17
+ console.error('Failed to fetch active redemptions:', error);
21
18
  throw error;
22
19
  }
23
- }, [redemptions]);
24
- const getActiveRedemptions = useCallback(async () => {
25
- if (!isInitialized) {
20
+ }, [sdk, isInitialized]);
21
+ const getUserRedemptions = useCallback(async () => {
22
+ if (!isInitialized || !sdk) {
26
23
  throw new Error('SDK not initialized. Call initialize() first.');
27
24
  }
28
- if (!redemptions?.getActiveRedemptions) {
29
- console.warn('getActiveRedemptions method not available');
25
+ if (!isAuthenticated) {
26
+ console.warn('SDK not authenticated. getUserRedemptions requires authentication.');
30
27
  return [];
31
28
  }
32
29
  try {
33
- const result = await redemptions.getActiveRedemptions();
34
- console.log(' Active redemptions fetched successfully:', result);
30
+ const result = await sdk.redemptions.getUserRedemptions();
31
+ console.log('User redemptions fetched successfully:', result);
35
32
  return result;
36
33
  }
37
34
  catch (error) {
38
- console.error('Failed to fetch active redemptions:', error);
35
+ console.error('Failed to fetch user redemptions:', error);
39
36
  throw error;
40
37
  }
41
- }, [redemptions]);
42
- const getUserRedeems = useCallback(async () => {
43
- if (!isInitialized) {
38
+ }, [sdk, isInitialized, isAuthenticated]);
39
+ const redeemOffer = useCallback(async (redemptionId) => {
40
+ if (!isInitialized || !sdk) {
44
41
  throw new Error('SDK not initialized. Call initialize() first.');
45
42
  }
46
43
  if (!isAuthenticated) {
47
- console.warn('SDK not authenticated. getUserRedeems requires authentication.');
48
- return [];
44
+ throw new Error('SDK not authenticated. redeemOffer requires authentication.');
49
45
  }
50
- if (!redemptions?.getUserRedeems) {
51
- console.warn('getUserRedeems method not available');
52
- return [];
46
+ try {
47
+ console.log('Redeeming redemption:', redemptionId);
48
+ const result = await sdk.redemptions.redeemOffer(redemptionId);
49
+ // Check if result has signing fields and sign transaction if required and signer is available
50
+ console.log('Redemption processed successfully:', result);
51
+ const txToken = result.senderTransaction?.actionable?.authToken;
52
+ if (txToken && isSignerAvailable) {
53
+ console.log('Transaction requires blockchain signing, processing with WebAuthn signer...');
54
+ try {
55
+ const signingResult = await signTransaction(txToken);
56
+ console.log('Blockchain signing result:', signingResult);
57
+ if (signingResult.success) {
58
+ console.log('Transaction signed successfully:', signingResult.transactionHash);
59
+ // Return enhanced result with signing information
60
+ return {
61
+ ...result,
62
+ transactionHash: signingResult.transactionHash,
63
+ signature: signingResult.signature,
64
+ isSigned: true,
65
+ signedAt: new Date().toISOString()
66
+ };
67
+ }
68
+ else {
69
+ console.error('Transaction signing failed:', signingResult.error);
70
+ throw new Error(signingResult.error || 'Transaction signing failed');
71
+ }
72
+ }
73
+ catch (signingError) {
74
+ console.error('Blockchain signing error:', signingError);
75
+ throw new Error(`Transaction signing failed: ${signingError}`);
76
+ }
77
+ }
78
+ else if (txToken && !isSignerAvailable) {
79
+ console.warn('Transaction requires signature but signer is not available');
80
+ throw new Error('Transaction requires signature but blockchain signer is not initialized');
81
+ }
82
+ // Return original result if no signing was required
83
+ return result;
84
+ }
85
+ catch (error) {
86
+ console.error('Failed to redeem redemption:', error);
87
+ throw error;
88
+ }
89
+ }, [sdk, isInitialized, isAuthenticated, signTransaction, isSignerAvailable]);
90
+ // Admin methods
91
+ const createRedemption = useCallback(async (redemptionData) => {
92
+ if (!isInitialized || !sdk) {
93
+ throw new Error('SDK not initialized. Call initialize() first.');
53
94
  }
54
95
  try {
55
- const result = await redemptions.getUserRedeems();
56
- console.log('✅ User redemptions fetched successfully:', result);
96
+ console.log('Creating redemption offer with data:', redemptionData);
97
+ const result = await sdk.redemptions.createRedemption(redemptionData);
98
+ console.log('Redemption offer created successfully:', result);
57
99
  return result;
58
100
  }
59
101
  catch (error) {
60
- console.error('Failed to fetch user redemptions:', error);
102
+ console.error('Failed to create redemption offer:', error);
61
103
  throw error;
62
104
  }
63
- }, [isInitialized, isAuthenticated, redemptions]);
64
- const redeemRedemption = useCallback(async (redemptionId) => {
65
- if (!isInitialized) {
105
+ }, [sdk, isInitialized]);
106
+ const getAllRedemptions = useCallback(async (active) => {
107
+ if (!isInitialized || !sdk) {
66
108
  throw new Error('SDK not initialized. Call initialize() first.');
67
109
  }
68
- if (!isAuthenticated) {
69
- throw new Error('SDK not authenticated. redeemRedemption requires authentication.');
110
+ try {
111
+ const result = await sdk.redemptions.getAllRedemptions(active);
112
+ console.log('All redemptions fetched successfully:', result);
113
+ return result;
114
+ }
115
+ catch (error) {
116
+ console.error('Failed to fetch all redemptions:', error);
117
+ throw error;
70
118
  }
71
- if (!redemptions?.redeemRedemption) {
72
- throw new Error('redeemRedemption method not available');
119
+ }, [sdk, isInitialized]);
120
+ const getRedemptionTypes = useCallback(async () => {
121
+ if (!isInitialized || !sdk) {
122
+ throw new Error('SDK not initialized. Call initialize() first.');
73
123
  }
74
124
  try {
75
- console.log('🔄 Redeeming redemption:', redemptionId);
76
- const result = await redemptions.redeemRedemption(redemptionId);
77
- // React Native specific: Handle signature URLs for redemptions
78
- if (result?.actionable?.actionUrl) {
79
- try {
80
- const { Linking } = require('react-native');
81
- console.log('🔗 Opening redemption signature URL:', result.actionable.actionUrl);
82
- await Linking.openURL(result.actionable.actionUrl);
83
- }
84
- catch (linkingError) {
85
- console.error('❌ Failed to open redemption signature URL:', linkingError);
86
- }
87
- }
88
- console.log('✅ Redemption processed successfully:', result);
125
+ const result = await sdk.redemptions.getRedemptionTypes();
126
+ console.log('Redemption types fetched successfully:', result);
89
127
  return result;
90
128
  }
91
129
  catch (error) {
92
- console.error('Failed to redeem redemption:', error);
130
+ console.error('Failed to fetch redemption types:', error);
93
131
  throw error;
94
132
  }
95
- }, [isInitialized, isAuthenticated, redemptions]);
96
- const getRedemptionById = useCallback(async (redemptionId) => {
97
- if (!isInitialized) {
133
+ }, [sdk, isInitialized]);
134
+ const updateRedemption = useCallback(async (redemptionId, redemptionData) => {
135
+ if (!isInitialized || !sdk) {
98
136
  throw new Error('SDK not initialized. Call initialize() first.');
99
137
  }
100
- if (!redemptions?.getRedemptionById) {
101
- throw new Error('getRedemptionById method not available');
138
+ try {
139
+ const result = await sdk.redemptions.updateRedemption(redemptionId, redemptionData);
140
+ console.log('Redemption updated successfully:', result);
141
+ return result;
142
+ }
143
+ catch (error) {
144
+ console.error('Failed to update redemption:', error);
145
+ throw error;
146
+ }
147
+ }, [sdk, isInitialized]);
148
+ const toggleRedemptionStatus = useCallback(async (redemptionId) => {
149
+ if (!isInitialized || !sdk) {
150
+ throw new Error('SDK not initialized. Call initialize() first.');
102
151
  }
103
152
  try {
104
- const result = await redemptions.getRedemptionById(redemptionId);
105
- console.log('Redemption fetched successfully:', result);
153
+ const result = await sdk.redemptions.toggleRedemptionStatus(redemptionId);
154
+ console.log('Redemption status toggled successfully:', result);
106
155
  return result;
107
156
  }
108
157
  catch (error) {
109
- console.error('Failed to fetch redemption:', error);
158
+ console.error('Failed to toggle redemption status:', error);
110
159
  throw error;
111
160
  }
112
- }, [redemptions]);
161
+ }, [sdk, isInitialized]);
113
162
  return {
114
- createRedemption,
115
163
  getActiveRedemptions,
116
- getUserRedeems,
117
- redeemRedemption,
118
- getRedemptionById,
119
- isAvailable: isInitialized && !!redemptions,
164
+ getUserRedemptions,
165
+ redeemOffer,
166
+ getRedemptionTypes,
167
+ createRedemption,
168
+ getAllRedemptions,
169
+ updateRedemption,
170
+ toggleRedemptionStatus,
171
+ isAvailable: isInitialized && !!sdk?.redemptions,
120
172
  };
121
173
  };
@@ -0,0 +1,10 @@
1
+ import type { TenantPublicDTO, TenantClientConfigDTO, AdminDTO } from '@explorins/pers-shared';
2
+ export declare const useTenants: () => {
3
+ getTenantInfo: () => Promise<TenantPublicDTO>;
4
+ getClientConfig: () => Promise<TenantClientConfigDTO>;
5
+ getLoginToken: () => Promise<string>;
6
+ getAdmins: () => Promise<AdminDTO[]>;
7
+ isAvailable: boolean;
8
+ };
9
+ export type TenantHook = ReturnType<typeof useTenants>;
10
+ //# sourceMappingURL=useTenants.d.ts.map
@@ -0,0 +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;2BAetB,QAAQ,qBAAqB,CAAC;yBAehC,QAAQ,MAAM,CAAC;qBAenB,QAAQ,QAAQ,EAAE,CAAC;;CAsB5D,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ export const useTenants = () => {
4
+ const { sdk, isInitialized } = usePersSDK();
5
+ const getTenantInfo = useCallback(async () => {
6
+ if (!isInitialized || !sdk) {
7
+ throw new Error('SDK not initialized. Call initialize() first.');
8
+ }
9
+ try {
10
+ const result = await sdk.tenants.getTenantInfo();
11
+ console.log('Tenant info fetched successfully:', result);
12
+ return result;
13
+ }
14
+ catch (error) {
15
+ console.error('Failed to fetch tenant info:', error);
16
+ throw error;
17
+ }
18
+ }, [sdk, isInitialized]);
19
+ const getClientConfig = useCallback(async () => {
20
+ if (!isInitialized || !sdk) {
21
+ throw new Error('SDK not initialized. Call initialize() first.');
22
+ }
23
+ try {
24
+ const result = await sdk.tenants.getClientConfig();
25
+ console.log('Client config fetched successfully:', result);
26
+ return result;
27
+ }
28
+ catch (error) {
29
+ console.error('Failed to fetch client config:', error);
30
+ throw error;
31
+ }
32
+ }, [sdk, isInitialized]);
33
+ const getLoginToken = useCallback(async () => {
34
+ if (!isInitialized || !sdk) {
35
+ throw new Error('SDK not initialized. Call initialize() first.');
36
+ }
37
+ try {
38
+ const result = await sdk.tenants.getLoginToken();
39
+ console.log('Login token fetched successfully');
40
+ return result;
41
+ }
42
+ catch (error) {
43
+ console.error('Failed to fetch login token:', error);
44
+ throw error;
45
+ }
46
+ }, [sdk, isInitialized]);
47
+ const getAdmins = useCallback(async () => {
48
+ if (!isInitialized || !sdk) {
49
+ throw new Error('SDK not initialized. Call initialize() first.');
50
+ }
51
+ try {
52
+ const result = await sdk.tenants.getAdmins();
53
+ console.log('Admins fetched successfully:', result);
54
+ return result;
55
+ }
56
+ catch (error) {
57
+ console.error('Failed to fetch admins:', error);
58
+ throw error;
59
+ }
60
+ }, [sdk, isInitialized]);
61
+ return {
62
+ getTenantInfo,
63
+ getClientConfig,
64
+ getLoginToken,
65
+ getAdmins,
66
+ isAvailable: isInitialized && !!sdk?.tenants,
67
+ };
68
+ };
@@ -1,6 +1,40 @@
1
+ import type { TokenDTO } from '@explorins/pers-shared';
2
+ /**
3
+ * React hook for token operations in the PERS SDK
4
+ *
5
+ * Provides methods for fetching various types of tokens including credit, reward, and status tokens.
6
+ * Supports both general token queries and specific contract-based token retrieval.
7
+ *
8
+ * @returns Token hook with methods for token management
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * function TokensComponent() {
13
+ * const { getTokens, getActiveCreditToken, getRewardTokens } = useTokens();
14
+ *
15
+ * const loadTokens = async () => {
16
+ * try {
17
+ * const tokens = await getTokens();
18
+ * const creditToken = await getActiveCreditToken();
19
+ * console.log('Loaded tokens:', tokens);
20
+ * console.log('Active credit token:', creditToken);
21
+ * } catch (error) {
22
+ * console.error('Failed to load tokens:', error);
23
+ * }
24
+ * };
25
+ *
26
+ * return <button onClick={loadTokens}>Load Tokens</button>;
27
+ * }
28
+ * ```
29
+ */
1
30
  export declare const useTokens: () => {
2
- getTokens: () => Promise<any>;
3
- getTokenById: (tokenId: string) => Promise<any>;
31
+ getTokens: () => Promise<TokenDTO[]>;
32
+ getActiveCreditToken: () => Promise<TokenDTO>;
33
+ getRewardTokens: () => Promise<TokenDTO[]>;
34
+ getTokenTypes: () => Promise<any>;
35
+ getStatusTokens: () => Promise<TokenDTO[]>;
36
+ getTokenByContract: (contractAddress: string, contractTokenId?: string | null) => Promise<TokenDTO>;
4
37
  isAvailable: boolean;
5
38
  };
39
+ export type TokenHook = ReturnType<typeof useTokens>;
6
40
  //# sourceMappingURL=useTokens.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTokens.d.ts","sourceRoot":"","sources":["../../src/hooks/useTokens.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;4BA0B6B,MAAM;;CAuBxD,CAAC"}
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;gCA4BR,QAAQ,QAAQ,CAAC;2BA4BtB,QAAQ,QAAQ,EAAE,CAAC;yBA4BrB,QAAQ,GAAG,CAAC;2BA4BV,QAAQ,QAAQ,EAAE,CAAC;0CA8BF,MAAM,oBAAoB,MAAM,GAAG,IAAI,KAAG,QAAQ,QAAQ,CAAC;;CAwB3H,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}