@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.
@@ -1,9 +1,21 @@
1
1
  /**
2
2
  * AsyncStorage Token Storage for React Native Mobile Platforms
3
3
  *
4
- * Bundler-agnostic AsyncStorage implementation for mobile platforms
4
+ * Bundler-agnostic AsyncStorage implementation for mobile platforms.
5
+ *
6
+ * IMPORTANT: Due to bundler conflicts between Rollup (SDK) and Metro (app),
7
+ * the consuming app MUST set global.AsyncStorageModule before using this SDK:
8
+ *
9
+ * ```javascript
10
+ * // In your app's index.js, BEFORE importing the SDK:
11
+ * import AsyncStorage from '@react-native-async-storage/async-storage';
12
+ * global.AsyncStorageModule = AsyncStorage;
13
+ * ```
5
14
  */
6
15
  import type { TokenStorage } from '@explorins/pers-sdk/core';
16
+ declare global {
17
+ var AsyncStorageModule: any;
18
+ }
7
19
  /**
8
20
  * AsyncStorage implementation for mobile platforms
9
21
  *
@@ -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;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,kBAAkB,EAAE,GAAG,CAAC;CAC7B;AA4FD;;;;;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"}
@@ -1,34 +1,67 @@
1
1
  /**
2
2
  * AsyncStorage Token Storage for React Native Mobile Platforms
3
3
  *
4
- * Bundler-agnostic AsyncStorage implementation for mobile platforms
4
+ * Bundler-agnostic AsyncStorage implementation for mobile platforms.
5
+ *
6
+ * IMPORTANT: Due to bundler conflicts between Rollup (SDK) and Metro (app),
7
+ * the consuming app MUST set global.AsyncStorageModule before using this SDK:
8
+ *
9
+ * ```javascript
10
+ * // In your app's index.js, BEFORE importing the SDK:
11
+ * import AsyncStorage from '@react-native-async-storage/async-storage';
12
+ * global.AsyncStorageModule = AsyncStorage;
13
+ * ```
5
14
  */
6
- import AsyncStorage from '@react-native-async-storage/async-storage';
7
15
  /**
8
- * Bundler-agnostic AsyncStorage wrapper
9
- * Handles different module resolution patterns across bundlers (Metro, Webpack, Rollup, etc.)
16
+ * Get AsyncStorage from the global that the app must set.
17
+ *
18
+ * This bypasses all bundler resolution issues by having the app
19
+ * explicitly provide the AsyncStorage module via a global variable.
10
20
  */
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;
21
+ function getAsyncStorage() {
22
+ // Check if the app has set the global
23
+ if (global.AsyncStorageModule) {
24
+ const module = global.AsyncStorageModule;
25
+ // Validate it has the expected methods
26
+ if (typeof module?.getItem === 'function') {
27
+ console.log('[AsyncStorage] Using global.AsyncStorageModule (direct)');
28
+ return module;
17
29
  }
18
- else if (asyncStorageModule?.getItem) {
19
- // Direct export pattern: { getItem, setItem, ... }
20
- this.storage = asyncStorageModule;
30
+ else if (typeof module?.default?.getItem === 'function') {
31
+ console.log('[AsyncStorage] Using global.AsyncStorageModule.default');
32
+ return module.default;
21
33
  }
22
- else if (typeof asyncStorageModule === 'function') {
23
- // Function export pattern (some bundlers)
24
- this.storage = asyncStorageModule();
34
+ }
35
+ // Fallback: try require (may not work due to bundler conflicts)
36
+ try {
37
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
38
+ const module = require('@react-native-async-storage/async-storage');
39
+ if (typeof module?.default?.getItem === 'function') {
40
+ console.log('[AsyncStorage] Fallback: using require().default');
41
+ return module.default;
25
42
  }
26
- 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.');
43
+ else if (typeof module?.getItem === 'function') {
44
+ console.log('[AsyncStorage] Fallback: using require() direct');
45
+ return module;
31
46
  }
47
+ }
48
+ catch (e) {
49
+ // Ignore require errors
50
+ }
51
+ // If we get here, provide a helpful error
52
+ throw new Error('AsyncStorage not available. Please add this to your app\'s index.js BEFORE importing the SDK:\n\n' +
53
+ ' import AsyncStorage from \'@react-native-async-storage/async-storage\';\n' +
54
+ ' global.AsyncStorageModule = AsyncStorage;\n\n' +
55
+ 'This is required due to bundler conflicts between Rollup and Metro.');
56
+ }
57
+ /**
58
+ * Bundler-agnostic AsyncStorage wrapper
59
+ * Uses global injection to avoid bundler conflicts
60
+ */
61
+ class BundlerAgnosticAsyncStorage {
62
+ constructor() {
63
+ // Get AsyncStorage at runtime, not from a potentially corrupted static import
64
+ this.storage = getAsyncStorage();
32
65
  // Validate that we have the required methods
33
66
  const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
34
67
  const missingMethods = requiredMethods.filter(method => typeof this.storage[method] !== 'function');
@@ -64,7 +97,8 @@ export class AsyncStorageTokenStorage {
64
97
  this.keyPrefix = keyPrefix;
65
98
  try {
66
99
  // Initialize bundler-agnostic AsyncStorage wrapper
67
- this.asyncStorage = new BundlerAgnosticAsyncStorage(AsyncStorage);
100
+ // No longer passes the module - it uses runtime require() internally
101
+ this.asyncStorage = new BundlerAgnosticAsyncStorage();
68
102
  }
69
103
  catch (error) {
70
104
  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.2",
3
+ "version": "2.2.0-alpha.4",
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",
@@ -1,38 +1,81 @@
1
1
  /**
2
2
  * AsyncStorage Token Storage for React Native Mobile Platforms
3
3
  *
4
- * Bundler-agnostic AsyncStorage implementation for mobile platforms
4
+ * Bundler-agnostic AsyncStorage implementation for mobile platforms.
5
+ *
6
+ * IMPORTANT: Due to bundler conflicts between Rollup (SDK) and Metro (app),
7
+ * the consuming app MUST set global.AsyncStorageModule before using this SDK:
8
+ *
9
+ * ```javascript
10
+ * // In your app's index.js, BEFORE importing the SDK:
11
+ * import AsyncStorage from '@react-native-async-storage/async-storage';
12
+ * global.AsyncStorageModule = AsyncStorage;
13
+ * ```
5
14
  */
6
15
 
7
- import AsyncStorage from '@react-native-async-storage/async-storage';
8
16
  import type { TokenStorage } from '@explorins/pers-sdk/core';
9
17
 
18
+ // Declare global type for TypeScript
19
+ declare global {
20
+ var AsyncStorageModule: any;
21
+ }
22
+
23
+ /**
24
+ * Get AsyncStorage from the global that the app must set.
25
+ *
26
+ * This bypasses all bundler resolution issues by having the app
27
+ * explicitly provide the AsyncStorage module via a global variable.
28
+ */
29
+ function getAsyncStorage(): any {
30
+ // Check if the app has set the global
31
+ if (global.AsyncStorageModule) {
32
+ const module = global.AsyncStorageModule;
33
+
34
+ // Validate it has the expected methods
35
+ if (typeof module?.getItem === 'function') {
36
+ console.log('[AsyncStorage] Using global.AsyncStorageModule (direct)');
37
+ return module;
38
+ } else if (typeof module?.default?.getItem === 'function') {
39
+ console.log('[AsyncStorage] Using global.AsyncStorageModule.default');
40
+ return module.default;
41
+ }
42
+ }
43
+
44
+ // Fallback: try require (may not work due to bundler conflicts)
45
+ try {
46
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
47
+ const module = require('@react-native-async-storage/async-storage');
48
+
49
+ if (typeof module?.default?.getItem === 'function') {
50
+ console.log('[AsyncStorage] Fallback: using require().default');
51
+ return module.default;
52
+ } else if (typeof module?.getItem === 'function') {
53
+ console.log('[AsyncStorage] Fallback: using require() direct');
54
+ return module;
55
+ }
56
+ } catch (e) {
57
+ // Ignore require errors
58
+ }
59
+
60
+ // If we get here, provide a helpful error
61
+ throw new Error(
62
+ 'AsyncStorage not available. Please add this to your app\'s index.js BEFORE importing the SDK:\n\n' +
63
+ ' import AsyncStorage from \'@react-native-async-storage/async-storage\';\n' +
64
+ ' global.AsyncStorageModule = AsyncStorage;\n\n' +
65
+ 'This is required due to bundler conflicts between Rollup and Metro.'
66
+ );
67
+ }
68
+
10
69
  /**
11
70
  * Bundler-agnostic AsyncStorage wrapper
12
- * Handles different module resolution patterns across bundlers (Metro, Webpack, Rollup, etc.)
71
+ * Uses global injection to avoid bundler conflicts
13
72
  */
14
73
  class BundlerAgnosticAsyncStorage {
15
74
  private storage: any;
16
75
 
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
- }
76
+ constructor() {
77
+ // Get AsyncStorage at runtime, not from a potentially corrupted static import
78
+ this.storage = getAsyncStorage();
36
79
 
37
80
  // Validate that we have the required methods
38
81
  const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
@@ -82,7 +125,8 @@ export class AsyncStorageTokenStorage implements TokenStorage {
82
125
 
83
126
  try {
84
127
  // Initialize bundler-agnostic AsyncStorage wrapper
85
- this.asyncStorage = new BundlerAgnosticAsyncStorage(AsyncStorage);
128
+ // No longer passes the module - it uses runtime require() internally
129
+ this.asyncStorage = new BundlerAgnosticAsyncStorage();
86
130
  } catch (error) {
87
131
  console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);
88
132
  throw new Error(