@explorins/pers-sdk-react-native 2.1.1 → 2.1.2

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":"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;AAG3D,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAGlC,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,WAAW,cAAc;IAE7B,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IAGpB,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,eAAe,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACtC,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAGlC,YAAY,EAAE,mBAAmB,GAAG,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,IAAI,CAAC;IAC1B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,eAAe,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACtC,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAGlC,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;CACtC;AAMD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC;IACrC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAyMA,CAAC;AAGF,eAAO,MAAM,UAAU,QAAO,cAQ7B,CAAC"}
@@ -75,30 +75,11 @@ export const PersSDKProvider = ({ children, config }) => {
75
75
  // Auto-initialize if config is provided
76
76
  useEffect(() => {
77
77
  if (config && !isInitialized && !initializingRef.current) {
78
- initialize(config).then(async () => {
79
- // Validate stored tokens on startup
80
- // SDK's initialize() already calls ensureValidToken() which handles expired tokens
81
- // This provides an additional safety layer for missing/corrupted tokens
82
- if (authProvider && sdk) {
83
- try {
84
- const hasToken = await sdk.auth.hasValidAuth();
85
- if (!hasToken) {
86
- console.log('[PersSDK] No tokens found on startup, ensuring clean state');
87
- await authProvider.clearTokens();
88
- setAuthenticationState(null, false);
89
- }
90
- // Note: Token expiration validation happens automatically in SDK's initialize()
91
- // which calls ensureValidToken() → checks expiration → triggers AUTH_FAILED if needed
92
- }
93
- catch (error) {
94
- console.warn('[PersSDK] Token validation on startup failed:', error);
95
- }
96
- }
97
- }).catch(err => {
78
+ initialize(config).catch(err => {
98
79
  console.error('Auto-initialization failed:', err);
99
80
  });
100
81
  }
101
- }, [config, isInitialized, initialize, authProvider, sdk, setAuthenticationState]);
82
+ }, [config, isInitialized, initialize]);
102
83
  const refreshUserData = useCallback(async () => {
103
84
  if (!sdk || !isAuthenticated || !isInitialized) {
104
85
  throw new Error('SDK not initialized or not authenticated. Cannot refresh user data.');
@@ -112,52 +93,36 @@ export const PersSDKProvider = ({ children, config }) => {
112
93
  throw error;
113
94
  }
114
95
  }, [sdk, isAuthenticated, isInitialized]);
115
- // Listen for authentication status changes and refresh user data when tokens are renewed
96
+ // Listen for authentication events from core SDK
97
+ // Set up immediately when SDK is created (don't wait for isInitialized)
98
+ // to catch session_restored events that fire during SDK initialization
116
99
  useEffect(() => {
117
- if (!authProvider || !isInitialized)
118
- return;
119
- // Access the config object with proper type safety
120
- const providerConfig = authProvider.config;
121
- if (!providerConfig)
100
+ if (!sdk)
122
101
  return;
123
- // Set up auth status change handler
124
- const originalHandler = providerConfig.onAuthStatusChange;
125
- const authStatusHandler = async (status) => {
126
- console.log('[PersSDK] Auth status changed:', status);
127
- // Call original handler first if it exists
128
- if (originalHandler) {
129
- await originalHandler(status);
130
- }
131
- // If token was refreshed successfully and user is authenticated, reload user data
132
- if (status === 'authenticated' && isAuthenticated && sdk) {
133
- try {
134
- console.log('[PersSDK] Token refreshed, reloading user data...');
135
- await refreshUserData();
136
- }
137
- catch (error) {
138
- console.error('[PersSDK] Failed to refresh user data after token renewal:', error);
139
- }
102
+ const unsubscribe = sdk.events.subscribe((event) => {
103
+ if (event.domain !== 'authentication')
104
+ return;
105
+ // Session restored successfully - sync React state
106
+ if (event.type === 'session_restored') {
107
+ console.log('[PersSDK] Session restoration event received, syncing state...');
108
+ sdk.users.getCurrentUser()
109
+ .then(userData => {
110
+ setAuthenticationState(userData, true);
111
+ })
112
+ .catch(error => {
113
+ console.error('[PersSDK] Failed to sync restored session:', error);
114
+ });
140
115
  }
141
- // If authentication failed, clear state
142
- // Frontend app can observe isAuthenticated state change to show custom UI
143
- if (status === 'auth_failed') {
144
- console.log('[PersSDK] Authentication failed - session expired');
145
- // Note: Token clearing already handled by SDK's handleAuthFailure()
146
- // which calls authProvider.clearTokens() with robust retry logic
147
- // Clear React state to sync with SDK
148
- // This triggers re-render, allowing app to show login screen
116
+ // Session restoration failed or auth error - clear React state
117
+ if (event.type === 'session_restoration_failed' || event.code === 'AUTH_FAILED') {
118
+ console.log('[PersSDK] Authentication failed - clearing session');
149
119
  setAuthenticationState(null, false);
150
120
  }
151
- };
152
- // Inject our handler into the auth provider config
153
- providerConfig.onAuthStatusChange = authStatusHandler;
154
- // Cleanup
121
+ }, { domains: ['authentication'] });
155
122
  return () => {
156
- if (originalHandler) {
157
- providerConfig.onAuthStatusChange = originalHandler;
158
- }
123
+ unsubscribe();
159
124
  };
160
- }, [authProvider, isInitialized, isAuthenticated, sdk, refreshUserData, setAuthenticationState]);
125
+ }, [sdk, setAuthenticationState]);
161
126
  // iOS/Android: Monitor app state and validate tokens when app becomes active
162
127
  useEffect(() => {
163
128
  if (!sdk || Platform.OS === 'web') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explorins/pers-sdk-react-native",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
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",
@@ -37,7 +37,7 @@
37
37
  "author": "eXplorins",
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "@explorins/pers-sdk": "^2.1.1",
40
+ "@explorins/pers-sdk": "^2.1.2",
41
41
  "@explorins/pers-signer": "^1.0.33",
42
42
  "buffer": "^6.0.3",
43
43
  "ethers": "^6.15.0",
package/src/index.ts CHANGED
@@ -266,7 +266,7 @@ export {
266
266
  } from './hooks';
267
267
 
268
268
  // Re-export signing status types for convenience
269
- export type { OnStatusUpdateFn, StatusUpdateData, SigningStatusType } from './hooks';
269
+ export type { OnStatusUpdateFn, StatusUpdateData, SigningStatusType, TransactionSigningResult, SubmissionResult, AuthenticatedUser } from './hooks';
270
270
 
271
271
  // Re-export event types for convenience
272
272
  export type { EventsHook, PersEvent, EventHandler, EventFilter, Unsubscribe } from './hooks';
@@ -140,29 +140,11 @@ export const PersSDKProvider: React.FC<{
140
140
  // Auto-initialize if config is provided
141
141
  useEffect(() => {
142
142
  if (config && !isInitialized && !initializingRef.current) {
143
- initialize(config).then(async () => {
144
- // Validate stored tokens on startup
145
- // SDK's initialize() already calls ensureValidToken() which handles expired tokens
146
- // This provides an additional safety layer for missing/corrupted tokens
147
- if (authProvider && sdk) {
148
- try {
149
- const hasToken = await sdk.auth.hasValidAuth();
150
- if (!hasToken) {
151
- console.log('[PersSDK] No tokens found on startup, ensuring clean state');
152
- await authProvider.clearTokens();
153
- setAuthenticationState(null, false);
154
- }
155
- // Note: Token expiration validation happens automatically in SDK's initialize()
156
- // which calls ensureValidToken() → checks expiration → triggers AUTH_FAILED if needed
157
- } catch (error) {
158
- console.warn('[PersSDK] Token validation on startup failed:', error);
159
- }
160
- }
161
- }).catch(err => {
143
+ initialize(config).catch(err => {
162
144
  console.error('Auto-initialization failed:', err);
163
145
  });
164
146
  }
165
- }, [config, isInitialized, initialize, authProvider, sdk, setAuthenticationState]);
147
+ }, [config, isInitialized, initialize]);
166
148
 
167
149
  const refreshUserData = useCallback(async (): Promise<void> => {
168
150
  if (!sdk || !isAuthenticated || !isInitialized) {
@@ -177,60 +159,38 @@ export const PersSDKProvider: React.FC<{
177
159
  throw error;
178
160
  }
179
161
  }, [sdk, isAuthenticated, isInitialized]);
180
-
181
- // Listen for authentication status changes and refresh user data when tokens are renewed
162
+ // Listen for authentication events from core SDK
163
+ // Set up immediately when SDK is created (don't wait for isInitialized)
164
+ // to catch session_restored events that fire during SDK initialization
182
165
  useEffect(() => {
183
- if (!authProvider || !isInitialized) return;
166
+ if (!sdk) return;
184
167
 
185
- // Access the config object with proper type safety
186
- const providerConfig = (authProvider as any).config;
187
- if (!providerConfig) return;
168
+ const unsubscribe = sdk.events.subscribe((event) => {
169
+ if (event.domain !== 'authentication') return;
188
170
 
189
- // Set up auth status change handler
190
- const originalHandler = providerConfig.onAuthStatusChange;
191
-
192
- const authStatusHandler = async (status: string) => {
193
- console.log('[PersSDK] Auth status changed:', status);
194
-
195
- // Call original handler first if it exists
196
- if (originalHandler) {
197
- await originalHandler(status);
198
- }
199
-
200
- // If token was refreshed successfully and user is authenticated, reload user data
201
- if (status === 'authenticated' && isAuthenticated && sdk) {
202
- try {
203
- console.log('[PersSDK] Token refreshed, reloading user data...');
204
- await refreshUserData();
205
- } catch (error) {
206
- console.error('[PersSDK] Failed to refresh user data after token renewal:', error);
207
- }
171
+ // Session restored successfully - sync React state
172
+ if (event.type === 'session_restored') {
173
+ console.log('[PersSDK] Session restoration event received, syncing state...');
174
+ sdk.users.getCurrentUser()
175
+ .then(userData => {
176
+ setAuthenticationState(userData, true);
177
+ })
178
+ .catch(error => {
179
+ console.error('[PersSDK] Failed to sync restored session:', error);
180
+ });
208
181
  }
209
-
210
- // If authentication failed, clear state
211
- // Frontend app can observe isAuthenticated state change to show custom UI
212
- if (status === 'auth_failed') {
213
- console.log('[PersSDK] Authentication failed - session expired');
214
-
215
- // Note: Token clearing already handled by SDK's handleAuthFailure()
216
- // which calls authProvider.clearTokens() with robust retry logic
217
-
218
- // Clear React state to sync with SDK
219
- // This triggers re-render, allowing app to show login screen
182
+
183
+ // Session restoration failed or auth error - clear React state
184
+ if (event.type === 'session_restoration_failed' || event.code === 'AUTH_FAILED') {
185
+ console.log('[PersSDK] Authentication failed - clearing session');
220
186
  setAuthenticationState(null, false);
221
187
  }
222
- };
223
-
224
- // Inject our handler into the auth provider config
225
- providerConfig.onAuthStatusChange = authStatusHandler;
226
-
227
- // Cleanup
188
+ }, { domains: ['authentication'] });
189
+
228
190
  return () => {
229
- if (originalHandler) {
230
- providerConfig.onAuthStatusChange = originalHandler;
231
- }
191
+ unsubscribe();
232
192
  };
233
- }, [authProvider, isInitialized, isAuthenticated, sdk, refreshUserData, setAuthenticationState]);
193
+ }, [sdk, setAuthenticationState]);
234
194
 
235
195
  // iOS/Android: Monitor app state and validate tokens when app becomes active
236
196
  useEffect(() => {