@explorins/pers-sdk-react-native 2.3.7 → 2.3.8

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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1266 -1244
  3. package/dist/__tests__/PersSDKProvider.test.js +33 -0
  4. package/dist/hooks/useBusiness.d.ts +2 -2
  5. package/dist/hooks/useBusiness.d.ts.map +1 -1
  6. package/dist/hooks/useBusiness.js +2 -2
  7. package/dist/hooks/useIPFSUrl.d.ts +3 -3
  8. package/dist/hooks/useIPFSUrl.d.ts.map +1 -1
  9. package/dist/hooks/useIPFSUrl.js +7 -7
  10. package/dist/hooks/useWeb3.js +4 -4
  11. package/dist/index.js +2400 -487
  12. package/dist/index.js.map +1 -1
  13. package/dist/providers/PersSDKProvider.d.ts +4 -0
  14. package/dist/providers/PersSDKProvider.d.ts.map +1 -1
  15. package/dist/providers/PersSDKProvider.js +14 -0
  16. package/dist/providers/react-native-http-client.d.ts +2 -0
  17. package/dist/providers/react-native-http-client.d.ts.map +1 -1
  18. package/dist/providers/react-native-http-client.js +5 -2
  19. package/dist/storage/rn-secure-storage.d.ts.map +1 -1
  20. package/dist/storage/rn-secure-storage.js +21 -8
  21. package/package.json +3 -3
  22. package/src/__tests__/PersSDKProvider.test.tsx +484 -420
  23. package/src/__tests__/setup.ts +40 -40
  24. package/src/hooks/index.ts +60 -60
  25. package/src/hooks/useAnalytics.ts +327 -327
  26. package/src/hooks/useAuth.ts +265 -265
  27. package/src/hooks/useBookings.ts +191 -191
  28. package/src/hooks/useBusiness.ts +251 -251
  29. package/src/hooks/useCampaigns.ts +500 -500
  30. package/src/hooks/useDonations.ts +66 -66
  31. package/src/hooks/useEvents.ts +372 -372
  32. package/src/hooks/useFiles.ts +155 -155
  33. package/src/hooks/useIPFSUrl.ts +192 -192
  34. package/src/hooks/usePurchases.ts +65 -65
  35. package/src/hooks/useRedemptions.ts +467 -467
  36. package/src/hooks/useTenants.ts +72 -72
  37. package/src/hooks/useTokenBalances.ts +385 -385
  38. package/src/hooks/useTokens.ts +313 -313
  39. package/src/hooks/useTransactionSigner.ts +611 -611
  40. package/src/hooks/useTransactions.ts +299 -299
  41. package/src/hooks/useTriggerSources.ts +301 -301
  42. package/src/hooks/useUserStatus.ts +61 -61
  43. package/src/hooks/useUsers.ts +167 -167
  44. package/src/hooks/useWeb3.ts +355 -355
  45. package/src/index.ts +777 -777
  46. package/src/polyfills/index.ts +160 -160
  47. package/src/polyfills/web3-polyfills.ts +97 -97
  48. package/src/providers/PersSDKProvider.tsx +393 -374
  49. package/src/providers/react-native-auth-provider.ts +110 -110
  50. package/src/providers/react-native-http-client.ts +150 -145
  51. package/src/providers/rn-dpop-provider.ts +190 -190
  52. package/src/storage/async-storage-token-storage.ts +185 -185
  53. package/src/storage/rn-secure-storage.ts +182 -170
  54. package/src/types/react-native-globals.d.ts +45 -45
  55. package/src/utils/index.ts +8 -8
  56. package/src/utils/platform-detection.ts +86 -86
  57. package/dist/index-CzLxqePZ.js +0 -7717
  58. package/dist/index-CzLxqePZ.js.map +0 -1
@@ -1,186 +1,186 @@
1
- /**
2
- * AsyncStorage Token Storage for React Native Mobile Platforms
3
- *
4
- * Bundler-agnostic AsyncStorage implementation for mobile platforms.
5
- *
6
- * IMPORTANT: Due to bundler conflicts between Rollup (SDK) and Metro (app),
7
- * the consuming app MUST set global.AsyncStorageModule before using this SDK:
8
- *
9
- * ```javascript
10
- * // In your app's index.js, BEFORE importing the SDK:
11
- * import AsyncStorage from '@react-native-async-storage/async-storage';
12
- * global.AsyncStorageModule = AsyncStorage;
13
- * ```
14
- */
15
-
16
- import type { TokenStorage } from '@explorins/pers-sdk/core';
17
-
18
- // Declare global type for TypeScript
19
- declare global {
20
- var AsyncStorageModule: any;
21
- }
22
-
23
- /**
24
- * Get AsyncStorage from the global that the app must set.
25
- *
26
- * This bypasses all bundler resolution issues by having the app
27
- * explicitly provide the AsyncStorage module via a global variable.
28
- */
29
- function getAsyncStorage(): any {
30
- // Check if the app has set the global
31
- if (global.AsyncStorageModule) {
32
- const module = global.AsyncStorageModule;
33
-
34
- // Validate it has the expected methods
35
- if (typeof module?.getItem === 'function') {
36
- console.log('[AsyncStorage] Using global.AsyncStorageModule (direct)');
37
- return module;
38
- } else if (typeof module?.default?.getItem === 'function') {
39
- console.log('[AsyncStorage] Using global.AsyncStorageModule.default');
40
- return module.default;
41
- }
42
- }
43
-
44
- // Fallback: try require (may not work due to bundler conflicts)
45
- try {
46
- // eslint-disable-next-line @typescript-eslint/no-var-requires
47
- const module = require('@react-native-async-storage/async-storage');
48
-
49
- if (typeof module?.default?.getItem === 'function') {
50
- console.log('[AsyncStorage] Fallback: using require().default');
51
- return module.default;
52
- } else if (typeof module?.getItem === 'function') {
53
- console.log('[AsyncStorage] Fallback: using require() direct');
54
- return module;
55
- }
56
- } catch (e) {
57
- // Ignore require errors
58
- }
59
-
60
- // If we get here, provide a helpful error
61
- throw new Error(
62
- 'AsyncStorage not available. Please add this to your app\'s index.js BEFORE importing the SDK:\n\n' +
63
- ' import AsyncStorage from \'@react-native-async-storage/async-storage\';\n' +
64
- ' global.AsyncStorageModule = AsyncStorage;\n\n' +
65
- 'This is required due to bundler conflicts between Rollup and Metro.'
66
- );
67
- }
68
-
69
- /**
70
- * Bundler-agnostic AsyncStorage wrapper
71
- * Uses global injection to avoid bundler conflicts
72
- */
73
- class BundlerAgnosticAsyncStorage {
74
- private storage: any;
75
-
76
- constructor() {
77
- // Get AsyncStorage at runtime, not from a potentially corrupted static import
78
- this.storage = getAsyncStorage();
79
-
80
- // Validate that we have the required methods
81
- const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
82
- const missingMethods = requiredMethods.filter(method => typeof this.storage[method] !== 'function');
83
-
84
- if (missingMethods.length > 0) {
85
- throw new Error(
86
- `AsyncStorage missing required methods: ${missingMethods.join(', ')}. ` +
87
- 'Ensure @react-native-async-storage/async-storage is properly installed and compatible.'
88
- );
89
- }
90
- }
91
-
92
- async getItem(key: string): Promise<string | null> {
93
- return this.storage.getItem(key);
94
- }
95
-
96
- async setItem(key: string, value: string): Promise<void> {
97
- return this.storage.setItem(key, value);
98
- }
99
-
100
- async removeItem(key: string): Promise<void> {
101
- return this.storage.removeItem(key);
102
- }
103
-
104
- async getAllKeys(): Promise<readonly string[]> {
105
- return this.storage.getAllKeys();
106
- }
107
-
108
- async multiRemove(keys: string[]): Promise<void> {
109
- return this.storage.multiRemove(keys);
110
- }
111
- }
112
-
113
- /**
114
- * AsyncStorage implementation for mobile platforms
115
- *
116
- * This class is only used on mobile platforms (iOS/Android).
117
- * Web platforms use LocalStorageTokenStorage from core SDK.
118
- */
119
- export class AsyncStorageTokenStorage implements TokenStorage {
120
- private keyPrefix: string;
121
- private asyncStorage: BundlerAgnosticAsyncStorage;
122
-
123
- constructor(keyPrefix: string = 'pers_tokens_') {
124
- this.keyPrefix = keyPrefix;
125
-
126
- try {
127
- // Initialize bundler-agnostic AsyncStorage wrapper
128
- // No longer passes the module - it uses runtime require() internally
129
- this.asyncStorage = new BundlerAgnosticAsyncStorage();
130
- } catch (error) {
131
- console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);
132
- throw new Error(
133
- 'Failed to initialize AsyncStorage. Make sure @react-native-async-storage/async-storage is installed and ' +
134
- 'this code is running on a React Native mobile platform (not web).'
135
- );
136
- }
137
- }
138
-
139
- async set(key: string, value: string): Promise<void> {
140
- try {
141
- const fullKey = `${this.keyPrefix}${key}`;
142
- await this.asyncStorage.setItem(fullKey, value);
143
- console.log(`[AsyncStorage] Token stored: ${key}`);
144
- } catch (error) {
145
- console.error(`[AsyncStorage] Failed to store token ${key}:`, error);
146
- throw new Error(`Token storage failed: ${error}`);
147
- }
148
- }
149
-
150
- async get(key: string): Promise<string | null> {
151
- try {
152
- const fullKey = `${this.keyPrefix}${key}`;
153
- const value = await this.asyncStorage.getItem(fullKey);
154
- console.log(`[AsyncStorage] Token retrieved: ${key} - ${value ? 'exists' : 'null'}`);
155
- return value;
156
- } catch (error) {
157
- console.error(`[AsyncStorage] Failed to retrieve token ${key}:`, error);
158
- return null;
159
- }
160
- }
161
-
162
- async remove(key: string): Promise<void> {
163
- try {
164
- await this.asyncStorage.removeItem(`${this.keyPrefix}${key}`);
165
- } catch (error) {
166
- console.error(`Failed to remove token ${key}:`, error);
167
- }
168
- }
169
-
170
- async clear(): Promise<void> {
171
- try {
172
- const allKeys = await this.asyncStorage.getAllKeys();
173
- const ourKeys = allKeys.filter(key => key.startsWith(this.keyPrefix));
174
-
175
- if (ourKeys.length > 0) {
176
- console.log(`[AsyncStorage] Clearing ${ourKeys.length} token(s):`, ourKeys);
177
- await this.asyncStorage.multiRemove(ourKeys);
178
- console.log('[AsyncStorage] All tokens cleared successfully');
179
- } else {
180
- console.log('[AsyncStorage] No tokens to clear');
181
- }
182
- } catch (error) {
183
- console.error('[AsyncStorage] Failed to clear token storage:', error);
184
- }
185
- }
1
+ /**
2
+ * AsyncStorage Token Storage for React Native Mobile Platforms
3
+ *
4
+ * Bundler-agnostic AsyncStorage implementation for mobile platforms.
5
+ *
6
+ * IMPORTANT: Due to bundler conflicts between Rollup (SDK) and Metro (app),
7
+ * the consuming app MUST set global.AsyncStorageModule before using this SDK:
8
+ *
9
+ * ```javascript
10
+ * // In your app's index.js, BEFORE importing the SDK:
11
+ * import AsyncStorage from '@react-native-async-storage/async-storage';
12
+ * global.AsyncStorageModule = AsyncStorage;
13
+ * ```
14
+ */
15
+
16
+ import type { TokenStorage } from '@explorins/pers-sdk/core';
17
+
18
+ // Declare global type for TypeScript
19
+ declare global {
20
+ var AsyncStorageModule: any;
21
+ }
22
+
23
+ /**
24
+ * Get AsyncStorage from the global that the app must set.
25
+ *
26
+ * This bypasses all bundler resolution issues by having the app
27
+ * explicitly provide the AsyncStorage module via a global variable.
28
+ */
29
+ function getAsyncStorage(): any {
30
+ // Check if the app has set the global
31
+ if (global.AsyncStorageModule) {
32
+ const module = global.AsyncStorageModule;
33
+
34
+ // Validate it has the expected methods
35
+ if (typeof module?.getItem === 'function') {
36
+ console.log('[AsyncStorage] Using global.AsyncStorageModule (direct)');
37
+ return module;
38
+ } else if (typeof module?.default?.getItem === 'function') {
39
+ console.log('[AsyncStorage] Using global.AsyncStorageModule.default');
40
+ return module.default;
41
+ }
42
+ }
43
+
44
+ // Fallback: try require (may not work due to bundler conflicts)
45
+ try {
46
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
47
+ const module = require('@react-native-async-storage/async-storage');
48
+
49
+ if (typeof module?.default?.getItem === 'function') {
50
+ console.log('[AsyncStorage] Fallback: using require().default');
51
+ return module.default;
52
+ } else if (typeof module?.getItem === 'function') {
53
+ console.log('[AsyncStorage] Fallback: using require() direct');
54
+ return module;
55
+ }
56
+ } catch (e) {
57
+ // Ignore require errors
58
+ }
59
+
60
+ // If we get here, provide a helpful error
61
+ throw new Error(
62
+ 'AsyncStorage not available. Please add this to your app\'s index.js BEFORE importing the SDK:\n\n' +
63
+ ' import AsyncStorage from \'@react-native-async-storage/async-storage\';\n' +
64
+ ' global.AsyncStorageModule = AsyncStorage;\n\n' +
65
+ 'This is required due to bundler conflicts between Rollup and Metro.'
66
+ );
67
+ }
68
+
69
+ /**
70
+ * Bundler-agnostic AsyncStorage wrapper
71
+ * Uses global injection to avoid bundler conflicts
72
+ */
73
+ class BundlerAgnosticAsyncStorage {
74
+ private storage: any;
75
+
76
+ constructor() {
77
+ // Get AsyncStorage at runtime, not from a potentially corrupted static import
78
+ this.storage = getAsyncStorage();
79
+
80
+ // Validate that we have the required methods
81
+ const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
82
+ const missingMethods = requiredMethods.filter(method => typeof this.storage[method] !== 'function');
83
+
84
+ if (missingMethods.length > 0) {
85
+ throw new Error(
86
+ `AsyncStorage missing required methods: ${missingMethods.join(', ')}. ` +
87
+ 'Ensure @react-native-async-storage/async-storage is properly installed and compatible.'
88
+ );
89
+ }
90
+ }
91
+
92
+ async getItem(key: string): Promise<string | null> {
93
+ return this.storage.getItem(key);
94
+ }
95
+
96
+ async setItem(key: string, value: string): Promise<void> {
97
+ return this.storage.setItem(key, value);
98
+ }
99
+
100
+ async removeItem(key: string): Promise<void> {
101
+ return this.storage.removeItem(key);
102
+ }
103
+
104
+ async getAllKeys(): Promise<readonly string[]> {
105
+ return this.storage.getAllKeys();
106
+ }
107
+
108
+ async multiRemove(keys: string[]): Promise<void> {
109
+ return this.storage.multiRemove(keys);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * AsyncStorage implementation for mobile platforms
115
+ *
116
+ * This class is only used on mobile platforms (iOS/Android).
117
+ * Web platforms use LocalStorageTokenStorage from core SDK.
118
+ */
119
+ export class AsyncStorageTokenStorage implements TokenStorage {
120
+ private keyPrefix: string;
121
+ private asyncStorage: BundlerAgnosticAsyncStorage;
122
+
123
+ constructor(keyPrefix: string = 'pers_tokens_') {
124
+ this.keyPrefix = keyPrefix;
125
+
126
+ try {
127
+ // Initialize bundler-agnostic AsyncStorage wrapper
128
+ // No longer passes the module - it uses runtime require() internally
129
+ this.asyncStorage = new BundlerAgnosticAsyncStorage();
130
+ } catch (error) {
131
+ console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);
132
+ throw new Error(
133
+ 'Failed to initialize AsyncStorage. Make sure @react-native-async-storage/async-storage is installed and ' +
134
+ 'this code is running on a React Native mobile platform (not web).'
135
+ );
136
+ }
137
+ }
138
+
139
+ async set(key: string, value: string): Promise<void> {
140
+ try {
141
+ const fullKey = `${this.keyPrefix}${key}`;
142
+ await this.asyncStorage.setItem(fullKey, value);
143
+ console.log(`[AsyncStorage] Token stored: ${key}`);
144
+ } catch (error) {
145
+ console.error(`[AsyncStorage] Failed to store token ${key}:`, error);
146
+ throw new Error(`Token storage failed: ${error}`);
147
+ }
148
+ }
149
+
150
+ async get(key: string): Promise<string | null> {
151
+ try {
152
+ const fullKey = `${this.keyPrefix}${key}`;
153
+ const value = await this.asyncStorage.getItem(fullKey);
154
+ console.log(`[AsyncStorage] Token retrieved: ${key} - ${value ? 'exists' : 'null'}`);
155
+ return value;
156
+ } catch (error) {
157
+ console.error(`[AsyncStorage] Failed to retrieve token ${key}:`, error);
158
+ return null;
159
+ }
160
+ }
161
+
162
+ async remove(key: string): Promise<void> {
163
+ try {
164
+ await this.asyncStorage.removeItem(`${this.keyPrefix}${key}`);
165
+ } catch (error) {
166
+ console.error(`Failed to remove token ${key}:`, error);
167
+ }
168
+ }
169
+
170
+ async clear(): Promise<void> {
171
+ try {
172
+ const allKeys = await this.asyncStorage.getAllKeys();
173
+ const ourKeys = allKeys.filter(key => key.startsWith(this.keyPrefix));
174
+
175
+ if (ourKeys.length > 0) {
176
+ console.log(`[AsyncStorage] Clearing ${ourKeys.length} token(s):`, ourKeys);
177
+ await this.asyncStorage.multiRemove(ourKeys);
178
+ console.log('[AsyncStorage] All tokens cleared successfully');
179
+ } else {
180
+ console.log('[AsyncStorage] No tokens to clear');
181
+ }
182
+ } catch (error) {
183
+ console.error('[AsyncStorage] Failed to clear token storage:', error);
184
+ }
185
+ }
186
186
  }