@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,161 +1,161 @@
1
- // React Native polyfills for crypto and Web3 functionality
2
- // Consolidated "batteries included" approach for React Native SDK
3
-
4
- // CRITICAL: URL polyfill must be imported FIRST before any other code
5
- // This provides full URLSearchParams support for React Native
6
- import 'react-native-url-polyfill/auto';
7
-
8
- import { Buffer } from 'buffer';
9
- import { setupWeb3InstanceofPolyfill } from './web3-polyfills';
10
-
11
- // Initialize React Native polyfills
12
- export const initializeReactNativePolyfills = (): boolean => {
13
- try {
14
- // Set up basic global environment
15
- (global as any).global = global;
16
- (global as any).Buffer = Buffer;
17
-
18
- // Add process if missing
19
- if (typeof global !== 'undefined' && !global.process) {
20
- global.process = {
21
- env: {},
22
- version: '16.0.0',
23
- nextTick: (callback: () => void) => setTimeout(callback, 0)
24
- } as any;
25
- }
26
-
27
- // Initialize crypto polyfills (CRITICAL for Web3)
28
- require('react-native-get-random-values');
29
-
30
- // Crypto polyfill for better Web3 compatibility
31
- if (typeof global !== 'undefined' && !(global as any).crypto) {
32
- (global as any).crypto = {
33
- getRandomValues: (arr: any) => {
34
- require('react-native-get-random-values');
35
- return (global as any).crypto.getRandomValues(arr);
36
- },
37
- randomUUID: () => {
38
- const hex = '0123456789abcdef';
39
- let result = '';
40
- for (let i = 0; i < 32; i++) {
41
- result += hex[Math.floor(Math.random() * 16)];
42
- if (i === 7 || i === 11 || i === 15 || i === 19) result += '-';
43
- }
44
- return result;
45
- }
46
- };
47
- }
48
-
49
- // URL polyfill is handled by react-native-url-polyfill/auto import at top
50
-
51
- // Add btoa/atob polyfills for Web3 compatibility
52
- if (typeof global !== 'undefined') {
53
- if (!(global as any).btoa) {
54
- (global as any).btoa = (str: string) => Buffer.from(str, 'binary').toString('base64');
55
- }
56
- if (!(global as any).atob) {
57
- (global as any).atob = (str: string) => Buffer.from(str, 'base64').toString('binary');
58
- }
59
- }
60
-
61
- // EventTarget polyfill for Web3 providers
62
- if (typeof global !== 'undefined' && !(global as any).EventTarget) {
63
- (global as any).EventTarget = class EventTarget {
64
- private listeners: { [key: string]: ((...args: any[]) => void)[] } = {};
65
-
66
- addEventListener(type: string, listener: (...args: any[]) => void) {
67
- if (!this.listeners[type]) {
68
- this.listeners[type] = [];
69
- }
70
- this.listeners[type].push(listener);
71
- }
72
-
73
- removeEventListener(type: string, listener: (...args: any[]) => void) {
74
- if (this.listeners[type]) {
75
- const index = this.listeners[type].indexOf(listener);
76
- if (index > -1) {
77
- this.listeners[type].splice(index, 1);
78
- }
79
- }
80
- }
81
-
82
- dispatchEvent(event: any) {
83
- if (this.listeners[event.type]) {
84
- this.listeners[event.type].forEach(listener => {
85
- listener(event);
86
- });
87
- }
88
- return true;
89
- }
90
- };
91
- }
92
-
93
- // Performance polyfill
94
- if (typeof global !== 'undefined' && !(global as any).performance) {
95
- (global as any).performance = {
96
- now: () => Date.now(),
97
- timeOrigin: Date.now()
98
- };
99
- }
100
-
101
- // Stream polyfill (minimal)
102
- if (typeof global !== 'undefined' && !(global as any).stream) {
103
- (global as any).stream = {
104
- Readable: class {},
105
- Writable: class {},
106
- Transform: class {}
107
- };
108
- }
109
-
110
- // Web3 specific polyfills for instanceof issues
111
- setupWeb3Polyfills();
112
- setupWeb3InstanceofPolyfill();
113
-
114
- return true;
115
- } catch (error) {
116
- console.warn('[PERS SDK] Failed to initialize some polyfills:', error);
117
- return true;
118
- }
119
- };
120
-
121
- // Web3 specific polyfills to fix instanceof issues
122
- const setupWeb3Polyfills = () => {
123
- try {
124
- // Ensure Symbol polyfill for constructor comparison
125
- if (typeof global !== 'undefined' && !(global as any).Symbol) {
126
- (global as any).Symbol = {
127
- for: (key: string) => `Symbol(${key})`,
128
- iterator: '@@iterator',
129
- toStringTag: '@@toStringTag'
130
- };
131
- }
132
-
133
- // Add constructor.name polyfill for better class detection
134
- if (typeof global !== 'undefined' && typeof Function !== 'undefined') {
135
- const originalToString = Function.prototype.toString;
136
- if (!Function.prototype.name) {
137
- Object.defineProperty(Function.prototype, 'name', {
138
- get: function() {
139
- const match = originalToString.call(this).match(/function\s*([^(]*)/);
140
- return match ? match[1] : '';
141
- }
142
- });
143
- }
144
- }
145
-
146
- // Module resolution enhancement for Web3
147
- if (typeof global !== 'undefined') {
148
- // Store reference to help with instanceof checks
149
- (global as any).__PERS_SDK_WEB3_POLYFILLS__ = true;
150
- }
151
-
152
- } catch (error) {
153
- console.warn('[PERS SDK] Web3 polyfills setup failed:', error);
154
- }
155
- };
156
-
157
- // Auto-initialize polyfills when SDK is imported
158
- initializeReactNativePolyfills();
159
-
160
- // Export utilities for advanced usage
1
+ // React Native polyfills for crypto and Web3 functionality
2
+ // Consolidated "batteries included" approach for React Native SDK
3
+
4
+ // CRITICAL: URL polyfill must be imported FIRST before any other code
5
+ // This provides full URLSearchParams support for React Native
6
+ import 'react-native-url-polyfill/auto';
7
+
8
+ import { Buffer } from 'buffer';
9
+ import { setupWeb3InstanceofPolyfill } from './web3-polyfills';
10
+
11
+ // Initialize React Native polyfills
12
+ export const initializeReactNativePolyfills = (): boolean => {
13
+ try {
14
+ // Set up basic global environment
15
+ (global as any).global = global;
16
+ (global as any).Buffer = Buffer;
17
+
18
+ // Add process if missing
19
+ if (typeof global !== 'undefined' && !global.process) {
20
+ global.process = {
21
+ env: {},
22
+ version: '16.0.0',
23
+ nextTick: (callback: () => void) => setTimeout(callback, 0)
24
+ } as any;
25
+ }
26
+
27
+ // Initialize crypto polyfills (CRITICAL for Web3)
28
+ require('react-native-get-random-values');
29
+
30
+ // Crypto polyfill for better Web3 compatibility
31
+ if (typeof global !== 'undefined' && !(global as any).crypto) {
32
+ (global as any).crypto = {
33
+ getRandomValues: (arr: any) => {
34
+ require('react-native-get-random-values');
35
+ return (global as any).crypto.getRandomValues(arr);
36
+ },
37
+ randomUUID: () => {
38
+ const hex = '0123456789abcdef';
39
+ let result = '';
40
+ for (let i = 0; i < 32; i++) {
41
+ result += hex[Math.floor(Math.random() * 16)];
42
+ if (i === 7 || i === 11 || i === 15 || i === 19) result += '-';
43
+ }
44
+ return result;
45
+ }
46
+ };
47
+ }
48
+
49
+ // URL polyfill is handled by react-native-url-polyfill/auto import at top
50
+
51
+ // Add btoa/atob polyfills for Web3 compatibility
52
+ if (typeof global !== 'undefined') {
53
+ if (!(global as any).btoa) {
54
+ (global as any).btoa = (str: string) => Buffer.from(str, 'binary').toString('base64');
55
+ }
56
+ if (!(global as any).atob) {
57
+ (global as any).atob = (str: string) => Buffer.from(str, 'base64').toString('binary');
58
+ }
59
+ }
60
+
61
+ // EventTarget polyfill for Web3 providers
62
+ if (typeof global !== 'undefined' && !(global as any).EventTarget) {
63
+ (global as any).EventTarget = class EventTarget {
64
+ private listeners: { [key: string]: ((...args: any[]) => void)[] } = {};
65
+
66
+ addEventListener(type: string, listener: (...args: any[]) => void) {
67
+ if (!this.listeners[type]) {
68
+ this.listeners[type] = [];
69
+ }
70
+ this.listeners[type].push(listener);
71
+ }
72
+
73
+ removeEventListener(type: string, listener: (...args: any[]) => void) {
74
+ if (this.listeners[type]) {
75
+ const index = this.listeners[type].indexOf(listener);
76
+ if (index > -1) {
77
+ this.listeners[type].splice(index, 1);
78
+ }
79
+ }
80
+ }
81
+
82
+ dispatchEvent(event: any) {
83
+ if (this.listeners[event.type]) {
84
+ this.listeners[event.type].forEach(listener => {
85
+ listener(event);
86
+ });
87
+ }
88
+ return true;
89
+ }
90
+ };
91
+ }
92
+
93
+ // Performance polyfill
94
+ if (typeof global !== 'undefined' && !(global as any).performance) {
95
+ (global as any).performance = {
96
+ now: () => Date.now(),
97
+ timeOrigin: Date.now()
98
+ };
99
+ }
100
+
101
+ // Stream polyfill (minimal)
102
+ if (typeof global !== 'undefined' && !(global as any).stream) {
103
+ (global as any).stream = {
104
+ Readable: class {},
105
+ Writable: class {},
106
+ Transform: class {}
107
+ };
108
+ }
109
+
110
+ // Web3 specific polyfills for instanceof issues
111
+ setupWeb3Polyfills();
112
+ setupWeb3InstanceofPolyfill();
113
+
114
+ return true;
115
+ } catch (error) {
116
+ console.warn('[PERS SDK] Failed to initialize some polyfills:', error);
117
+ return true;
118
+ }
119
+ };
120
+
121
+ // Web3 specific polyfills to fix instanceof issues
122
+ const setupWeb3Polyfills = () => {
123
+ try {
124
+ // Ensure Symbol polyfill for constructor comparison
125
+ if (typeof global !== 'undefined' && !(global as any).Symbol) {
126
+ (global as any).Symbol = {
127
+ for: (key: string) => `Symbol(${key})`,
128
+ iterator: '@@iterator',
129
+ toStringTag: '@@toStringTag'
130
+ };
131
+ }
132
+
133
+ // Add constructor.name polyfill for better class detection
134
+ if (typeof global !== 'undefined' && typeof Function !== 'undefined') {
135
+ const originalToString = Function.prototype.toString;
136
+ if (!Function.prototype.name) {
137
+ Object.defineProperty(Function.prototype, 'name', {
138
+ get: function() {
139
+ const match = originalToString.call(this).match(/function\s*([^(]*)/);
140
+ return match ? match[1] : '';
141
+ }
142
+ });
143
+ }
144
+ }
145
+
146
+ // Module resolution enhancement for Web3
147
+ if (typeof global !== 'undefined') {
148
+ // Store reference to help with instanceof checks
149
+ (global as any).__PERS_SDK_WEB3_POLYFILLS__ = true;
150
+ }
151
+
152
+ } catch (error) {
153
+ console.warn('[PERS SDK] Web3 polyfills setup failed:', error);
154
+ }
155
+ };
156
+
157
+ // Auto-initialize polyfills when SDK is imported
158
+ initializeReactNativePolyfills();
159
+
160
+ // Export utilities for advanced usage
161
161
  export { createSafeWeb3Check } from './web3-polyfills';
@@ -1,98 +1,98 @@
1
- /**
2
- * Web3 specific polyfills for React Native
3
- * Addresses instanceof and constructor issues in React Native environments
4
- */
5
-
6
- export const setupWeb3InstanceofPolyfill = () => {
7
- try {
8
- // Store the original instanceof behavior
9
- const originalInstanceof = Function.prototype[Symbol.hasInstance];
10
-
11
- // Override Symbol.hasInstance for better Web3 detection in React Native
12
- if (typeof global !== 'undefined' && global.Symbol && global.Symbol.hasInstance) {
13
- // Create a safer instanceof check for Web3
14
- const createSafeInstanceofCheck = (constructor: any) => {
15
- return function(instance: any) {
16
- // Try the original check first
17
- try {
18
- if (originalInstanceof) {
19
- return originalInstanceof.call(constructor, instance);
20
- }
21
- return instance instanceof constructor;
22
- } catch (error) {
23
- // Fallback to constructor and duck-typing checks
24
- if (!instance || typeof instance !== 'object') {
25
- return false;
26
- }
27
-
28
- // Check constructor name
29
- if (instance.constructor && instance.constructor.name === constructor.name) {
30
- return true;
31
- }
32
-
33
- // Check constructor reference
34
- if (instance.constructor === constructor) {
35
- return true;
36
- }
37
-
38
- // For Web3 specifically, check characteristic properties
39
- if (constructor.name === 'Web3' &&
40
- 'currentProvider' in instance &&
41
- 'eth' in instance &&
42
- 'utils' in instance) {
43
- return true;
44
- }
45
-
46
- return false;
47
- }
48
- };
49
- };
50
-
51
- // Apply the polyfill to global scope for dynamic loading
52
- (global as any).__PERS_SDK_SAFE_INSTANCEOF__ = createSafeInstanceofCheck;
53
-
54
- }
55
-
56
- return true;
57
- } catch (error) {
58
- console.warn('[PERS SDK] Web3 instanceof polyfill setup failed:', error);
59
- return false;
60
- }
61
- };
62
-
63
- export const createSafeWeb3Check = (provider: unknown): boolean => {
64
- if (!provider || typeof provider !== 'object') {
65
- return false;
66
- }
67
-
68
- try {
69
- // Method 1: Check if it's already a Web3 instance using multiple approaches
70
- const providerObj = provider as any;
71
-
72
- // Constructor name check
73
- if (providerObj.constructor?.name === 'Web3') {
74
- return true;
75
- }
76
-
77
- // Duck typing for Web3 properties
78
- if ('currentProvider' in providerObj &&
79
- 'eth' in providerObj &&
80
- 'utils' in providerObj &&
81
- typeof providerObj.eth === 'object') {
82
- return true;
83
- }
84
-
85
- // Check for Web3 version property
86
- if ('version' in providerObj && typeof providerObj.version === 'string') {
87
- return true;
88
- }
89
-
90
- return false;
91
- } catch (error) {
92
- console.warn('Safe Web3 check failed:', error);
93
- return false;
94
- }
95
- };
96
-
97
- // Auto-initialize
1
+ /**
2
+ * Web3 specific polyfills for React Native
3
+ * Addresses instanceof and constructor issues in React Native environments
4
+ */
5
+
6
+ export const setupWeb3InstanceofPolyfill = () => {
7
+ try {
8
+ // Store the original instanceof behavior
9
+ const originalInstanceof = Function.prototype[Symbol.hasInstance];
10
+
11
+ // Override Symbol.hasInstance for better Web3 detection in React Native
12
+ if (typeof global !== 'undefined' && global.Symbol && global.Symbol.hasInstance) {
13
+ // Create a safer instanceof check for Web3
14
+ const createSafeInstanceofCheck = (constructor: any) => {
15
+ return function(instance: any) {
16
+ // Try the original check first
17
+ try {
18
+ if (originalInstanceof) {
19
+ return originalInstanceof.call(constructor, instance);
20
+ }
21
+ return instance instanceof constructor;
22
+ } catch (error) {
23
+ // Fallback to constructor and duck-typing checks
24
+ if (!instance || typeof instance !== 'object') {
25
+ return false;
26
+ }
27
+
28
+ // Check constructor name
29
+ if (instance.constructor && instance.constructor.name === constructor.name) {
30
+ return true;
31
+ }
32
+
33
+ // Check constructor reference
34
+ if (instance.constructor === constructor) {
35
+ return true;
36
+ }
37
+
38
+ // For Web3 specifically, check characteristic properties
39
+ if (constructor.name === 'Web3' &&
40
+ 'currentProvider' in instance &&
41
+ 'eth' in instance &&
42
+ 'utils' in instance) {
43
+ return true;
44
+ }
45
+
46
+ return false;
47
+ }
48
+ };
49
+ };
50
+
51
+ // Apply the polyfill to global scope for dynamic loading
52
+ (global as any).__PERS_SDK_SAFE_INSTANCEOF__ = createSafeInstanceofCheck;
53
+
54
+ }
55
+
56
+ return true;
57
+ } catch (error) {
58
+ console.warn('[PERS SDK] Web3 instanceof polyfill setup failed:', error);
59
+ return false;
60
+ }
61
+ };
62
+
63
+ export const createSafeWeb3Check = (provider: unknown): boolean => {
64
+ if (!provider || typeof provider !== 'object') {
65
+ return false;
66
+ }
67
+
68
+ try {
69
+ // Method 1: Check if it's already a Web3 instance using multiple approaches
70
+ const providerObj = provider as any;
71
+
72
+ // Constructor name check
73
+ if (providerObj.constructor?.name === 'Web3') {
74
+ return true;
75
+ }
76
+
77
+ // Duck typing for Web3 properties
78
+ if ('currentProvider' in providerObj &&
79
+ 'eth' in providerObj &&
80
+ 'utils' in providerObj &&
81
+ typeof providerObj.eth === 'object') {
82
+ return true;
83
+ }
84
+
85
+ // Check for Web3 version property
86
+ if ('version' in providerObj && typeof providerObj.version === 'string') {
87
+ return true;
88
+ }
89
+
90
+ return false;
91
+ } catch (error) {
92
+ console.warn('Safe Web3 check failed:', error);
93
+ return false;
94
+ }
95
+ };
96
+
97
+ // Auto-initialize
98
98
  setupWeb3InstanceofPolyfill();