@explorins/pers-sdk-react-native 2.2.0-alpha.2 → 2.2.0-alpha.4
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/dist/index.js +56 -22
- package/dist/index.js.map +1 -1
- package/dist/storage/async-storage-token-storage.d.ts +13 -1
- package/dist/storage/async-storage-token-storage.d.ts.map +1 -1
- package/dist/storage/async-storage-token-storage.js +56 -22
- package/package.json +1 -1
- package/src/storage/async-storage-token-storage.ts +67 -23
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
7
|
var reactNative = require('react-native');
|
|
8
|
-
var AsyncStorage = require('@react-native-async-storage/async-storage');
|
|
9
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
10
9
|
var react = require('react');
|
|
11
10
|
require('@ethereumjs/tx');
|
|
@@ -19452,33 +19451,67 @@ function warnIfProblematicEnvironment(feature) {
|
|
|
19452
19451
|
/**
|
|
19453
19452
|
* AsyncStorage Token Storage for React Native Mobile Platforms
|
|
19454
19453
|
*
|
|
19455
|
-
* Bundler-agnostic AsyncStorage implementation for mobile platforms
|
|
19454
|
+
* Bundler-agnostic AsyncStorage implementation for mobile platforms.
|
|
19455
|
+
*
|
|
19456
|
+
* IMPORTANT: Due to bundler conflicts between Rollup (SDK) and Metro (app),
|
|
19457
|
+
* the consuming app MUST set global.AsyncStorageModule before using this SDK:
|
|
19458
|
+
*
|
|
19459
|
+
* ```javascript
|
|
19460
|
+
* // In your app's index.js, BEFORE importing the SDK:
|
|
19461
|
+
* import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
19462
|
+
* global.AsyncStorageModule = AsyncStorage;
|
|
19463
|
+
* ```
|
|
19456
19464
|
*/
|
|
19457
19465
|
/**
|
|
19458
|
-
*
|
|
19459
|
-
*
|
|
19466
|
+
* Get AsyncStorage from the global that the app must set.
|
|
19467
|
+
*
|
|
19468
|
+
* This bypasses all bundler resolution issues by having the app
|
|
19469
|
+
* explicitly provide the AsyncStorage module via a global variable.
|
|
19460
19470
|
*/
|
|
19461
|
-
|
|
19462
|
-
|
|
19463
|
-
|
|
19464
|
-
|
|
19465
|
-
|
|
19466
|
-
|
|
19471
|
+
function getAsyncStorage() {
|
|
19472
|
+
// Check if the app has set the global
|
|
19473
|
+
if (global.AsyncStorageModule) {
|
|
19474
|
+
const module = global.AsyncStorageModule;
|
|
19475
|
+
// Validate it has the expected methods
|
|
19476
|
+
if (typeof module?.getItem === 'function') {
|
|
19477
|
+
console.log('[AsyncStorage] Using global.AsyncStorageModule (direct)');
|
|
19478
|
+
return module;
|
|
19467
19479
|
}
|
|
19468
|
-
else if (
|
|
19469
|
-
|
|
19470
|
-
|
|
19480
|
+
else if (typeof module?.default?.getItem === 'function') {
|
|
19481
|
+
console.log('[AsyncStorage] Using global.AsyncStorageModule.default');
|
|
19482
|
+
return module.default;
|
|
19471
19483
|
}
|
|
19472
|
-
|
|
19473
|
-
|
|
19474
|
-
|
|
19484
|
+
}
|
|
19485
|
+
// Fallback: try require (may not work due to bundler conflicts)
|
|
19486
|
+
try {
|
|
19487
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
19488
|
+
const module = require('@react-native-async-storage/async-storage');
|
|
19489
|
+
if (typeof module?.default?.getItem === 'function') {
|
|
19490
|
+
console.log('[AsyncStorage] Fallback: using require().default');
|
|
19491
|
+
return module.default;
|
|
19475
19492
|
}
|
|
19476
|
-
else {
|
|
19477
|
-
|
|
19478
|
-
|
|
19479
|
-
throw new Error('AsyncStorage methods not found. Expected structure with getItem/setItem methods. ' +
|
|
19480
|
-
'Make sure @react-native-async-storage/async-storage is properly installed.');
|
|
19493
|
+
else if (typeof module?.getItem === 'function') {
|
|
19494
|
+
console.log('[AsyncStorage] Fallback: using require() direct');
|
|
19495
|
+
return module;
|
|
19481
19496
|
}
|
|
19497
|
+
}
|
|
19498
|
+
catch (e) {
|
|
19499
|
+
// Ignore require errors
|
|
19500
|
+
}
|
|
19501
|
+
// If we get here, provide a helpful error
|
|
19502
|
+
throw new Error('AsyncStorage not available. Please add this to your app\'s index.js BEFORE importing the SDK:\n\n' +
|
|
19503
|
+
' import AsyncStorage from \'@react-native-async-storage/async-storage\';\n' +
|
|
19504
|
+
' global.AsyncStorageModule = AsyncStorage;\n\n' +
|
|
19505
|
+
'This is required due to bundler conflicts between Rollup and Metro.');
|
|
19506
|
+
}
|
|
19507
|
+
/**
|
|
19508
|
+
* Bundler-agnostic AsyncStorage wrapper
|
|
19509
|
+
* Uses global injection to avoid bundler conflicts
|
|
19510
|
+
*/
|
|
19511
|
+
class BundlerAgnosticAsyncStorage {
|
|
19512
|
+
constructor() {
|
|
19513
|
+
// Get AsyncStorage at runtime, not from a potentially corrupted static import
|
|
19514
|
+
this.storage = getAsyncStorage();
|
|
19482
19515
|
// Validate that we have the required methods
|
|
19483
19516
|
const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
|
|
19484
19517
|
const missingMethods = requiredMethods.filter(method => typeof this.storage[method] !== 'function');
|
|
@@ -19514,7 +19547,8 @@ class AsyncStorageTokenStorage {
|
|
|
19514
19547
|
this.keyPrefix = keyPrefix;
|
|
19515
19548
|
try {
|
|
19516
19549
|
// Initialize bundler-agnostic AsyncStorage wrapper
|
|
19517
|
-
|
|
19550
|
+
// No longer passes the module - it uses runtime require() internally
|
|
19551
|
+
this.asyncStorage = new BundlerAgnosticAsyncStorage();
|
|
19518
19552
|
}
|
|
19519
19553
|
catch (error) {
|
|
19520
19554
|
console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);
|