@explorins/pers-sdk-react-native 2.2.0-alpha.1 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"async-storage-token-storage.d.ts","sourceRoot":"","sources":["../../src/storage/async-storage-token-storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AA8D7D;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,YAAY;IAC3D,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,YAAY,CAA8B;gBAEtC,SAAS,GAAE,MAAuB;IAexC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAYxC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAgB7B"}
1
+ {"version":3,"file":"async-storage-token-storage.d.ts","sourceRoot":"","sources":["../../src/storage/async-storage-token-storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AA0F7D;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,YAAY;IAC3D,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,YAAY,CAA8B;gBAEtC,SAAS,GAAE,MAAuB;IAgBxC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAYxC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAgB7B"}
@@ -3,32 +3,55 @@
3
3
  *
4
4
  * Bundler-agnostic AsyncStorage implementation for mobile platforms
5
5
  */
6
- import AsyncStorage from '@react-native-async-storage/async-storage';
7
6
  /**
8
- * Bundler-agnostic AsyncStorage wrapper
9
- * Handles different module resolution patterns across bundlers (Metro, Webpack, Rollup, etc.)
7
+ * Dynamically resolve AsyncStorage at runtime to avoid bundler conflicts
8
+ *
9
+ * When the SDK is pre-bundled (e.g., with Rollup) and then consumed by an app
10
+ * that uses Metro, the static import can get resolved incorrectly due to module
11
+ * hoisting and namespace collisions.
12
+ *
13
+ * By using require() at runtime, we ensure we get the actual AsyncStorage
14
+ * from the app's node_modules, not a bundled/mangled version.
10
15
  */
11
- class BundlerAgnosticAsyncStorage {
12
- constructor(asyncStorageModule) {
13
- // Try different import patterns to handle various bundlers
14
- if (asyncStorageModule?.default?.getItem) {
15
- // Metro/Webpack pattern: { default: { getItem, setItem, ... } }
16
- this.storage = asyncStorageModule.default;
17
- }
18
- else if (asyncStorageModule?.getItem) {
19
- // Direct export pattern: { getItem, setItem, ... }
20
- this.storage = asyncStorageModule;
16
+ function getAsyncStorage() {
17
+ // Use require() to get the module at runtime
18
+ // This bypasses any bundler transformations that might have corrupted the import
19
+ try {
20
+ // Try default export first (Metro pattern)
21
+ const module = require('@react-native-async-storage/async-storage');
22
+ // Log for debugging what we actually received
23
+ const hasGetItem = typeof module?.getItem === 'function';
24
+ const hasDefaultGetItem = typeof module?.default?.getItem === 'function';
25
+ console.log('[AsyncStorage] Module resolution:', {
26
+ hasGetItem,
27
+ hasDefaultGetItem,
28
+ moduleType: typeof module,
29
+ keys: module ? Object.keys(module).slice(0, 10) : []
30
+ });
31
+ if (hasDefaultGetItem) {
32
+ return module.default;
21
33
  }
22
- else if (typeof asyncStorageModule === 'function') {
23
- // Function export pattern (some bundlers)
24
- this.storage = asyncStorageModule();
34
+ else if (hasGetItem) {
35
+ return module;
25
36
  }
26
37
  else {
27
- // Log the structure for debugging
28
- console.error('[BundlerAgnosticAsyncStorage] Unknown AsyncStorage structure:', asyncStorageModule);
29
- throw new Error('AsyncStorage methods not found. Expected structure with getItem/setItem methods. ' +
30
- 'Make sure @react-native-async-storage/async-storage is properly installed.');
38
+ throw new Error('AsyncStorage module found but missing getItem method');
31
39
  }
40
+ }
41
+ catch (error) {
42
+ console.error('[AsyncStorage] Failed to dynamically require:', error);
43
+ throw new Error('Failed to load @react-native-async-storage/async-storage. ' +
44
+ 'Make sure it is installed and properly linked.');
45
+ }
46
+ }
47
+ /**
48
+ * Bundler-agnostic AsyncStorage wrapper
49
+ * Now uses runtime require() to avoid bundler conflicts
50
+ */
51
+ class BundlerAgnosticAsyncStorage {
52
+ constructor() {
53
+ // Get AsyncStorage at runtime, not from a potentially corrupted static import
54
+ this.storage = getAsyncStorage();
32
55
  // Validate that we have the required methods
33
56
  const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
34
57
  const missingMethods = requiredMethods.filter(method => typeof this.storage[method] !== 'function');
@@ -64,7 +87,8 @@ export class AsyncStorageTokenStorage {
64
87
  this.keyPrefix = keyPrefix;
65
88
  try {
66
89
  // Initialize bundler-agnostic AsyncStorage wrapper
67
- this.asyncStorage = new BundlerAgnosticAsyncStorage(AsyncStorage);
90
+ // No longer passes the module - it uses runtime require() internally
91
+ this.asyncStorage = new BundlerAgnosticAsyncStorage();
68
92
  }
69
93
  catch (error) {
70
94
  console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explorins/pers-sdk-react-native",
3
- "version": "2.2.0-alpha.1",
3
+ "version": "2.2.0-alpha.3",
4
4
  "description": "React Native SDK for PERS Platform - Tourism Loyalty System with Blockchain Transaction Signing and WebAuthn Authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -4,35 +4,62 @@
4
4
  * Bundler-agnostic AsyncStorage implementation for mobile platforms
5
5
  */
6
6
 
7
- import AsyncStorage from '@react-native-async-storage/async-storage';
8
7
  import type { TokenStorage } from '@explorins/pers-sdk/core';
9
8
 
9
+ /**
10
+ * Dynamically resolve AsyncStorage at runtime to avoid bundler conflicts
11
+ *
12
+ * When the SDK is pre-bundled (e.g., with Rollup) and then consumed by an app
13
+ * that uses Metro, the static import can get resolved incorrectly due to module
14
+ * hoisting and namespace collisions.
15
+ *
16
+ * By using require() at runtime, we ensure we get the actual AsyncStorage
17
+ * from the app's node_modules, not a bundled/mangled version.
18
+ */
19
+ function getAsyncStorage(): any {
20
+ // Use require() to get the module at runtime
21
+ // This bypasses any bundler transformations that might have corrupted the import
22
+ try {
23
+ // Try default export first (Metro pattern)
24
+ const module = require('@react-native-async-storage/async-storage');
25
+
26
+ // Log for debugging what we actually received
27
+ const hasGetItem = typeof module?.getItem === 'function';
28
+ const hasDefaultGetItem = typeof module?.default?.getItem === 'function';
29
+
30
+ console.log('[AsyncStorage] Module resolution:', {
31
+ hasGetItem,
32
+ hasDefaultGetItem,
33
+ moduleType: typeof module,
34
+ keys: module ? Object.keys(module).slice(0, 10) : []
35
+ });
36
+
37
+ if (hasDefaultGetItem) {
38
+ return module.default;
39
+ } else if (hasGetItem) {
40
+ return module;
41
+ } else {
42
+ throw new Error('AsyncStorage module found but missing getItem method');
43
+ }
44
+ } catch (error) {
45
+ console.error('[AsyncStorage] Failed to dynamically require:', error);
46
+ throw new Error(
47
+ 'Failed to load @react-native-async-storage/async-storage. ' +
48
+ 'Make sure it is installed and properly linked.'
49
+ );
50
+ }
51
+ }
52
+
10
53
  /**
11
54
  * Bundler-agnostic AsyncStorage wrapper
12
- * Handles different module resolution patterns across bundlers (Metro, Webpack, Rollup, etc.)
55
+ * Now uses runtime require() to avoid bundler conflicts
13
56
  */
14
57
  class BundlerAgnosticAsyncStorage {
15
58
  private storage: any;
16
59
 
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
- }
60
+ constructor() {
61
+ // Get AsyncStorage at runtime, not from a potentially corrupted static import
62
+ this.storage = getAsyncStorage();
36
63
 
37
64
  // Validate that we have the required methods
38
65
  const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
@@ -82,7 +109,8 @@ export class AsyncStorageTokenStorage implements TokenStorage {
82
109
 
83
110
  try {
84
111
  // Initialize bundler-agnostic AsyncStorage wrapper
85
- this.asyncStorage = new BundlerAgnosticAsyncStorage(AsyncStorage);
112
+ // No longer passes the module - it uses runtime require() internally
113
+ this.asyncStorage = new BundlerAgnosticAsyncStorage();
86
114
  } catch (error) {
87
115
  console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);
88
116
  throw new Error(