@explorins/pers-sdk-react-native 2.2.0-alpha.3 → 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 +40 -30
- 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 +40 -30
- package/package.json +1 -1
- package/src/storage/async-storage-token-storage.ts +49 -33
package/dist/index.js
CHANGED
|
@@ -19451,52 +19451,62 @@ function warnIfProblematicEnvironment(feature) {
|
|
|
19451
19451
|
/**
|
|
19452
19452
|
* AsyncStorage Token Storage for React Native Mobile Platforms
|
|
19453
19453
|
*
|
|
19454
|
-
* 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
|
+
* ```
|
|
19455
19464
|
*/
|
|
19456
19465
|
/**
|
|
19457
|
-
*
|
|
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.
|
|
19466
|
+
* Get AsyncStorage from the global that the app must set.
|
|
19462
19467
|
*
|
|
19463
|
-
*
|
|
19464
|
-
*
|
|
19468
|
+
* This bypasses all bundler resolution issues by having the app
|
|
19469
|
+
* explicitly provide the AsyncStorage module via a global variable.
|
|
19465
19470
|
*/
|
|
19466
19471
|
function getAsyncStorage() {
|
|
19467
|
-
//
|
|
19468
|
-
|
|
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;
|
|
19479
|
+
}
|
|
19480
|
+
else if (typeof module?.default?.getItem === 'function') {
|
|
19481
|
+
console.log('[AsyncStorage] Using global.AsyncStorageModule.default');
|
|
19482
|
+
return module.default;
|
|
19483
|
+
}
|
|
19484
|
+
}
|
|
19485
|
+
// Fallback: try require (may not work due to bundler conflicts)
|
|
19469
19486
|
try {
|
|
19470
|
-
//
|
|
19487
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
19471
19488
|
const module = require('@react-native-async-storage/async-storage');
|
|
19472
|
-
|
|
19473
|
-
|
|
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) {
|
|
19489
|
+
if (typeof module?.default?.getItem === 'function') {
|
|
19490
|
+
console.log('[AsyncStorage] Fallback: using require().default');
|
|
19482
19491
|
return module.default;
|
|
19483
19492
|
}
|
|
19484
|
-
else if (
|
|
19493
|
+
else if (typeof module?.getItem === 'function') {
|
|
19494
|
+
console.log('[AsyncStorage] Fallback: using require() direct');
|
|
19485
19495
|
return module;
|
|
19486
19496
|
}
|
|
19487
|
-
else {
|
|
19488
|
-
throw new Error('AsyncStorage module found but missing getItem method');
|
|
19489
|
-
}
|
|
19490
19497
|
}
|
|
19491
|
-
catch (
|
|
19492
|
-
|
|
19493
|
-
throw new Error('Failed to load @react-native-async-storage/async-storage. ' +
|
|
19494
|
-
'Make sure it is installed and properly linked.');
|
|
19498
|
+
catch (e) {
|
|
19499
|
+
// Ignore require errors
|
|
19495
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.');
|
|
19496
19506
|
}
|
|
19497
19507
|
/**
|
|
19498
19508
|
* Bundler-agnostic AsyncStorage wrapper
|
|
19499
|
-
*
|
|
19509
|
+
* Uses global injection to avoid bundler conflicts
|
|
19500
19510
|
*/
|
|
19501
19511
|
class BundlerAgnosticAsyncStorage {
|
|
19502
19512
|
constructor() {
|