@explorins/pers-sdk-react-native 1.5.18 → 1.5.21
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.
- package/README.md +336 -234
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useAnalytics.d.ts +6 -2
- package/dist/hooks/useAnalytics.d.ts.map +1 -1
- package/dist/hooks/useAuth.d.ts +1 -1
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +7 -7
- package/dist/hooks/useRedemptions.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.js +4 -4
- package/dist/hooks/useTenants.d.ts.map +1 -1
- package/dist/hooks/useTenants.js +0 -1
- package/dist/hooks/useTransactionSigner.d.ts +186 -53
- package/dist/hooks/useTransactionSigner.d.ts.map +1 -1
- package/dist/hooks/useTransactionSigner.js +285 -102
- package/dist/hooks/useTransactions.d.ts +2 -2
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +9 -10
- package/dist/hooks/useWeb3.d.ts +8 -2
- package/dist/hooks/useWeb3.d.ts.map +1 -1
- package/dist/index.d.ts +211 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21061 -18475
- package/dist/index.js.map +1 -1
- package/dist/providers/PersSDKProvider.d.ts +2 -8
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +16 -31
- package/dist/providers/react-native-auth-provider.d.ts +24 -36
- package/dist/providers/react-native-auth-provider.d.ts.map +1 -1
- package/dist/providers/react-native-auth-provider.js +35 -146
- package/dist/providers/react-native-http-client.d.ts +15 -0
- package/dist/providers/react-native-http-client.d.ts.map +1 -1
- package/dist/storage/async-storage-token-storage.d.ts +22 -0
- package/dist/storage/async-storage-token-storage.d.ts.map +1 -0
- package/dist/storage/async-storage-token-storage.js +113 -0
- package/package.json +16 -11
- package/src/hooks/index.ts +1 -1
- package/src/hooks/useAnalytics.ts +6 -2
- package/src/hooks/useAuth.ts +7 -7
- package/src/hooks/useRedemptions.ts +5 -7
- package/src/hooks/useTenants.ts +0 -1
- package/src/hooks/useTransactionSigner.ts +322 -166
- package/src/hooks/useTransactions.ts +12 -11
- package/src/hooks/useWeb3.ts +8 -1
- package/src/index.ts +243 -7
- package/src/providers/PersSDKProvider.tsx +21 -40
- package/src/providers/react-native-auth-provider.ts +58 -176
- package/src/providers/react-native-http-client.ts +15 -0
- package/src/storage/async-storage-token-storage.ts +133 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncStorage Token Storage for React Native Mobile Platforms
|
|
3
|
+
*
|
|
4
|
+
* Bundler-agnostic AsyncStorage implementation for mobile platforms
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
8
|
+
import type { TokenStorage } from '@explorins/pers-sdk/core';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Bundler-agnostic AsyncStorage wrapper
|
|
12
|
+
* Handles different module resolution patterns across bundlers (Metro, Webpack, Rollup, etc.)
|
|
13
|
+
*/
|
|
14
|
+
class BundlerAgnosticAsyncStorage {
|
|
15
|
+
private storage: any;
|
|
16
|
+
|
|
17
|
+
constructor(asyncStorageModule: any) {
|
|
18
|
+
// Try different import patterns to handle various bundlers
|
|
19
|
+
if (asyncStorageModule?.default?.getItem) {
|
|
20
|
+
// Metro/Webpack pattern: { default: { getItem, setItem, ... } }
|
|
21
|
+
this.storage = asyncStorageModule.default;
|
|
22
|
+
} else if (asyncStorageModule?.getItem) {
|
|
23
|
+
// Direct export pattern: { getItem, setItem, ... }
|
|
24
|
+
this.storage = asyncStorageModule;
|
|
25
|
+
} else if (typeof asyncStorageModule === 'function') {
|
|
26
|
+
// Function export pattern (some bundlers)
|
|
27
|
+
this.storage = asyncStorageModule();
|
|
28
|
+
} else {
|
|
29
|
+
// Log the structure for debugging
|
|
30
|
+
console.error('[BundlerAgnosticAsyncStorage] Unknown AsyncStorage structure:', asyncStorageModule);
|
|
31
|
+
throw new Error(
|
|
32
|
+
'AsyncStorage methods not found. Expected structure with getItem/setItem methods. ' +
|
|
33
|
+
'Make sure @react-native-async-storage/async-storage is properly installed.'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Validate that we have the required methods
|
|
38
|
+
const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
|
|
39
|
+
const missingMethods = requiredMethods.filter(method => typeof this.storage[method] !== 'function');
|
|
40
|
+
|
|
41
|
+
if (missingMethods.length > 0) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`AsyncStorage missing required methods: ${missingMethods.join(', ')}. ` +
|
|
44
|
+
'Ensure @react-native-async-storage/async-storage is properly installed and compatible.'
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async getItem(key: string): Promise<string | null> {
|
|
50
|
+
return this.storage.getItem(key);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
54
|
+
return this.storage.setItem(key, value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async removeItem(key: string): Promise<void> {
|
|
58
|
+
return this.storage.removeItem(key);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getAllKeys(): Promise<readonly string[]> {
|
|
62
|
+
return this.storage.getAllKeys();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async multiRemove(keys: string[]): Promise<void> {
|
|
66
|
+
return this.storage.multiRemove(keys);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* AsyncStorage implementation for mobile platforms
|
|
72
|
+
*
|
|
73
|
+
* This class is only used on mobile platforms (iOS/Android).
|
|
74
|
+
* Web platforms use LocalStorageTokenStorage from core SDK.
|
|
75
|
+
*/
|
|
76
|
+
export class AsyncStorageTokenStorage implements TokenStorage {
|
|
77
|
+
private keyPrefix: string;
|
|
78
|
+
private asyncStorage: BundlerAgnosticAsyncStorage;
|
|
79
|
+
|
|
80
|
+
constructor(keyPrefix: string = 'pers_tokens_') {
|
|
81
|
+
this.keyPrefix = keyPrefix;
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
// Initialize bundler-agnostic AsyncStorage wrapper
|
|
85
|
+
this.asyncStorage = new BundlerAgnosticAsyncStorage(AsyncStorage);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);
|
|
88
|
+
throw new Error(
|
|
89
|
+
'Failed to initialize AsyncStorage. Make sure @react-native-async-storage/async-storage is installed and ' +
|
|
90
|
+
'this code is running on a React Native mobile platform (not web).'
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async set(key: string, value: string): Promise<void> {
|
|
96
|
+
try {
|
|
97
|
+
await this.asyncStorage.setItem(`${this.keyPrefix}${key}`, value);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error(`Failed to store token ${key}:`, error);
|
|
100
|
+
throw new Error(`Token storage failed: ${error}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async get(key: string): Promise<string | null> {
|
|
105
|
+
try {
|
|
106
|
+
return await this.asyncStorage.getItem(`${this.keyPrefix}${key}`);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(`Failed to retrieve token ${key}:`, error);
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async remove(key: string): Promise<void> {
|
|
114
|
+
try {
|
|
115
|
+
await this.asyncStorage.removeItem(`${this.keyPrefix}${key}`);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error(`Failed to remove token ${key}:`, error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async clear(): Promise<void> {
|
|
122
|
+
try {
|
|
123
|
+
const allKeys = await this.asyncStorage.getAllKeys();
|
|
124
|
+
const ourKeys = allKeys.filter(key => key.startsWith(this.keyPrefix));
|
|
125
|
+
|
|
126
|
+
if (ourKeys.length > 0) {
|
|
127
|
+
await this.asyncStorage.multiRemove(ourKeys);
|
|
128
|
+
}
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Failed to clear token storage:', error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|