@explorins/pers-sdk-react-native 1.3.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 (63) hide show
  1. package/README.md +200 -0
  2. package/dist/hooks/index.d.ts +8 -0
  3. package/dist/hooks/index.d.ts.map +1 -0
  4. package/dist/hooks/index.js +8 -0
  5. package/dist/hooks/useAuth.d.ts +12 -0
  6. package/dist/hooks/useAuth.d.ts.map +1 -0
  7. package/dist/hooks/useAuth.js +16 -0
  8. package/dist/hooks/useBusiness.d.ts +7 -0
  9. package/dist/hooks/useBusiness.d.ts.map +1 -0
  10. package/dist/hooks/useBusiness.js +64 -0
  11. package/dist/hooks/useCampaigns.d.ts +8 -0
  12. package/dist/hooks/useCampaigns.d.ts.map +1 -0
  13. package/dist/hooks/useCampaigns.js +90 -0
  14. package/dist/hooks/useRedemptions.d.ts +9 -0
  15. package/dist/hooks/useRedemptions.d.ts.map +1 -0
  16. package/dist/hooks/useRedemptions.js +121 -0
  17. package/dist/hooks/useTokens.d.ts +6 -0
  18. package/dist/hooks/useTokens.d.ts.map +1 -0
  19. package/dist/hooks/useTokens.js +48 -0
  20. package/dist/hooks/useTransactions.d.ts +7 -0
  21. package/dist/hooks/useTransactions.d.ts.map +1 -0
  22. package/dist/hooks/useTransactions.js +78 -0
  23. package/dist/hooks/useWeb3.d.ts +11 -0
  24. package/dist/hooks/useWeb3.d.ts.map +1 -0
  25. package/dist/hooks/useWeb3.js +63 -0
  26. package/dist/index.d.ts +7 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.esm.js +1057 -0
  29. package/dist/index.esm.js.map +1 -0
  30. package/dist/index.js +1077 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/polyfills/index.d.ts +3 -0
  33. package/dist/polyfills/index.d.ts.map +1 -0
  34. package/dist/polyfills/index.js +13 -0
  35. package/dist/polyfills/index.simple.d.ts +2 -0
  36. package/dist/polyfills/index.simple.d.ts.map +1 -0
  37. package/dist/polyfills/index.simple.js +17 -0
  38. package/dist/providers/PersSDKProvider.d.ts +29 -0
  39. package/dist/providers/PersSDKProvider.d.ts.map +1 -0
  40. package/dist/providers/PersSDKProvider.js +194 -0
  41. package/dist/providers/react-native-auth-provider.d.ts +92 -0
  42. package/dist/providers/react-native-auth-provider.d.ts.map +1 -0
  43. package/dist/providers/react-native-auth-provider.js +268 -0
  44. package/dist/providers/react-native-http-client.d.ts +29 -0
  45. package/dist/providers/react-native-http-client.d.ts.map +1 -0
  46. package/dist/providers/react-native-http-client.js +94 -0
  47. package/package.json +157 -0
  48. package/src/hooks/index.ts +8 -0
  49. package/src/hooks/useAuth.ts +43 -0
  50. package/src/hooks/useBusiness.ts +69 -0
  51. package/src/hooks/useCampaigns.ts +96 -0
  52. package/src/hooks/useRedemptions.ts +129 -0
  53. package/src/hooks/useTokens.ts +53 -0
  54. package/src/hooks/useTransactions.ts +85 -0
  55. package/src/hooks/useWeb3.ts +70 -0
  56. package/src/index.ts +51 -0
  57. package/src/polyfills/index.simple.ts +22 -0
  58. package/src/polyfills/index.ts +16 -0
  59. package/src/providers/PersSDKProvider.tsx +274 -0
  60. package/src/providers/react-native-auth-provider.ts +332 -0
  61. package/src/providers/react-native-http-client.ts +129 -0
  62. package/src/types/external-modules.d.ts +13 -0
  63. package/src/types/react-native-globals.d.ts +46 -0
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # PERS SDK - React Native
2
+
3
+ React Native SDK for PERS Platform - Tourism Loyalty System. This package provides React Native-specific implementations of authentication providers and HTTP clients that integrate seamlessly with the PERS SDK.
4
+
5
+ ## Features
6
+
7
+ - 🔐 **Multiple Storage Strategies**: AsyncStorage, Keychain, or Memory
8
+ - 🛡️ **Security-First**: Configurable security levels per token type
9
+ - 📱 **Cross-Platform**: iOS, Android, and Web support
10
+ - 🎯 **Blueprint Ready**: Serves as blueprint for native iOS/Android implementations
11
+ - 🔧 **Flexible Configuration**: Customizable storage and security options
12
+ - 📦 **TypeScript**: Full type safety and IntelliSense support
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @explorins/pers-sdk-react-native @explorins/pers-sdk @react-native-async-storage/async-storage
18
+ ```
19
+
20
+ ### Optional Dependencies
21
+
22
+ For enhanced security (Keychain storage):
23
+ ```bash
24
+ npm install react-native-keychain
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### Basic Usage
30
+
31
+ ```typescript
32
+ import {
33
+ PersApiClient,
34
+ SimpleReactNativeAuthProvider,
35
+ ReactNativeHttpClient
36
+ } from '@explorins/pers-sdk-react-native';
37
+
38
+ // Create HTTP client
39
+ const httpClient = new ReactNativeHttpClient();
40
+
41
+ // Create auth provider
42
+ const authProvider = new SimpleReactNativeAuthProvider('your-project-key');
43
+
44
+ // Create API client
45
+ const apiClient = new PersApiClient(httpClient, {
46
+ environment: 'staging',
47
+ apiVersion: 'v2',
48
+ apiProjectKey: 'your-project-key',
49
+ authProvider: authProvider,
50
+ });
51
+
52
+ // Login and store tokens automatically
53
+ const result = await apiClient.loginUser('your-jwt-token');
54
+ console.log('Logged in:', result.user);
55
+ ```
56
+
57
+ ### Secure Usage (with Keychain)
58
+
59
+ ```typescript
60
+ import {
61
+ SecureReactNativeAuthProvider,
62
+ StorageStrategy
63
+ } from '@explorins/pers-sdk-react-native';
64
+
65
+ // Maximum security - all tokens in Keychain
66
+ const authProvider = new SecureReactNativeAuthProvider('your-project-key', {
67
+ debug: true // Enable debug logging
68
+ });
69
+ ```
70
+
71
+ ### Custom Configuration
72
+
73
+ ```typescript
74
+ import {
75
+ BaseReactNativeAuthProvider,
76
+ StorageStrategy
77
+ } from '@explorins/pers-sdk-react-native';
78
+
79
+ class CustomAuthProvider extends BaseReactNativeAuthProvider {
80
+ readonly authType = 'user' as const;
81
+
82
+ constructor(projectKey: string) {
83
+ super(projectKey, {
84
+ accessTokenStrategy: StorageStrategy.ASYNC_STORAGE,
85
+ refreshTokenStrategy: StorageStrategy.KEYCHAIN,
86
+ keyPrefix: 'myapp',
87
+ debug: __DEV__
88
+ });
89
+ }
90
+
91
+ async getProjectKey(): Promise<string | null> {
92
+ return 'your-project-key';
93
+ }
94
+
95
+ async onTokenExpired(): Promise<void> {
96
+ // Implement token refresh logic
97
+ console.log('Token expired - implement refresh');
98
+ }
99
+ }
100
+ ```
101
+
102
+ ## Storage Strategies
103
+
104
+ ### AsyncStorage (Default)
105
+ - **Use Case**: General app data, user preferences
106
+ - **Security**: Basic - data is stored unencrypted locally
107
+ - **Availability**: Always available on React Native
108
+
109
+ ### Keychain (Recommended for Tokens)
110
+ - **Use Case**: Sensitive data like JWT tokens
111
+ - **Security**: High - uses iOS Keychain / Android Keystore
112
+ - **Availability**: Requires `react-native-keychain` package
113
+
114
+ ### Memory
115
+ - **Use Case**: Temporary data, development, fallback
116
+ - **Security**: High - data cleared on app termination
117
+ - **Availability**: Always available
118
+
119
+ ## API Reference
120
+
121
+ ### SimpleReactNativeAuthProvider
122
+
123
+ Ready-to-use provider with sensible defaults:
124
+ - Access tokens: AsyncStorage
125
+ - Refresh tokens: Keychain (fallback to AsyncStorage)
126
+
127
+ ```typescript
128
+ const authProvider = new SimpleReactNativeAuthProvider(projectKey, {
129
+ debug: true,
130
+ keyPrefix: 'custom_prefix'
131
+ });
132
+ ```
133
+
134
+ ### SecureReactNativeAuthProvider
135
+
136
+ Maximum security provider:
137
+ - All tokens: Keychain storage
138
+ - Automatic fallback to AsyncStorage if Keychain unavailable
139
+
140
+ ```typescript
141
+ const authProvider = new SecureReactNativeAuthProvider(projectKey);
142
+ ```
143
+
144
+ ### BaseReactNativeAuthProvider
145
+
146
+ Extendable base class for custom implementations:
147
+
148
+ ```typescript
149
+ class MyAuthProvider extends BaseReactNativeAuthProvider {
150
+ // Implement required methods
151
+ }
152
+ ```
153
+
154
+ ## Integration with PERS SDK
155
+
156
+ This package works seamlessly with all PERS SDK features:
157
+
158
+ ```typescript
159
+ import {
160
+ createWeb3SDK,
161
+ createBusinessSDK,
162
+ TokenSDK
163
+ } from '@explorins/pers-sdk-react-native';
164
+
165
+ // All SDK features are available
166
+ const web3SDK = createWeb3SDK(apiClient);
167
+ const tokenSDK = new TokenSDK(apiClient);
168
+ const businessSDK = createBusinessSDK(apiClient);
169
+ ```
170
+
171
+ ## Native Implementation Blueprint
172
+
173
+ This React Native SDK serves as a blueprint for native iOS and Android implementations:
174
+
175
+ ### iOS Blueprint
176
+ - AsyncStorage → NSUserDefaults
177
+ - Keychain → iOS Keychain Services
178
+ - HTTP Client → NSURLSession
179
+
180
+ ### Android Blueprint
181
+ - AsyncStorage → SharedPreferences
182
+ - Keychain → Android Keystore
183
+ - HTTP Client → OkHttp/Retrofit
184
+
185
+ ## Development
186
+
187
+ ```bash
188
+ # Install dependencies
189
+ npm install
190
+
191
+ # Build the package
192
+ npm run build
193
+
194
+ # Watch mode for development
195
+ npm run dev
196
+ ```
197
+
198
+ ## License
199
+
200
+ MIT License - see LICENSE file for details.
@@ -0,0 +1,8 @@
1
+ export { useAuth } from './useAuth';
2
+ export { useTokens } from './useTokens';
3
+ export { useTransactions } from './useTransactions';
4
+ export { useBusiness } from './useBusiness';
5
+ export { useCampaigns } from './useCampaigns';
6
+ export { useRedemptions } from './useRedemptions';
7
+ export { useWeb3 } from './useWeb3';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Export all hooks (only hooks, no providers to avoid circular dependency)
2
+ export { useAuth } from './useAuth';
3
+ export { useTokens } from './useTokens';
4
+ export { useTransactions } from './useTransactions';
5
+ export { useBusiness } from './useBusiness';
6
+ export { useCampaigns } from './useCampaigns';
7
+ export { useRedemptions } from './useRedemptions';
8
+ export { useWeb3 } from './useWeb3';
@@ -0,0 +1,12 @@
1
+ export interface AuthHook {
2
+ isInitialized: boolean;
3
+ isAuthenticated: boolean;
4
+ user: any | null;
5
+ accountAddress: string | null;
6
+ initialize: (config: any) => Promise<void>;
7
+ login: (jwtToken: string, userType?: 'user' | 'admin') => Promise<any>;
8
+ loginWithRawData: (rawUserData: any) => Promise<any>;
9
+ logout: () => Promise<void>;
10
+ }
11
+ export declare const useAuth: () => AuthHook;
12
+ //# sourceMappingURL=useAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,QAAQ;IAEvB,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAG9B,UAAU,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACvE,gBAAgB,EAAE,CAAC,WAAW,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACrD,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,eAAO,MAAM,OAAO,QAAO,QAyB1B,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { usePersSDK } from '../providers/PersSDKProvider';
2
+ export const useAuth = () => {
3
+ const { isInitialized, isAuthenticated, user, accountAddress, initialize, login, loginWithRawData, logout, } = usePersSDK();
4
+ return {
5
+ // State
6
+ isInitialized,
7
+ isAuthenticated,
8
+ user,
9
+ accountAddress,
10
+ // Actions
11
+ initialize,
12
+ login,
13
+ loginWithRawData,
14
+ logout,
15
+ };
16
+ };
@@ -0,0 +1,7 @@
1
+ export declare const useBusiness: () => {
2
+ getActiveBusinesses: () => Promise<any>;
3
+ getAllBusinessTypes: () => Promise<any>;
4
+ getBusinessById: (businessId: string) => Promise<any>;
5
+ isAvailable: boolean;
6
+ };
7
+ //# sourceMappingURL=useBusiness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBusiness.d.ts","sourceRoot":"","sources":["../../src/hooks/useBusiness.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW;;;kCAyCiC,MAAM;;CAwB9D,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ export const useBusiness = () => {
4
+ const { business, isInitialized } = usePersSDK();
5
+ const getActiveBusinesses = useCallback(async () => {
6
+ if (!isInitialized) {
7
+ throw new Error('SDK not initialized. Call initialize() first.');
8
+ }
9
+ if (!business?.getActiveBusinesses) {
10
+ console.warn('getActiveBusinesses method not available');
11
+ return [];
12
+ }
13
+ try {
14
+ const result = await business.getActiveBusinesses();
15
+ console.log('✅ Active businesses fetched successfully:', result);
16
+ return result;
17
+ }
18
+ catch (error) {
19
+ console.error('❌ Failed to fetch active businesses:', error);
20
+ throw error;
21
+ }
22
+ }, [business]);
23
+ const getAllBusinessTypes = useCallback(async () => {
24
+ if (!isInitialized) {
25
+ throw new Error('SDK not initialized. Call initialize() first.');
26
+ }
27
+ if (!business?.getAllBusinessTypes) {
28
+ console.warn('getAllBusinessTypes method not available');
29
+ return [];
30
+ }
31
+ try {
32
+ const result = await business.getAllBusinessTypes();
33
+ console.log('✅ Business types fetched successfully:', result);
34
+ return result;
35
+ }
36
+ catch (error) {
37
+ console.error('❌ Failed to fetch business types:', error);
38
+ throw error;
39
+ }
40
+ }, [business]);
41
+ const getBusinessById = useCallback(async (businessId) => {
42
+ if (!isInitialized) {
43
+ throw new Error('SDK not initialized. Call initialize() first.');
44
+ }
45
+ if (!business?.getBusinessById) {
46
+ throw new Error('getBusinessById method not available');
47
+ }
48
+ try {
49
+ const result = await business.getBusinessById(businessId);
50
+ console.log('✅ Business fetched successfully:', result);
51
+ return result;
52
+ }
53
+ catch (error) {
54
+ console.error('❌ Failed to fetch business:', error);
55
+ throw error;
56
+ }
57
+ }, [business]);
58
+ return {
59
+ getActiveBusinesses,
60
+ getAllBusinessTypes,
61
+ getBusinessById,
62
+ isAvailable: isInitialized && !!business,
63
+ };
64
+ };
@@ -0,0 +1,8 @@
1
+ export declare const useCampaigns: () => {
2
+ getActiveCampaigns: () => Promise<any>;
3
+ getCampaignById: (campaignId: string) => Promise<any>;
4
+ claimCampaign: (request: any) => Promise<any>;
5
+ getClaimsForLoggedUser: () => Promise<any>;
6
+ isAvailable: boolean;
7
+ };
8
+ //# sourceMappingURL=useCampaigns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCampaigns.d.ts","sourceRoot":"","sources":["../../src/hooks/useCampaigns.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;kCAsBgC,MAAM;6BAkBX,GAAG;;;CAoDtD,CAAC"}
@@ -0,0 +1,90 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ export const useCampaigns = () => {
4
+ const { campaigns, isInitialized, isAuthenticated } = usePersSDK();
5
+ const getActiveCampaigns = useCallback(async () => {
6
+ if (!isInitialized) {
7
+ throw new Error('SDK not initialized. Call initialize() first.');
8
+ }
9
+ if (!campaigns?.getActiveCampaigns) {
10
+ console.warn('getActiveCampaigns method not available');
11
+ return [];
12
+ }
13
+ try {
14
+ const result = await campaigns.getActiveCampaigns();
15
+ console.log('✅ Active campaigns fetched successfully:', result);
16
+ return result;
17
+ }
18
+ catch (error) {
19
+ console.error('❌ Failed to fetch active campaigns:', error);
20
+ throw error;
21
+ }
22
+ }, [campaigns]);
23
+ const getCampaignById = useCallback(async (campaignId) => {
24
+ if (!isInitialized) {
25
+ throw new Error('SDK not initialized. Call initialize() first.');
26
+ }
27
+ if (!campaigns?.getCampaignById) {
28
+ throw new Error('getCampaignById method not available');
29
+ }
30
+ try {
31
+ const result = await campaigns.getCampaignById(campaignId);
32
+ console.log('✅ Campaign fetched successfully:', result);
33
+ return result;
34
+ }
35
+ catch (error) {
36
+ console.error('❌ Failed to fetch campaign:', error);
37
+ throw error;
38
+ }
39
+ }, [campaigns]);
40
+ const claimCampaign = useCallback(async (request) => {
41
+ if (!isInitialized) {
42
+ throw new Error('SDK not initialized. Call initialize() first.');
43
+ }
44
+ if (!isAuthenticated) {
45
+ throw new Error('SDK not authenticated. claimCampaign requires authentication.');
46
+ }
47
+ if (!campaigns?.claimCampaign) {
48
+ throw new Error('claimCampaign method not available');
49
+ }
50
+ try {
51
+ console.log('🔄 Claiming campaign with request:', request);
52
+ const result = await campaigns.claimCampaign(request);
53
+ console.log('✅ Campaign claimed successfully:', result);
54
+ return result;
55
+ }
56
+ catch (error) {
57
+ console.error('❌ Failed to claim campaign:', error);
58
+ throw error;
59
+ }
60
+ }, [isInitialized, isAuthenticated, campaigns]);
61
+ const getClaimsForLoggedUser = useCallback(async () => {
62
+ if (!isInitialized) {
63
+ throw new Error('SDK not initialized. Call initialize() first.');
64
+ }
65
+ if (!isAuthenticated) {
66
+ console.warn('SDK not authenticated. getClaimsForLoggedUser requires authentication.');
67
+ return [];
68
+ }
69
+ if (!campaigns?.getClaimsForLoggedUser) {
70
+ console.warn('getClaimsForLoggedUser method not available');
71
+ return [];
72
+ }
73
+ try {
74
+ const result = await campaigns.getClaimsForLoggedUser();
75
+ console.log('✅ User claims fetched successfully:', result);
76
+ return result;
77
+ }
78
+ catch (error) {
79
+ console.error('❌ Failed to fetch user claims:', error);
80
+ throw error;
81
+ }
82
+ }, [isInitialized, isAuthenticated, campaigns]);
83
+ return {
84
+ getActiveCampaigns,
85
+ getCampaignById,
86
+ claimCampaign,
87
+ getClaimsForLoggedUser,
88
+ isAvailable: isInitialized && !!campaigns,
89
+ };
90
+ };
@@ -0,0 +1,9 @@
1
+ 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>;
7
+ isAvailable: boolean;
8
+ };
9
+ //# sourceMappingURL=useRedemptions.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,121 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ 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) {
8
+ throw new Error('SDK not initialized. Call initialize() first.');
9
+ }
10
+ if (!redemptions?.createRedemption) {
11
+ throw new Error('createRedemption method not available - admin access required');
12
+ }
13
+ 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);
17
+ return result;
18
+ }
19
+ catch (error) {
20
+ console.error('❌ Failed to create redemption offer:', error);
21
+ throw error;
22
+ }
23
+ }, [redemptions]);
24
+ const getActiveRedemptions = useCallback(async () => {
25
+ if (!isInitialized) {
26
+ throw new Error('SDK not initialized. Call initialize() first.');
27
+ }
28
+ if (!redemptions?.getActiveRedemptions) {
29
+ console.warn('getActiveRedemptions method not available');
30
+ return [];
31
+ }
32
+ try {
33
+ const result = await redemptions.getActiveRedemptions();
34
+ console.log('✅ Active redemptions fetched successfully:', result);
35
+ return result;
36
+ }
37
+ catch (error) {
38
+ console.error('❌ Failed to fetch active redemptions:', error);
39
+ throw error;
40
+ }
41
+ }, [redemptions]);
42
+ const getUserRedeems = useCallback(async () => {
43
+ if (!isInitialized) {
44
+ throw new Error('SDK not initialized. Call initialize() first.');
45
+ }
46
+ if (!isAuthenticated) {
47
+ console.warn('SDK not authenticated. getUserRedeems requires authentication.');
48
+ return [];
49
+ }
50
+ if (!redemptions?.getUserRedeems) {
51
+ console.warn('getUserRedeems method not available');
52
+ return [];
53
+ }
54
+ try {
55
+ const result = await redemptions.getUserRedeems();
56
+ console.log('✅ User redemptions fetched successfully:', result);
57
+ return result;
58
+ }
59
+ catch (error) {
60
+ console.error('❌ Failed to fetch user redemptions:', error);
61
+ throw error;
62
+ }
63
+ }, [isInitialized, isAuthenticated, redemptions]);
64
+ const redeemRedemption = useCallback(async (redemptionId) => {
65
+ if (!isInitialized) {
66
+ throw new Error('SDK not initialized. Call initialize() first.');
67
+ }
68
+ if (!isAuthenticated) {
69
+ throw new Error('SDK not authenticated. redeemRedemption requires authentication.');
70
+ }
71
+ if (!redemptions?.redeemRedemption) {
72
+ throw new Error('redeemRedemption method not available');
73
+ }
74
+ 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);
89
+ return result;
90
+ }
91
+ catch (error) {
92
+ console.error('❌ Failed to redeem redemption:', error);
93
+ throw error;
94
+ }
95
+ }, [isInitialized, isAuthenticated, redemptions]);
96
+ const getRedemptionById = useCallback(async (redemptionId) => {
97
+ if (!isInitialized) {
98
+ throw new Error('SDK not initialized. Call initialize() first.');
99
+ }
100
+ if (!redemptions?.getRedemptionById) {
101
+ throw new Error('getRedemptionById method not available');
102
+ }
103
+ try {
104
+ const result = await redemptions.getRedemptionById(redemptionId);
105
+ console.log('✅ Redemption fetched successfully:', result);
106
+ return result;
107
+ }
108
+ catch (error) {
109
+ console.error('❌ Failed to fetch redemption:', error);
110
+ throw error;
111
+ }
112
+ }, [redemptions]);
113
+ return {
114
+ createRedemption,
115
+ getActiveRedemptions,
116
+ getUserRedeems,
117
+ redeemRedemption,
118
+ getRedemptionById,
119
+ isAvailable: isInitialized && !!redemptions,
120
+ };
121
+ };
@@ -0,0 +1,6 @@
1
+ export declare const useTokens: () => {
2
+ getTokens: () => Promise<any>;
3
+ getTokenById: (tokenId: string) => Promise<any>;
4
+ isAvailable: boolean;
5
+ };
6
+ //# sourceMappingURL=useTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTokens.d.ts","sourceRoot":"","sources":["../../src/hooks/useTokens.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;4BA0B6B,MAAM;;CAuBxD,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ export const useTokens = () => {
4
+ const { tokens, isInitialized, isAuthenticated } = usePersSDK();
5
+ if (!isAuthenticated && isInitialized) {
6
+ console.warn('SDK not authenticated. Some token operations may fail.');
7
+ }
8
+ const getTokens = useCallback(async () => {
9
+ if (!isInitialized) {
10
+ throw new Error('SDK not initialized. Call initialize() first.');
11
+ }
12
+ if (!tokens?.getTokens) {
13
+ console.warn('getTokens method not available');
14
+ return [];
15
+ }
16
+ try {
17
+ const result = await tokens.getTokens();
18
+ console.log('✅ Tokens fetched successfully:', result);
19
+ return result;
20
+ }
21
+ catch (error) {
22
+ console.error('❌ Failed to fetch tokens:', error);
23
+ throw error;
24
+ }
25
+ }, [tokens]);
26
+ const getTokenById = useCallback(async (tokenId) => {
27
+ if (!isInitialized) {
28
+ throw new Error('SDK not initialized. Call initialize() first.');
29
+ }
30
+ if (!tokens?.getTokenById) {
31
+ throw new Error('getTokenById method not available');
32
+ }
33
+ try {
34
+ const result = await tokens.getTokenById(tokenId);
35
+ console.log('✅ Token fetched successfully:', result);
36
+ return result;
37
+ }
38
+ catch (error) {
39
+ console.error('❌ Failed to fetch token:', error);
40
+ throw error;
41
+ }
42
+ }, [tokens]);
43
+ return {
44
+ getTokens,
45
+ getTokenById,
46
+ isAvailable: isInitialized && !!tokens,
47
+ };
48
+ };
@@ -0,0 +1,7 @@
1
+ export declare const useTransactions: () => {
2
+ createTransaction: (request: any) => Promise<any>;
3
+ getTransactionById: (transactionId: string) => Promise<any>;
4
+ getTransactionHistory: (filters?: any) => Promise<any>;
5
+ isAvailable: boolean;
6
+ };
7
+ //# sourceMappingURL=useTransactions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTransactions.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactions.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe;iCAO4B,GAAG;wCA+BI,MAAM;sCAkBR,GAAG;;CAyB/D,CAAC"}