@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
|
@@ -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
|
|
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,52 +1,62 @@
|
|
|
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
|
-
*
|
|
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.
|
|
16
|
+
* Get AsyncStorage from the global that the app must set.
|
|
12
17
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
18
|
+
* This bypasses all bundler resolution issues by having the app
|
|
19
|
+
* explicitly provide the AsyncStorage module via a global variable.
|
|
15
20
|
*/
|
|
16
21
|
function getAsyncStorage() {
|
|
17
|
-
//
|
|
18
|
-
|
|
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;
|
|
29
|
+
}
|
|
30
|
+
else if (typeof module?.default?.getItem === 'function') {
|
|
31
|
+
console.log('[AsyncStorage] Using global.AsyncStorageModule.default');
|
|
32
|
+
return module.default;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Fallback: try require (may not work due to bundler conflicts)
|
|
19
36
|
try {
|
|
20
|
-
//
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
21
38
|
const module = require('@react-native-async-storage/async-storage');
|
|
22
|
-
|
|
23
|
-
|
|
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) {
|
|
39
|
+
if (typeof module?.default?.getItem === 'function') {
|
|
40
|
+
console.log('[AsyncStorage] Fallback: using require().default');
|
|
32
41
|
return module.default;
|
|
33
42
|
}
|
|
34
|
-
else if (
|
|
43
|
+
else if (typeof module?.getItem === 'function') {
|
|
44
|
+
console.log('[AsyncStorage] Fallback: using require() direct');
|
|
35
45
|
return module;
|
|
36
46
|
}
|
|
37
|
-
else {
|
|
38
|
-
throw new Error('AsyncStorage module found but missing getItem method');
|
|
39
|
-
}
|
|
40
47
|
}
|
|
41
|
-
catch (
|
|
42
|
-
|
|
43
|
-
throw new Error('Failed to load @react-native-async-storage/async-storage. ' +
|
|
44
|
-
'Make sure it is installed and properly linked.');
|
|
48
|
+
catch (e) {
|
|
49
|
+
// Ignore require errors
|
|
45
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.');
|
|
46
56
|
}
|
|
47
57
|
/**
|
|
48
58
|
* Bundler-agnostic AsyncStorage wrapper
|
|
49
|
-
*
|
|
59
|
+
* Uses global injection to avoid bundler conflicts
|
|
50
60
|
*/
|
|
51
61
|
class BundlerAgnosticAsyncStorage {
|
|
52
62
|
constructor() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@explorins/pers-sdk-react-native",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
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,58 +1,74 @@
|
|
|
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
16
|
import type { TokenStorage } from '@explorins/pers-sdk/core';
|
|
8
17
|
|
|
18
|
+
// Declare global type for TypeScript
|
|
19
|
+
declare global {
|
|
20
|
+
var AsyncStorageModule: any;
|
|
21
|
+
}
|
|
22
|
+
|
|
9
23
|
/**
|
|
10
|
-
*
|
|
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.
|
|
24
|
+
* Get AsyncStorage from the global that the app must set.
|
|
15
25
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
26
|
+
* This bypasses all bundler resolution issues by having the app
|
|
27
|
+
* explicitly provide the AsyncStorage module via a global variable.
|
|
18
28
|
*/
|
|
19
29
|
function getAsyncStorage(): any {
|
|
20
|
-
//
|
|
21
|
-
|
|
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)
|
|
22
45
|
try {
|
|
23
|
-
//
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
24
47
|
const module = require('@react-native-async-storage/async-storage');
|
|
25
48
|
|
|
26
|
-
|
|
27
|
-
|
|
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) {
|
|
49
|
+
if (typeof module?.default?.getItem === 'function') {
|
|
50
|
+
console.log('[AsyncStorage] Fallback: using require().default');
|
|
38
51
|
return module.default;
|
|
39
|
-
} else if (
|
|
52
|
+
} else if (typeof module?.getItem === 'function') {
|
|
53
|
+
console.log('[AsyncStorage] Fallback: using require() direct');
|
|
40
54
|
return module;
|
|
41
|
-
} else {
|
|
42
|
-
throw new Error('AsyncStorage module found but missing getItem method');
|
|
43
55
|
}
|
|
44
|
-
} catch (
|
|
45
|
-
|
|
46
|
-
throw new Error(
|
|
47
|
-
'Failed to load @react-native-async-storage/async-storage. ' +
|
|
48
|
-
'Make sure it is installed and properly linked.'
|
|
49
|
-
);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
// Ignore require errors
|
|
50
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
|
+
);
|
|
51
67
|
}
|
|
52
68
|
|
|
53
69
|
/**
|
|
54
70
|
* Bundler-agnostic AsyncStorage wrapper
|
|
55
|
-
*
|
|
71
|
+
* Uses global injection to avoid bundler conflicts
|
|
56
72
|
*/
|
|
57
73
|
class BundlerAgnosticAsyncStorage {
|
|
58
74
|
private storage: any;
|