@explorins/pers-sdk-react-native 2.2.0-alpha.2 → 2.2.0-alpha.3

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 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');
@@ -19455,30 +19454,54 @@ function warnIfProblematicEnvironment(feature) {
19455
19454
  * Bundler-agnostic AsyncStorage implementation for mobile platforms
19456
19455
  */
19457
19456
  /**
19458
- * Bundler-agnostic AsyncStorage wrapper
19459
- * Handles different module resolution patterns across bundlers (Metro, Webpack, Rollup, etc.)
19457
+ * Dynamically resolve AsyncStorage at runtime to avoid bundler conflicts
19458
+ *
19459
+ * When the SDK is pre-bundled (e.g., with Rollup) and then consumed by an app
19460
+ * that uses Metro, the static import can get resolved incorrectly due to module
19461
+ * hoisting and namespace collisions.
19462
+ *
19463
+ * By using require() at runtime, we ensure we get the actual AsyncStorage
19464
+ * from the app's node_modules, not a bundled/mangled version.
19460
19465
  */
19461
- class BundlerAgnosticAsyncStorage {
19462
- constructor(asyncStorageModule) {
19463
- // Try different import patterns to handle various bundlers
19464
- if (asyncStorageModule?.default?.getItem) {
19465
- // Metro/Webpack pattern: { default: { getItem, setItem, ... } }
19466
- this.storage = asyncStorageModule.default;
19467
- }
19468
- else if (asyncStorageModule?.getItem) {
19469
- // Direct export pattern: { getItem, setItem, ... }
19470
- this.storage = asyncStorageModule;
19466
+ function getAsyncStorage() {
19467
+ // Use require() to get the module at runtime
19468
+ // This bypasses any bundler transformations that might have corrupted the import
19469
+ try {
19470
+ // Try default export first (Metro pattern)
19471
+ const module = require('@react-native-async-storage/async-storage');
19472
+ // Log for debugging what we actually received
19473
+ const hasGetItem = typeof module?.getItem === 'function';
19474
+ const hasDefaultGetItem = typeof module?.default?.getItem === 'function';
19475
+ console.log('[AsyncStorage] Module resolution:', {
19476
+ hasGetItem,
19477
+ hasDefaultGetItem,
19478
+ moduleType: typeof module,
19479
+ keys: module ? Object.keys(module).slice(0, 10) : []
19480
+ });
19481
+ if (hasDefaultGetItem) {
19482
+ return module.default;
19471
19483
  }
19472
- else if (typeof asyncStorageModule === 'function') {
19473
- // Function export pattern (some bundlers)
19474
- this.storage = asyncStorageModule();
19484
+ else if (hasGetItem) {
19485
+ return module;
19475
19486
  }
19476
19487
  else {
19477
- // Log the structure for debugging
19478
- console.error('[BundlerAgnosticAsyncStorage] Unknown AsyncStorage structure:', asyncStorageModule);
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.');
19488
+ throw new Error('AsyncStorage module found but missing getItem method');
19481
19489
  }
19490
+ }
19491
+ catch (error) {
19492
+ console.error('[AsyncStorage] Failed to dynamically require:', error);
19493
+ throw new Error('Failed to load @react-native-async-storage/async-storage. ' +
19494
+ 'Make sure it is installed and properly linked.');
19495
+ }
19496
+ }
19497
+ /**
19498
+ * Bundler-agnostic AsyncStorage wrapper
19499
+ * Now uses runtime require() to avoid bundler conflicts
19500
+ */
19501
+ class BundlerAgnosticAsyncStorage {
19502
+ constructor() {
19503
+ // Get AsyncStorage at runtime, not from a potentially corrupted static import
19504
+ this.storage = getAsyncStorage();
19482
19505
  // Validate that we have the required methods
19483
19506
  const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
19484
19507
  const missingMethods = requiredMethods.filter(method => typeof this.storage[method] !== 'function');
@@ -19514,7 +19537,8 @@ class AsyncStorageTokenStorage {
19514
19537
  this.keyPrefix = keyPrefix;
19515
19538
  try {
19516
19539
  // Initialize bundler-agnostic AsyncStorage wrapper
19517
- this.asyncStorage = new BundlerAgnosticAsyncStorage(AsyncStorage);
19540
+ // No longer passes the module - it uses runtime require() internally
19541
+ this.asyncStorage = new BundlerAgnosticAsyncStorage();
19518
19542
  }
19519
19543
  catch (error) {
19520
19544
  console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);