@explorins/pers-sdk-react-native 2.1.14-beta.0 → 2.1.18
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/hooks/index.d.ts +3 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useAnalytics.d.ts +1 -1
- package/dist/hooks/useAnalytics.d.ts.map +1 -1
- package/dist/hooks/useAuth.d.ts +3 -3
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +14 -27
- package/dist/hooks/useBusiness.d.ts +3 -2
- package/dist/hooks/useBusiness.d.ts.map +1 -1
- package/dist/hooks/useBusiness.js +28 -2
- package/dist/hooks/useCampaigns.d.ts +10 -4
- package/dist/hooks/useCampaigns.d.ts.map +1 -1
- package/dist/hooks/useCampaigns.js +36 -8
- package/dist/hooks/useDonations.d.ts +1 -1
- package/dist/hooks/useDonations.d.ts.map +1 -1
- package/dist/hooks/usePurchases.d.ts +2 -2
- package/dist/hooks/usePurchases.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.d.ts +10 -2
- package/dist/hooks/useRedemptions.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.js +32 -4
- package/dist/hooks/useTenants.d.ts +1 -1
- package/dist/hooks/useTenants.d.ts.map +1 -1
- package/dist/hooks/useTokenBalances.d.ts +1 -1
- package/dist/hooks/useTokenBalances.d.ts.map +1 -1
- package/dist/hooks/useTokenBalances.js +1 -1
- package/dist/hooks/useTokens.d.ts +1 -1
- package/dist/hooks/useTokens.d.ts.map +1 -1
- package/dist/hooks/useTransactions.d.ts +1 -1
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTriggerSources.d.ts +1 -1
- package/dist/hooks/useTriggerSources.d.ts.map +1 -1
- package/dist/hooks/useUserStatus.d.ts +1 -1
- package/dist/hooks/useUserStatus.d.ts.map +1 -1
- package/dist/hooks/useUsers.d.ts +1 -1
- package/dist/hooks/useUsers.d.ts.map +1 -1
- package/dist/index-CzLxqePZ.js +7717 -0
- package/dist/index-CzLxqePZ.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1731 -284
- package/dist/index.js.map +1 -1
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +26 -37
- package/package.json +182 -182
- package/src/hooks/index.ts +5 -2
- package/src/hooks/useAnalytics.ts +1 -1
- package/src/hooks/useAuth.ts +16 -32
- package/src/hooks/useBusiness.ts +32 -3
- package/src/hooks/useCampaigns.ts +47 -12
- package/src/hooks/useDonations.ts +1 -1
- package/src/hooks/usePurchases.ts +1 -1
- package/src/hooks/useRedemptions.ts +43 -6
- package/src/hooks/useTenants.ts +1 -1
- package/src/hooks/useTokenBalances.ts +1 -1
- package/src/hooks/useTokens.ts +1 -1
- package/src/hooks/useTransactions.ts +1 -1
- package/src/hooks/useTriggerSources.ts +1 -1
- package/src/hooks/useUserStatus.ts +1 -1
- package/src/hooks/useUsers.ts +1 -1
- package/src/index.ts +6 -3
- package/src/providers/PersSDKProvider.tsx +29 -40
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersSDKProvider.d.ts","sourceRoot":"","sources":["../../src/providers/PersSDKProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAuC,SAAS,EAA2C,MAAM,OAAO,CAAC;AAEvH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAIpF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAkB3D,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAE7B,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IAGpB,YAAY,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAGzC,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC;IAGhC,UAAU,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,sBAAsB,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,EAAE,eAAe,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5F,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,cAAc,EAAE,MAAM,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CAC/C;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC;IACrC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,
|
|
1
|
+
{"version":3,"file":"PersSDKProvider.d.ts","sourceRoot":"","sources":["../../src/providers/PersSDKProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAuC,SAAS,EAA2C,MAAM,OAAO,CAAC;AAEvH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAIpF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAkB3D,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAE7B,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IAGpB,YAAY,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAGzC,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC;IAGhC,UAAU,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,sBAAsB,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,EAAE,eAAe,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5F,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,cAAc,EAAE,MAAM,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CAC/C;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC;IACrC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CA6NA,CAAC;AAGF,eAAO,MAAM,UAAU,QAAO,cAQ7B,CAAC"}
|
|
@@ -38,6 +38,7 @@ const SDKContext = createContext(null);
|
|
|
38
38
|
*/
|
|
39
39
|
export const PersSDKProvider = ({ children, config }) => {
|
|
40
40
|
const initializingRef = useRef(false);
|
|
41
|
+
const eventUnsubscribeRef = useRef(null);
|
|
41
42
|
// State refs for stable functions to read current values
|
|
42
43
|
const sdkRef = useRef(null);
|
|
43
44
|
const isInitializedRef = useRef(false);
|
|
@@ -91,6 +92,21 @@ export const PersSDKProvider = ({ children, config }) => {
|
|
|
91
92
|
};
|
|
92
93
|
// Initialize PersSDK with platform-aware auth provider
|
|
93
94
|
const sdkInstance = new PersSDK(httpClient, sdkConfig);
|
|
95
|
+
// Subscribe to auth events BEFORE exposing SDK to consumers
|
|
96
|
+
// This ensures no events are missed due to React timing
|
|
97
|
+
eventUnsubscribeRef.current = sdkInstance.events.subscribe((event) => {
|
|
98
|
+
if (event.type === 'session_restored' || event.type === 'login_success') {
|
|
99
|
+
const details = event.details;
|
|
100
|
+
if (details?.user) {
|
|
101
|
+
setUser(details.user);
|
|
102
|
+
setIsAuthenticated(true);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (event.type === 'logout_success' || event.type === 'session_restoration_failed' || event.code === 'AUTH_FAILED') {
|
|
106
|
+
setUser(null);
|
|
107
|
+
setIsAuthenticated(false);
|
|
108
|
+
}
|
|
109
|
+
}, { domains: ['authentication'], replay: true });
|
|
94
110
|
setAuthProvider(authProvider);
|
|
95
111
|
setSdk(sdkInstance);
|
|
96
112
|
setIsInitialized(true);
|
|
@@ -104,6 +120,15 @@ export const PersSDKProvider = ({ children, config }) => {
|
|
|
104
120
|
initializingRef.current = false;
|
|
105
121
|
}
|
|
106
122
|
}, [isInitialized]);
|
|
123
|
+
// Cleanup subscription on unmount
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
return () => {
|
|
126
|
+
if (eventUnsubscribeRef.current) {
|
|
127
|
+
eventUnsubscribeRef.current();
|
|
128
|
+
eventUnsubscribeRef.current = null;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}, []);
|
|
107
132
|
const setAuthenticationState = useCallback((user, isAuthenticated) => {
|
|
108
133
|
setUser(user);
|
|
109
134
|
setIsAuthenticated(isAuthenticated);
|
|
@@ -150,42 +175,7 @@ export const PersSDKProvider = ({ children, config }) => {
|
|
|
150
175
|
console.error('[PersSDK] Failed to restore session:', error);
|
|
151
176
|
throw error;
|
|
152
177
|
}
|
|
153
|
-
}, [setAuthenticationState]);
|
|
154
|
-
// Listen for authentication events from core SDK
|
|
155
|
-
// Set up immediately when SDK is created (don't wait for isInitialized)
|
|
156
|
-
// to catch session_restored events that fire during SDK initialization
|
|
157
|
-
useEffect(() => {
|
|
158
|
-
if (!sdk)
|
|
159
|
-
return;
|
|
160
|
-
const unsubscribe = sdk.events.subscribe((event) => {
|
|
161
|
-
if (event.domain !== 'authentication')
|
|
162
|
-
return;
|
|
163
|
-
// Session restored successfully - sync React state
|
|
164
|
-
if (event.type === 'session_restored') {
|
|
165
|
-
console.log('[PersSDK] Session restoration event received, syncing state...');
|
|
166
|
-
// Read user from event details if available, otherwise fetch
|
|
167
|
-
const userId = event.details?.userId;
|
|
168
|
-
if (userId) {
|
|
169
|
-
// User ID available, fetch user data
|
|
170
|
-
sdk.users.getCurrentUser()
|
|
171
|
-
.then(userData => {
|
|
172
|
-
setAuthenticationState(userData, true);
|
|
173
|
-
})
|
|
174
|
-
.catch(error => {
|
|
175
|
-
console.error('[PersSDK] Failed to sync restored session:', error);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
// Session restoration failed or auth error - clear React state
|
|
180
|
-
if (event.type === 'session_restoration_failed' || event.code === 'AUTH_FAILED') {
|
|
181
|
-
console.log('[PersSDK] Authentication failed - clearing session');
|
|
182
|
-
setAuthenticationState(null, false);
|
|
183
|
-
}
|
|
184
|
-
}, { domains: ['authentication'] });
|
|
185
|
-
return () => {
|
|
186
|
-
unsubscribe();
|
|
187
|
-
};
|
|
188
|
-
}, [sdk, setAuthenticationState]);
|
|
178
|
+
}, [setAuthenticationState]);
|
|
189
179
|
// iOS/Android: Monitor app state and validate tokens when app becomes active
|
|
190
180
|
useEffect(() => {
|
|
191
181
|
if (!sdk || Platform.OS === 'web') {
|
|
@@ -193,7 +183,6 @@ export const PersSDKProvider = ({ children, config }) => {
|
|
|
193
183
|
}
|
|
194
184
|
const handleAppStateChange = async (nextAppState) => {
|
|
195
185
|
if (nextAppState === 'active' && isAuthenticated) {
|
|
196
|
-
console.log('[PersSDK] App became active - validating tokens');
|
|
197
186
|
try {
|
|
198
187
|
// Trigger token validation when app resumes from background
|
|
199
188
|
// This ensures tokens are checked after extended inactivity
|
package/package.json
CHANGED
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@explorins/pers-sdk-react-native",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "React Native SDK for PERS Platform - Tourism Loyalty System with Blockchain Transaction Signing and WebAuthn Authentication",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc && rollup -c --bundleConfigAsCjs",
|
|
9
|
-
"build:watch": "rollup -c --bundleConfigAsCjs --watch",
|
|
10
|
-
"dev": "tsc --watch",
|
|
11
|
-
"clean": "rimraf dist",
|
|
12
|
-
"docs": "typedoc",
|
|
13
|
-
"docs:dev": "typedoc --watch",
|
|
14
|
-
"docs:json": "typedoc --json docs/api.json",
|
|
15
|
-
"docs:serve": "npx http-server docs -p 8080",
|
|
16
|
-
"prepublishOnly": "npm run clean && npm run build",
|
|
17
|
-
"publish-version": "npm run clean && npm run build && npm version patch && npm publish",
|
|
18
|
-
"publish-with-docs": "npm run clean && npm run build && npm run docs && npm version patch && npm publish",
|
|
19
|
-
"yalc:publish": "npm version patch --no-git-tag-version && npm run build && yalc publish",
|
|
20
|
-
"yalc:push": "npm version patch --no-git-tag-version && npm run build && yalc push"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"pers",
|
|
24
|
-
"sdk",
|
|
25
|
-
"react-native",
|
|
26
|
-
"tourism",
|
|
27
|
-
"loyalty",
|
|
28
|
-
"blockchain",
|
|
29
|
-
"web3",
|
|
30
|
-
"webauthn",
|
|
31
|
-
"transaction-signing",
|
|
32
|
-
"rewards",
|
|
33
|
-
"authentication",
|
|
34
|
-
"biometrics",
|
|
35
|
-
"secure-storage"
|
|
36
|
-
],
|
|
37
|
-
"author": "eXplorins",
|
|
38
|
-
"license": "MIT",
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"@explorins/pers-sdk": "^2.1.
|
|
41
|
-
"@explorins/pers-signer": "^1.0.33",
|
|
42
|
-
"buffer": "^6.0.3",
|
|
43
|
-
"ethers": "^6.15.0",
|
|
44
|
-
"react-native-get-random-values": "^2.0.0",
|
|
45
|
-
"react-native-keychain": "^10.0.0",
|
|
46
|
-
"react-native-passkey": "^3.3.2",
|
|
47
|
-
"react-native-quick-crypto": "^1.0.6"
|
|
48
|
-
},
|
|
49
|
-
"browser": {
|
|
50
|
-
"crypto": false,
|
|
51
|
-
"url": false,
|
|
52
|
-
"http": false,
|
|
53
|
-
"https": false,
|
|
54
|
-
"zlib": false,
|
|
55
|
-
"stream": false,
|
|
56
|
-
"assert": false,
|
|
57
|
-
"path": false,
|
|
58
|
-
"fs": false,
|
|
59
|
-
"os": false,
|
|
60
|
-
"readable-stream": false,
|
|
61
|
-
"util": false,
|
|
62
|
-
"events": false,
|
|
63
|
-
"net": false,
|
|
64
|
-
"tls": false,
|
|
65
|
-
"child_process": false,
|
|
66
|
-
"pngjs": false,
|
|
67
|
-
"pngjs/lib/bitmapper": false,
|
|
68
|
-
"pngjs/lib/parser-async": false,
|
|
69
|
-
"pngjs/lib/parser-sync": false,
|
|
70
|
-
"./bitmapper": false,
|
|
71
|
-
"hash-base": false,
|
|
72
|
-
"@ethereumjs/common": false,
|
|
73
|
-
"@ethereumjs/tx": false,
|
|
74
|
-
"@ethereumjs/util": false,
|
|
75
|
-
"stream-browserify": false,
|
|
76
|
-
"crypto-browserify": false,
|
|
77
|
-
"inherits": false,
|
|
78
|
-
"safe-buffer": false,
|
|
79
|
-
"string_decoder": false,
|
|
80
|
-
"process-nextick-args": false,
|
|
81
|
-
"isarray": false,
|
|
82
|
-
"core-util-is": false,
|
|
83
|
-
"util-deprecate": false,
|
|
84
|
-
"ethereum-cryptography": false,
|
|
85
|
-
"keccak": false,
|
|
86
|
-
"secp256k1": false,
|
|
87
|
-
"scrypt-js": false,
|
|
88
|
-
"bech32": false,
|
|
89
|
-
"ws": false,
|
|
90
|
-
"xhr2-cookies": false,
|
|
91
|
-
"aes-js": false,
|
|
92
|
-
"@ethersproject/sha2": false,
|
|
93
|
-
"@ethersproject/pbkdf2": false,
|
|
94
|
-
"@ethersproject/scrypt": false
|
|
95
|
-
},
|
|
96
|
-
"peerDependencies": {
|
|
97
|
-
"@react-native-async-storage/async-storage": ">=1.15.0",
|
|
98
|
-
"react": ">=16.8.0",
|
|
99
|
-
"react-native": ">=0.60.0"
|
|
100
|
-
},
|
|
101
|
-
"peerDependenciesMeta": {
|
|
102
|
-
"react-native-keychain": {
|
|
103
|
-
"optional": true
|
|
104
|
-
},
|
|
105
|
-
"@react-native-async-storage/async-storage": {
|
|
106
|
-
"optional": false
|
|
107
|
-
},
|
|
108
|
-
"react-native-get-random-values": {
|
|
109
|
-
"optional": true
|
|
110
|
-
},
|
|
111
|
-
"react-native-url-polyfill": {
|
|
112
|
-
"optional": true
|
|
113
|
-
},
|
|
114
|
-
"react-native-polyfill-globals": {
|
|
115
|
-
"optional": true
|
|
116
|
-
},
|
|
117
|
-
"web-streams-polyfill": {
|
|
118
|
-
"optional": true
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
"overrides": {
|
|
122
|
-
"readable-stream": false,
|
|
123
|
-
"@ethereumjs/common": false,
|
|
124
|
-
"@ethereumjs/util": false,
|
|
125
|
-
"@ethereumjs/rlp": false,
|
|
126
|
-
"@ethereumjs/tx": false,
|
|
127
|
-
"stream": false,
|
|
128
|
-
"util": false,
|
|
129
|
-
"events": false,
|
|
130
|
-
"crypto": false,
|
|
131
|
-
"fs": false,
|
|
132
|
-
"path": false,
|
|
133
|
-
"os": false,
|
|
134
|
-
"net": false,
|
|
135
|
-
"tls": false,
|
|
136
|
-
"child_process": false,
|
|
137
|
-
"hash-base": false,
|
|
138
|
-
"inherits": false,
|
|
139
|
-
"safe-buffer": false,
|
|
140
|
-
"string_decoder": false,
|
|
141
|
-
"process-nextick-args": false,
|
|
142
|
-
"isarray": false,
|
|
143
|
-
"core-util-is": false,
|
|
144
|
-
"util-deprecate": false,
|
|
145
|
-
"ethereum-cryptography": false,
|
|
146
|
-
"keccak": false,
|
|
147
|
-
"secp256k1": false,
|
|
148
|
-
"scrypt-js": false,
|
|
149
|
-
"bech32": false,
|
|
150
|
-
"ws": false,
|
|
151
|
-
"xhr2-cookies": false,
|
|
152
|
-
"aes-js": false,
|
|
153
|
-
"@ethersproject/sha2": false,
|
|
154
|
-
"@ethersproject/pbkdf2": false,
|
|
155
|
-
"@ethersproject/scrypt": false
|
|
156
|
-
},
|
|
157
|
-
"devDependencies": {
|
|
158
|
-
"@explorins/pers-shared": "^2.1.
|
|
159
|
-
"@react-native-async-storage/async-storage": "^3.0.2",
|
|
160
|
-
"@rollup/plugin-commonjs": "^25.0.7",
|
|
161
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
162
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
163
|
-
"@types/react": "^19.1.1",
|
|
164
|
-
"@types/react-native": "^0.72.8",
|
|
165
|
-
"rimraf": "^5.0.0",
|
|
166
|
-
"rollup": "^4.0.0",
|
|
167
|
-
"rollup-plugin-typescript2": "^0.36.0",
|
|
168
|
-
"typedoc": "^0.25.13",
|
|
169
|
-
"typedoc-plugin-markdown": "^3.17.1",
|
|
170
|
-
"typescript": "^5.2.0"
|
|
171
|
-
},
|
|
172
|
-
"files": [
|
|
173
|
-
"dist/**/*",
|
|
174
|
-
"src/**/*",
|
|
175
|
-
"README.md"
|
|
176
|
-
],
|
|
177
|
-
"repository": {
|
|
178
|
-
"type": "git",
|
|
179
|
-
"url": "git+https://github.com/eXplorins/pers-sdk.git",
|
|
180
|
-
"directory": "packages/pers-sdk-react-native"
|
|
181
|
-
}
|
|
182
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@explorins/pers-sdk-react-native",
|
|
3
|
+
"version": "2.1.18",
|
|
4
|
+
"description": "React Native SDK for PERS Platform - Tourism Loyalty System with Blockchain Transaction Signing and WebAuthn Authentication",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc && rollup -c --bundleConfigAsCjs",
|
|
9
|
+
"build:watch": "rollup -c --bundleConfigAsCjs --watch",
|
|
10
|
+
"dev": "tsc --watch",
|
|
11
|
+
"clean": "rimraf dist",
|
|
12
|
+
"docs": "typedoc",
|
|
13
|
+
"docs:dev": "typedoc --watch",
|
|
14
|
+
"docs:json": "typedoc --json docs/api.json",
|
|
15
|
+
"docs:serve": "npx http-server docs -p 8080",
|
|
16
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
17
|
+
"publish-version": "npm run clean && npm run build && npm version patch && npm publish",
|
|
18
|
+
"publish-with-docs": "npm run clean && npm run build && npm run docs && npm version patch && npm publish",
|
|
19
|
+
"yalc:publish": "npm version patch --no-git-tag-version && npm run build && yalc publish",
|
|
20
|
+
"yalc:push": "npm version patch --no-git-tag-version && npm run build && yalc push"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"pers",
|
|
24
|
+
"sdk",
|
|
25
|
+
"react-native",
|
|
26
|
+
"tourism",
|
|
27
|
+
"loyalty",
|
|
28
|
+
"blockchain",
|
|
29
|
+
"web3",
|
|
30
|
+
"webauthn",
|
|
31
|
+
"transaction-signing",
|
|
32
|
+
"rewards",
|
|
33
|
+
"authentication",
|
|
34
|
+
"biometrics",
|
|
35
|
+
"secure-storage"
|
|
36
|
+
],
|
|
37
|
+
"author": "eXplorins",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@explorins/pers-sdk": "^2.1.26",
|
|
41
|
+
"@explorins/pers-signer": "^1.0.33",
|
|
42
|
+
"buffer": "^6.0.3",
|
|
43
|
+
"ethers": "^6.15.0",
|
|
44
|
+
"react-native-get-random-values": "^2.0.0",
|
|
45
|
+
"react-native-keychain": "^10.0.0",
|
|
46
|
+
"react-native-passkey": "^3.3.2",
|
|
47
|
+
"react-native-quick-crypto": "^1.0.6"
|
|
48
|
+
},
|
|
49
|
+
"browser": {
|
|
50
|
+
"crypto": false,
|
|
51
|
+
"url": false,
|
|
52
|
+
"http": false,
|
|
53
|
+
"https": false,
|
|
54
|
+
"zlib": false,
|
|
55
|
+
"stream": false,
|
|
56
|
+
"assert": false,
|
|
57
|
+
"path": false,
|
|
58
|
+
"fs": false,
|
|
59
|
+
"os": false,
|
|
60
|
+
"readable-stream": false,
|
|
61
|
+
"util": false,
|
|
62
|
+
"events": false,
|
|
63
|
+
"net": false,
|
|
64
|
+
"tls": false,
|
|
65
|
+
"child_process": false,
|
|
66
|
+
"pngjs": false,
|
|
67
|
+
"pngjs/lib/bitmapper": false,
|
|
68
|
+
"pngjs/lib/parser-async": false,
|
|
69
|
+
"pngjs/lib/parser-sync": false,
|
|
70
|
+
"./bitmapper": false,
|
|
71
|
+
"hash-base": false,
|
|
72
|
+
"@ethereumjs/common": false,
|
|
73
|
+
"@ethereumjs/tx": false,
|
|
74
|
+
"@ethereumjs/util": false,
|
|
75
|
+
"stream-browserify": false,
|
|
76
|
+
"crypto-browserify": false,
|
|
77
|
+
"inherits": false,
|
|
78
|
+
"safe-buffer": false,
|
|
79
|
+
"string_decoder": false,
|
|
80
|
+
"process-nextick-args": false,
|
|
81
|
+
"isarray": false,
|
|
82
|
+
"core-util-is": false,
|
|
83
|
+
"util-deprecate": false,
|
|
84
|
+
"ethereum-cryptography": false,
|
|
85
|
+
"keccak": false,
|
|
86
|
+
"secp256k1": false,
|
|
87
|
+
"scrypt-js": false,
|
|
88
|
+
"bech32": false,
|
|
89
|
+
"ws": false,
|
|
90
|
+
"xhr2-cookies": false,
|
|
91
|
+
"aes-js": false,
|
|
92
|
+
"@ethersproject/sha2": false,
|
|
93
|
+
"@ethersproject/pbkdf2": false,
|
|
94
|
+
"@ethersproject/scrypt": false
|
|
95
|
+
},
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"@react-native-async-storage/async-storage": ">=1.15.0",
|
|
98
|
+
"react": ">=16.8.0",
|
|
99
|
+
"react-native": ">=0.60.0"
|
|
100
|
+
},
|
|
101
|
+
"peerDependenciesMeta": {
|
|
102
|
+
"react-native-keychain": {
|
|
103
|
+
"optional": true
|
|
104
|
+
},
|
|
105
|
+
"@react-native-async-storage/async-storage": {
|
|
106
|
+
"optional": false
|
|
107
|
+
},
|
|
108
|
+
"react-native-get-random-values": {
|
|
109
|
+
"optional": true
|
|
110
|
+
},
|
|
111
|
+
"react-native-url-polyfill": {
|
|
112
|
+
"optional": true
|
|
113
|
+
},
|
|
114
|
+
"react-native-polyfill-globals": {
|
|
115
|
+
"optional": true
|
|
116
|
+
},
|
|
117
|
+
"web-streams-polyfill": {
|
|
118
|
+
"optional": true
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"overrides": {
|
|
122
|
+
"readable-stream": false,
|
|
123
|
+
"@ethereumjs/common": false,
|
|
124
|
+
"@ethereumjs/util": false,
|
|
125
|
+
"@ethereumjs/rlp": false,
|
|
126
|
+
"@ethereumjs/tx": false,
|
|
127
|
+
"stream": false,
|
|
128
|
+
"util": false,
|
|
129
|
+
"events": false,
|
|
130
|
+
"crypto": false,
|
|
131
|
+
"fs": false,
|
|
132
|
+
"path": false,
|
|
133
|
+
"os": false,
|
|
134
|
+
"net": false,
|
|
135
|
+
"tls": false,
|
|
136
|
+
"child_process": false,
|
|
137
|
+
"hash-base": false,
|
|
138
|
+
"inherits": false,
|
|
139
|
+
"safe-buffer": false,
|
|
140
|
+
"string_decoder": false,
|
|
141
|
+
"process-nextick-args": false,
|
|
142
|
+
"isarray": false,
|
|
143
|
+
"core-util-is": false,
|
|
144
|
+
"util-deprecate": false,
|
|
145
|
+
"ethereum-cryptography": false,
|
|
146
|
+
"keccak": false,
|
|
147
|
+
"secp256k1": false,
|
|
148
|
+
"scrypt-js": false,
|
|
149
|
+
"bech32": false,
|
|
150
|
+
"ws": false,
|
|
151
|
+
"xhr2-cookies": false,
|
|
152
|
+
"aes-js": false,
|
|
153
|
+
"@ethersproject/sha2": false,
|
|
154
|
+
"@ethersproject/pbkdf2": false,
|
|
155
|
+
"@ethersproject/scrypt": false
|
|
156
|
+
},
|
|
157
|
+
"devDependencies": {
|
|
158
|
+
"@explorins/pers-shared": "^2.1.128",
|
|
159
|
+
"@react-native-async-storage/async-storage": "^3.0.2",
|
|
160
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
161
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
162
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
163
|
+
"@types/react": "^19.1.1",
|
|
164
|
+
"@types/react-native": "^0.72.8",
|
|
165
|
+
"rimraf": "^5.0.0",
|
|
166
|
+
"rollup": "^4.0.0",
|
|
167
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
168
|
+
"typedoc": "^0.25.13",
|
|
169
|
+
"typedoc-plugin-markdown": "^3.17.1",
|
|
170
|
+
"typescript": "^5.2.0"
|
|
171
|
+
},
|
|
172
|
+
"files": [
|
|
173
|
+
"dist/**/*",
|
|
174
|
+
"src/**/*",
|
|
175
|
+
"README.md"
|
|
176
|
+
],
|
|
177
|
+
"repository": {
|
|
178
|
+
"type": "git",
|
|
179
|
+
"url": "git+https://github.com/eXplorins/pers-sdk.git",
|
|
180
|
+
"directory": "packages/pers-sdk-react-native"
|
|
181
|
+
}
|
|
182
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -38,10 +38,13 @@ export type {
|
|
|
38
38
|
} from './useTokenBalances';
|
|
39
39
|
|
|
40
40
|
// Export campaign-related types
|
|
41
|
-
export type { CampaignClaimFilters, CampaignHook, GetCampaignsOptions } from './useCampaigns';
|
|
41
|
+
export type { CampaignClaimFilters, CampaignFilterOptions, CampaignHook, GetCampaignsOptions } from './useCampaigns';
|
|
42
42
|
|
|
43
43
|
// Export redemption-related types
|
|
44
|
-
export type { RedemptionRedeemFilters, RedemptionHook } from './useRedemptions';
|
|
44
|
+
export type { RedemptionRedeemFilters, RedemptionFilterOptions, RedemptionHook, GetRedemptionsOptions } from './useRedemptions';
|
|
45
|
+
|
|
46
|
+
// Export business-related types
|
|
47
|
+
export type { BusinessFilterOptions, BusinessHook } from './useBusiness';
|
|
45
48
|
|
|
46
49
|
// Export transaction-related types
|
|
47
50
|
export type { TransactionQueryOptions, TransactionHook } from './useTransactions';
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { useCallback } from 'react';
|
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
3
|
import type { RawUserData } from '@explorins/pers-sdk/core';
|
|
4
4
|
import { AccountOwnerType } from '@explorins/pers-sdk/core';
|
|
5
|
-
import type { UserDTO,
|
|
5
|
+
import type { UserDTO, SessionAuthContextResponseDTO } from '@explorins/pers-sdk';
|
|
6
6
|
|
|
7
7
|
// Re-export RawUserData for convenience
|
|
8
8
|
export type { RawUserData };
|
|
@@ -50,8 +50,7 @@ export const useAuth = () => {
|
|
|
50
50
|
authProvider,
|
|
51
51
|
isInitialized,
|
|
52
52
|
isAuthenticated,
|
|
53
|
-
user,
|
|
54
|
-
setAuthenticationState,
|
|
53
|
+
user,
|
|
55
54
|
refreshUserData
|
|
56
55
|
} = usePersSDK();
|
|
57
56
|
|
|
@@ -79,23 +78,15 @@ export const useAuth = () => {
|
|
|
79
78
|
// Set token in auth provider
|
|
80
79
|
await authProvider.setAccessToken(jwtToken);
|
|
81
80
|
|
|
82
|
-
// Perform login
|
|
81
|
+
// Perform login - emits login_success event which Provider handles
|
|
83
82
|
const result = await sdk.auth.loginWithToken(jwtToken, userType);
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (userData) {
|
|
88
|
-
setAuthenticationState(userData, true);
|
|
89
|
-
|
|
90
|
-
return result;
|
|
91
|
-
} else {
|
|
92
|
-
throw new Error('No user data returned from login');
|
|
93
|
-
}
|
|
84
|
+
return result;
|
|
94
85
|
} catch (error) {
|
|
95
86
|
console.error('Login failed:', error);
|
|
96
87
|
throw error;
|
|
97
88
|
}
|
|
98
|
-
}, [sdk, authProvider
|
|
89
|
+
}, [sdk, authProvider]);
|
|
99
90
|
|
|
100
91
|
/**
|
|
101
92
|
* Logs in a user using raw user data (direct authentication bypass)
|
|
@@ -115,26 +106,18 @@ export const useAuth = () => {
|
|
|
115
106
|
}
|
|
116
107
|
|
|
117
108
|
try {
|
|
118
|
-
// Use the raw data login
|
|
109
|
+
// Use the raw data login - emits login_success event which Provider handles
|
|
119
110
|
const result = await sdk.auth.loginWithRawData(rawUserData);
|
|
120
111
|
|
|
121
112
|
// Set token from result
|
|
122
113
|
if (result.accessToken) {
|
|
123
114
|
await authProvider.setAccessToken(result.accessToken);
|
|
124
115
|
}
|
|
125
|
-
|
|
126
|
-
const userData = result.user;
|
|
127
|
-
|
|
128
|
-
if (userData) {
|
|
129
|
-
setAuthenticationState(userData, true);
|
|
130
|
-
} else {
|
|
131
|
-
throw new Error('No user data returned from raw data login');
|
|
132
|
-
}
|
|
133
116
|
} catch (error) {
|
|
134
117
|
console.error('Raw data login failed:', error);
|
|
135
118
|
throw error;
|
|
136
119
|
}
|
|
137
|
-
}, [sdk, authProvider
|
|
120
|
+
}, [sdk, authProvider]);
|
|
138
121
|
|
|
139
122
|
/**
|
|
140
123
|
* Logs out the current user and clears authentication state
|
|
@@ -149,17 +132,18 @@ export const useAuth = () => {
|
|
|
149
132
|
* ```
|
|
150
133
|
*/
|
|
151
134
|
const logout = useCallback(async (): Promise<void> => {
|
|
135
|
+
if (!sdk) {
|
|
136
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
137
|
+
}
|
|
138
|
+
|
|
152
139
|
try {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
setAuthenticationState(null, false);
|
|
140
|
+
// clearAuth emits logout_success event which Provider handles
|
|
141
|
+
await sdk.auth.clearAuth();
|
|
158
142
|
} catch (error) {
|
|
159
143
|
console.error('Logout failed:', error);
|
|
160
144
|
throw error;
|
|
161
145
|
}
|
|
162
|
-
}, [
|
|
146
|
+
}, [sdk]);
|
|
163
147
|
|
|
164
148
|
/**
|
|
165
149
|
* Retrieves the current authenticated user data
|
|
@@ -237,9 +221,9 @@ export const useAuth = () => {
|
|
|
237
221
|
if (!sdk) {
|
|
238
222
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
239
223
|
}
|
|
224
|
+
// clearAuth emits logout_success event which Provider handles
|
|
240
225
|
await sdk.auth.clearAuth();
|
|
241
|
-
|
|
242
|
-
}, [sdk, setAuthenticationState]);
|
|
226
|
+
}, [sdk]);
|
|
243
227
|
|
|
244
228
|
/**
|
|
245
229
|
* Checks if the current authentication is valid (non-expired)
|
package/src/hooks/useBusiness.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import type { BusinessDTO, BusinessTypeDTO, BusinessUpdateRequestDTO, BusinessToggleActiveRequestDTO, PaginatedResponseDTO } from '@explorins/pers-
|
|
3
|
+
import type { BusinessDTO, BusinessTypeDTO, BusinessUpdateRequestDTO, BusinessToggleActiveRequestDTO, PaginatedResponseDTO, BusinessFilterOptions } from '@explorins/pers-sdk';
|
|
4
|
+
|
|
5
|
+
// Re-export for consumers
|
|
6
|
+
export type { BusinessFilterOptions } from '@explorins/pers-sdk';
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* React hook for business operations in the PERS SDK
|
|
@@ -107,13 +110,39 @@ export const useBusiness = () => {
|
|
|
107
110
|
}
|
|
108
111
|
}, [sdk, isInitialized]);
|
|
109
112
|
|
|
110
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Admin: Get all businesses with optional filtering
|
|
115
|
+
*
|
|
116
|
+
* @param options - Filter and pagination options
|
|
117
|
+
* @returns Promise resolving to paginated businesses
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Get all businesses
|
|
122
|
+
* const { data } = await getBusinesses();
|
|
123
|
+
*
|
|
124
|
+
* // Filter by tag
|
|
125
|
+
* const tagged = await getBusinesses({ tag: 'restaurant' });
|
|
126
|
+
*
|
|
127
|
+
* // Multiple tags (OR match)
|
|
128
|
+
* const multiTag = await getBusinesses({ tag: ['restaurant', 'cafe'] });
|
|
129
|
+
*
|
|
130
|
+
* // With search and pagination
|
|
131
|
+
* const filtered = await getBusinesses({
|
|
132
|
+
* search: 'coffee',
|
|
133
|
+
* active: true,
|
|
134
|
+
* page: 1,
|
|
135
|
+
* limit: 20
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
const getBusinesses = useCallback(async (options?: BusinessFilterOptions): Promise<PaginatedResponseDTO<BusinessDTO>> => {
|
|
111
140
|
if (!isInitialized || !sdk) {
|
|
112
141
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
113
142
|
}
|
|
114
143
|
|
|
115
144
|
try {
|
|
116
|
-
const result = await sdk.businesses.getBusinesses();
|
|
145
|
+
const result = await sdk.businesses.getBusinesses(options);
|
|
117
146
|
return result;
|
|
118
147
|
} catch (error) {
|
|
119
148
|
console.error('Failed to fetch all businesses:', error);
|