@onairos/react-native 3.0.40 → 3.0.44

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.
Files changed (39) hide show
  1. package/lib/commonjs/components/OnairosButton.js +2 -2
  2. package/lib/commonjs/components/OnairosButton.js.map +1 -1
  3. package/lib/commonjs/components/TrainingModal.js +14 -8
  4. package/lib/commonjs/components/TrainingModal.js.map +1 -1
  5. package/lib/commonjs/components/UniversalOnboarding.js +69 -17
  6. package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
  7. package/lib/commonjs/components/onboarding/OAuthWebView.js +56 -5
  8. package/lib/commonjs/components/onboarding/OAuthWebView.js.map +1 -1
  9. package/lib/commonjs/index.js +65 -53
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/services/platformAuthService.js +64 -1
  12. package/lib/commonjs/services/platformAuthService.js.map +1 -1
  13. package/lib/module/components/OnairosButton.js +2 -2
  14. package/lib/module/components/OnairosButton.js.map +1 -1
  15. package/lib/module/components/TrainingModal.js +14 -8
  16. package/lib/module/components/TrainingModal.js.map +1 -1
  17. package/lib/module/components/UniversalOnboarding.js +72 -20
  18. package/lib/module/components/UniversalOnboarding.js.map +1 -1
  19. package/lib/module/components/onboarding/OAuthWebView.js +56 -5
  20. package/lib/module/components/onboarding/OAuthWebView.js.map +1 -1
  21. package/lib/module/index.js +37 -37
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/services/platformAuthService.js +62 -0
  24. package/lib/module/services/platformAuthService.js.map +1 -1
  25. package/lib/typescript/components/TrainingModal.d.ts.map +1 -1
  26. package/lib/typescript/components/UniversalOnboarding.d.ts.map +1 -1
  27. package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +1 -1
  28. package/lib/typescript/index.d.ts +26 -32
  29. package/lib/typescript/index.d.ts.map +1 -1
  30. package/lib/typescript/services/platformAuthService.d.ts +7 -0
  31. package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
  32. package/package.json +2 -1
  33. package/src/components/OnairosButton.tsx +2 -2
  34. package/src/components/TrainingModal.tsx +13 -7
  35. package/src/components/UniversalOnboarding.tsx +74 -18
  36. package/src/components/onboarding/OAuthWebView.tsx +51 -5
  37. package/src/index.ts +62 -67
  38. package/src/services/platformAuthService.ts +64 -0
  39. package/types/index.d.ts +5 -1
@@ -36,7 +36,13 @@ export const OAuthWebView: React.FC<OAuthWebViewProps> = ({
36
36
  const webViewRef = useRef<WebView>(null);
37
37
  const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
38
38
 
39
- console.log('Opening OAuth WebView with URL:', url);
39
+ console.log('🌐 Opening OAuth WebView with URL:', url);
40
+ console.log('🔗 Platform:', platform);
41
+ console.log('📱 URL Components:', {
42
+ protocol: url.split('://')[0],
43
+ domain: url.split('://')[1]?.split('/')[0],
44
+ path: url.split('://')[1]?.split('/').slice(1).join('/'),
45
+ });
40
46
 
41
47
  // Set up timeout for OAuth flow
42
48
  React.useEffect(() => {
@@ -157,10 +163,50 @@ export const OAuthWebView: React.FC<OAuthWebViewProps> = ({
157
163
 
158
164
  const handleError = (syntheticEvent: any) => {
159
165
  const { nativeEvent } = syntheticEvent;
160
- console.error('WebView error:', nativeEvent);
166
+ console.error('🚨 WebView error details:', {
167
+ description: nativeEvent.description,
168
+ code: nativeEvent.code,
169
+ domain: nativeEvent.domain,
170
+ url: nativeEvent.url,
171
+ canGoBack: nativeEvent.canGoBack,
172
+ canGoForward: nativeEvent.canGoForward,
173
+ loading: nativeEvent.loading,
174
+ target: nativeEvent.target,
175
+ title: nativeEvent.title,
176
+ });
177
+
178
+ // Check for specific NSURLErrorDomain codes
179
+ let errorMessage = 'Failed to load OAuth page.';
180
+
181
+ if (nativeEvent.domain === 'NSURLErrorDomain') {
182
+ switch (nativeEvent.code) {
183
+ case -1009: // NSURLErrorNotConnectedToInternet
184
+ errorMessage = 'No internet connection. Please check your network and try again.';
185
+ break;
186
+ case -1003: // NSURLErrorCannotFindHost
187
+ errorMessage = 'Cannot reach authentication server. Please check your internet connection.';
188
+ break;
189
+ case -1001: // NSURLErrorTimedOut
190
+ errorMessage = 'Connection timed out. Please try again.';
191
+ break;
192
+ case -1200: // NSURLErrorSecureConnectionFailed
193
+ errorMessage = 'Secure connection failed. Please try again.';
194
+ break;
195
+ case -1022: // NSURLErrorAppTransportSecurityRequiresSecureConnection
196
+ errorMessage = 'App Transport Security error. Connection must be secure.';
197
+ break;
198
+ case -1004: // NSURLErrorCannotConnectToHost
199
+ errorMessage = 'Cannot connect to authentication server. Please try again later.';
200
+ break;
201
+ default:
202
+ errorMessage = `Network error (${nativeEvent.code}): ${nativeEvent.description || 'Please check your connection and try again.'}`;
203
+ }
204
+ }
205
+
206
+ console.error('🔴 OAuth WebView Error:', errorMessage);
161
207
 
162
208
  if (retryCount < 2) {
163
- console.log(`Retrying OAuth load (attempt ${retryCount + 1})`);
209
+ console.log(`🔄 Retrying OAuth load (attempt ${retryCount + 1}/2)`);
164
210
  setRetryCount(prev => prev + 1);
165
211
  setIsLoading(true);
166
212
  setError(null);
@@ -170,9 +216,9 @@ export const OAuthWebView: React.FC<OAuthWebViewProps> = ({
170
216
  if (webViewRef.current) {
171
217
  webViewRef.current.reload();
172
218
  }
173
- }, 2000);
219
+ }, 3000);
174
220
  } else {
175
- setError('Failed to load OAuth page. Please try again or use the browser option.');
221
+ setError(errorMessage);
176
222
  setIsLoading(false);
177
223
  }
178
224
  };
package/src/index.ts CHANGED
@@ -3,38 +3,32 @@
3
3
  * A React Native implementation for Onairos personalized data integration
4
4
  */
5
5
 
6
- // Main components
7
- import { Onairos } from './components/Onairos';
8
- import { OnairosButton } from './components/OnairosButton';
9
- import { Overlay } from './components/Overlay';
10
- import { UniversalOnboarding } from './components/UniversalOnboarding';
11
-
12
- // Export main components
13
- export { Onairos } from './components/Onairos';
14
- export { OnairosButton } from './components/OnairosButton';
15
- export { Overlay } from './components/Overlay';
16
- export { UniversalOnboarding } from './components/UniversalOnboarding';
17
-
18
- // Export Portal components
19
- export { Portal, PortalHost } from './utils/Portal';
20
-
21
- // Screen Components
22
- export { ConnectorScreen } from './components/screens/ConnectorScreen';
23
- export { PinCreationScreen } from './components/screens/PinCreationScreen';
24
- export { LoadingScreen } from './components/screens/LoadingScreen';
25
- // export { SignInScreen } from './components/screens/SignInScreen';
6
+ // Export types first to avoid circular dependencies
7
+ export type {
8
+ OnairosButtonProps,
9
+ DataTier,
10
+ UniversalOnboardingProps,
11
+ ConnectionStatus,
12
+ PlatformListProps,
13
+ PinInputProps,
14
+ TrainingModalProps,
15
+ OAuthWebViewProps,
16
+ PlatformConfig,
17
+ ApiResponse,
18
+ CredentialsResult,
19
+ OverlayProps,
20
+ BiometricOptions,
21
+ PinRequirements,
22
+ } from './types';
26
23
 
27
- // Onboarding Components
28
- export { OAuthWebView } from './components/onboarding/OAuthWebView';
29
- export { PlatformConnector } from './components/onboarding/PlatformConnector';
30
- export { OnboardingHeader } from './components/onboarding/OnboardingHeader';
31
- export { PinInput } from './components/onboarding/PinInput';
24
+ export type { StorageOptions, OnairosCredentials } from './utils/secureStorage';
25
+ export type { OAuthConfig } from './services/oauthService';
26
+ export type { ApiErrorType, ApiError } from './utils/onairosApi';
32
27
 
33
- // Hooks
34
- export { useCredentials } from './hooks/useCredentials';
35
- export { useConnections } from './hooks/useConnections';
28
+ // Export constants
29
+ export { COLORS, PLATFORMS, API_ENDPOINTS, STORAGE_KEYS, PIN_REQUIREMENTS, DEEP_LINK_CONFIG } from './constants';
36
30
 
37
- // Utilities
31
+ // Export utilities
38
32
  export {
39
33
  storeCredentials,
40
34
  getCredentials,
@@ -67,7 +61,7 @@ export {
67
61
  isDebugMode,
68
62
  } from './utils/debugHelper';
69
63
 
70
- // Services
64
+ // Export services
71
65
  export {
72
66
  connectPlatform,
73
67
  disconnectPlatform,
@@ -76,52 +70,53 @@ export {
76
70
  storePlatformConnection,
77
71
  } from './services/oauthService';
78
72
 
79
- // Types
80
- export type {
81
- OnairosButtonProps,
82
- DataTier,
83
- UniversalOnboardingProps,
84
- ConnectionStatus,
85
- PlatformListProps,
86
- PinInputProps,
87
- TrainingModalProps,
88
- OAuthWebViewProps,
89
- PlatformConfig,
90
- ApiResponse,
91
- CredentialsResult,
92
- OverlayProps,
93
- BiometricOptions,
94
- PinRequirements,
95
- } from './types';
96
-
97
- export type { StorageOptions, OnairosCredentials } from './utils/secureStorage';
98
- export type { OAuthConfig } from './services/oauthService';
99
- export type { ApiErrorType, ApiError } from './utils/onairosApi';
100
-
101
- // Constants
102
- export { COLORS, PLATFORMS, API_ENDPOINTS, STORAGE_KEYS, PIN_REQUIREMENTS, DEEP_LINK_CONFIG } from './constants';
103
-
104
- // API and Services
73
+ // Export API and Services
105
74
  export { onairosApi } from './api';
106
75
  export { OAuthService } from './services/oauthService';
107
76
  export * from './utils/secureStorage';
108
77
  export * from './utils/encryption';
109
78
 
110
- // Define component types for default export using React.ComponentType
111
- import * as React from 'react';
112
- import type { OnairosButtonProps, UniversalOnboardingProps } from './types';
113
- import { PortalHost } from './utils/Portal';
79
+ // Export hooks
80
+ export { useCredentials } from './hooks/useCredentials';
81
+ export { useConnections } from './hooks/useConnections';
114
82
 
115
- interface OverlayComponent extends React.FC<any> {}
116
- interface OnairosComponent extends React.FC<any> {}
83
+ // Export Portal components
84
+ export { Portal, PortalHost } from './utils/Portal';
85
+
86
+ // Screen Components
87
+ export { ConnectorScreen } from './components/screens/ConnectorScreen';
88
+ export { PinCreationScreen } from './components/screens/PinCreationScreen';
89
+ export { LoadingScreen } from './components/screens/LoadingScreen';
90
+
91
+ // Onboarding Components
92
+ export { OAuthWebView } from './components/onboarding/OAuthWebView';
93
+ export { PlatformConnector } from './components/onboarding/PlatformConnector';
94
+ export { OnboardingHeader } from './components/onboarding/OnboardingHeader';
95
+
96
+ // Core Components - Export these last to avoid circular dependencies
97
+ export { PlatformList } from './components/PlatformList';
98
+ export { PinInput } from './components/PinInput';
99
+ export { TrainingModal } from './components/TrainingModal';
100
+ export { Overlay } from './components/Overlay';
101
+ export { UniversalOnboarding } from './components/UniversalOnboarding';
102
+ export { OnairosButton } from './components/OnairosButton';
103
+ export { Onairos } from './components/Onairos';
117
104
 
118
105
  // Define the public components for default export
106
+ import * as React from 'react';
107
+ import { Onairos } from './components/Onairos';
108
+ import { OnairosButton } from './components/OnairosButton';
109
+ import { Overlay } from './components/Overlay';
110
+ import { UniversalOnboarding } from './components/UniversalOnboarding';
111
+ import { PortalHost } from './utils/Portal';
112
+
113
+ // Simple default export object - main types are available through named exports
119
114
  const components = {
120
- Onairos: Onairos as OnairosComponent,
121
- OnairosButton: OnairosButton,
122
- OnairosOverlay: Overlay as OverlayComponent,
123
- UniversalOnboarding: UniversalOnboarding as React.ComponentType<UniversalOnboardingProps>,
124
- PortalHost: PortalHost,
115
+ Onairos: Onairos as any,
116
+ OnairosButton: OnairosButton as any,
117
+ OnairosOverlay: Overlay as any,
118
+ UniversalOnboarding: UniversalOnboarding as any,
119
+ PortalHost: PortalHost as any,
125
120
  };
126
121
 
127
122
  // Export the components as the default export
@@ -72,17 +72,26 @@ export const getPlatformColor = (platform: string): string => {
72
72
  */
73
73
  export const initiateOAuth = async (platform: string, username: string, appName?: string): Promise<string | null> => {
74
74
  try {
75
+ console.log('🚀 Initiating OAuth for platform:', platform);
76
+ console.log('👤 Username:', username);
77
+ console.log('📱 App name:', appName);
78
+
75
79
  // Check if the platform is supported
76
80
  if (!PLATFORM_AUTH_CONFIG[platform]) {
81
+ console.error('❌ Unsupported platform:', platform);
77
82
  throw new Error(`Unsupported platform: ${platform}`);
78
83
  }
79
84
 
80
85
  // Check if platform has a native SDK
81
86
  if (PLATFORM_AUTH_CONFIG[platform].hasNativeSDK) {
87
+ console.log('📱 Platform uses native SDK, returning null');
82
88
  // Return null to indicate that we should use the native SDK
83
89
  return null;
84
90
  }
85
91
 
92
+ console.log('🌐 Platform uses OAuth WebView flow');
93
+ console.log('🔗 Auth endpoint:', PLATFORM_AUTH_CONFIG[platform].authEndpoint);
94
+
86
95
  // Handle Instagram with specific API format
87
96
  if (platform === 'instagram') {
88
97
  const state = 'djksbfds';
@@ -93,6 +102,8 @@ export const initiateOAuth = async (platform: string, username: string, appName?
93
102
  },
94
103
  };
95
104
 
105
+ console.log('📤 Sending Instagram OAuth request:', jsonData);
106
+
96
107
  const response = await fetch('https://api2.onairos.uk/instagram/authorize', {
97
108
  method: 'POST',
98
109
  headers: {
@@ -101,12 +112,24 @@ export const initiateOAuth = async (platform: string, username: string, appName?
101
112
  body: JSON.stringify(jsonData),
102
113
  });
103
114
 
115
+ console.log('📡 Instagram OAuth response status:', response.status);
116
+ console.log('📡 Instagram OAuth response headers:', response.headers);
117
+
118
+ if (!response.ok) {
119
+ const errorText = await response.text();
120
+ console.error('❌ Instagram OAuth API error:', errorText);
121
+ throw new Error(`Instagram OAuth API error: ${response.status} - ${errorText}`);
122
+ }
123
+
104
124
  const responseData = await response.json();
125
+ console.log('📥 Instagram OAuth response data:', responseData);
105
126
 
106
127
  if (responseData.instagramURL) {
128
+ console.log('✅ Instagram OAuth URL received:', responseData.instagramURL);
107
129
  return responseData.instagramURL;
108
130
  }
109
131
 
132
+ console.error('❌ No Instagram URL found in response');
110
133
  throw new Error('No Instagram URL found in response');
111
134
  }
112
135
 
@@ -119,6 +142,8 @@ export const initiateOAuth = async (platform: string, username: string, appName?
119
142
  },
120
143
  };
121
144
 
145
+ console.log(`📤 Sending ${platform} OAuth request:`, jsonData);
146
+
122
147
  // Make the request to get the OAuth URL
123
148
  const response = await fetch(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
124
149
  method: 'POST',
@@ -128,8 +153,18 @@ export const initiateOAuth = async (platform: string, username: string, appName?
128
153
  body: JSON.stringify(jsonData),
129
154
  });
130
155
 
156
+ console.log(`📡 ${platform} OAuth response status:`, response.status);
157
+ console.log(`📡 ${platform} OAuth response headers:`, response.headers);
158
+
159
+ if (!response.ok) {
160
+ const errorText = await response.text();
161
+ console.error(`❌ ${platform} OAuth API error:`, errorText);
162
+ throw new Error(`${platform} OAuth API error: ${response.status} - ${errorText}`);
163
+ }
164
+
131
165
  // Parse the response
132
166
  const data = await response.json();
167
+ console.log(`📥 ${platform} OAuth response data:`, data);
133
168
 
134
169
  // Check if the response contains the OAuth URL based on platform
135
170
  switch (platform) {
@@ -249,3 +284,32 @@ export const isOAuthCallback = (url: string): boolean => {
249
284
  // Check if the URL starts with our redirect URI
250
285
  return url.startsWith('onairosanime://auth/');
251
286
  };
287
+
288
+ /**
289
+ * Test connectivity to the Onairos API server
290
+ */
291
+ export const testApiConnectivity = async (): Promise<{ success: boolean; error?: string }> => {
292
+ try {
293
+ console.log('🔍 Testing connectivity to Onairos API...');
294
+
295
+ const response = await fetch('https://api2.onairos.uk/health', {
296
+ method: 'GET',
297
+ headers: {
298
+ 'Content-Type': 'application/json',
299
+ },
300
+ });
301
+
302
+ console.log('🌐 API connectivity test response:', response.status);
303
+
304
+ if (response.ok) {
305
+ console.log('✅ API server is reachable');
306
+ return { success: true };
307
+ } else {
308
+ console.log('⚠️ API server responded with error:', response.status);
309
+ return { success: false, error: `API server error: ${response.status}` };
310
+ }
311
+ } catch (error) {
312
+ console.error('❌ API connectivity test failed:', error);
313
+ return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
314
+ }
315
+ };
package/types/index.d.ts CHANGED
@@ -81,7 +81,9 @@ export interface OnairosButtonProps {
81
81
  /** Whether the button is enabled */
82
82
  enabled?: boolean;
83
83
  /** Button form style */
84
- buttonForm?: 'default' | 'login' | 'signup';
84
+ buttonForm?: 'default' | 'login' | 'signup' | 'connect';
85
+ /** If true, makes API call automatically and returns result without showing UI */
86
+ auto?: boolean;
85
87
  /** Called when authentication is rejected */
86
88
  onRejection?: (error?: string) => void;
87
89
  /** Called when authentication is completed successfully */
@@ -94,6 +96,8 @@ export interface OnairosButtonProps {
94
96
  swerv?: boolean;
95
97
  /** Enable debug logging */
96
98
  debug?: boolean;
99
+ /** Enable dark mode styling */
100
+ darkMode?: boolean;
97
101
  /** Preferred platform to highlight */
98
102
  preferredPlatform?: string;
99
103
  /** Whether to use test mode */