@onairos/react-native 3.0.24 → 3.0.25

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 (37) hide show
  1. package/lib/commonjs/components/OnairosButton.js +2 -3
  2. package/lib/commonjs/components/OnairosButton.js.map +1 -1
  3. package/lib/commonjs/components/TrainingModal.js +120 -16
  4. package/lib/commonjs/components/TrainingModal.js.map +1 -1
  5. package/lib/commonjs/components/UniversalOnboarding.js +131 -76
  6. package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
  7. package/lib/commonjs/components/onboarding/OAuthWebView.js +138 -27
  8. package/lib/commonjs/components/onboarding/OAuthWebView.js.map +1 -1
  9. package/lib/commonjs/constants/index.js +3 -3
  10. package/lib/commonjs/constants/index.js.map +1 -1
  11. package/lib/commonjs/services/platformAuthService.js +91 -44
  12. package/lib/commonjs/services/platformAuthService.js.map +1 -1
  13. package/lib/module/components/OnairosButton.js +2 -3
  14. package/lib/module/components/OnairosButton.js.map +1 -1
  15. package/lib/module/components/TrainingModal.js +120 -17
  16. package/lib/module/components/TrainingModal.js.map +1 -1
  17. package/lib/module/components/UniversalOnboarding.js +132 -77
  18. package/lib/module/components/UniversalOnboarding.js.map +1 -1
  19. package/lib/module/components/onboarding/OAuthWebView.js +139 -28
  20. package/lib/module/components/onboarding/OAuthWebView.js.map +1 -1
  21. package/lib/module/constants/index.js +3 -3
  22. package/lib/module/constants/index.js.map +1 -1
  23. package/lib/module/services/platformAuthService.js +88 -42
  24. package/lib/module/services/platformAuthService.js.map +1 -1
  25. package/lib/typescript/components/OnairosButton.d.ts.map +1 -1
  26. package/lib/typescript/components/TrainingModal.d.ts.map +1 -1
  27. package/lib/typescript/components/UniversalOnboarding.d.ts.map +1 -1
  28. package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +1 -1
  29. package/lib/typescript/services/platformAuthService.d.ts +11 -4
  30. package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/src/components/OnairosButton.tsx +1 -4
  33. package/src/components/TrainingModal.tsx +202 -61
  34. package/src/components/UniversalOnboarding.tsx +129 -76
  35. package/src/components/onboarding/OAuthWebView.tsx +135 -25
  36. package/src/constants/index.ts +3 -3
  37. package/src/services/platformAuthService.ts +106 -40
@@ -17,8 +17,7 @@ const PLATFORM_AUTH_CONFIG: Record<string, PlatformAuthConfig> = {
17
17
  color: '#E1306C',
18
18
  },
19
19
  youtube: {
20
- hasNativeSDK: true, // YouTube uses Google Sign-In SDK
21
- nativeSDKPackage: '@react-native-google-signin/google-signin',
20
+ hasNativeSDK: false, // Changed to false to use OAuth flow through proxy
22
21
  authEndpoint: 'https://api2.onairos.uk/youtube/authorize',
23
22
  color: '#FF0000',
24
23
  },
@@ -64,57 +63,74 @@ export const getPlatformColor = (platform: string): string => {
64
63
  };
65
64
 
66
65
  /**
67
- * Initiates the OAuth flow for a platform
66
+ * Initiates the OAuth flow for a platform using Onairos proxy
68
67
  * @param platform The platform to authenticate with
69
- * @param username The username to associate with the authentication
70
- * @returns A Promise that resolves to the OAuth URL to open in a WebView or null if using native SDK
68
+ * @param userEmail The authenticated user's email (not random username)
69
+ * @returns A Promise that resolves to the OAuth URL to open in a WebView
71
70
  */
72
- export const initiateOAuth = async (platform: string, username: string): Promise<string | null> => {
71
+ export const initiateOAuth = async (platform: string, userEmail: string): Promise<string | null> => {
73
72
  try {
74
73
  // Check if the platform is supported
75
74
  if (!PLATFORM_AUTH_CONFIG[platform]) {
76
75
  throw new Error(`Unsupported platform: ${platform}`);
77
76
  }
78
77
 
79
- // Check if platform has a native SDK
80
- if (PLATFORM_AUTH_CONFIG[platform].hasNativeSDK) {
81
- // Return null to indicate that we should use the native SDK
82
- return null;
83
- }
78
+ console.log(`Initiating OAuth for ${platform} with user: ${userEmail}`);
84
79
 
85
- // Prepare the request body
86
- const jsonData = {
80
+ // Prepare the request body according to Onairos proxy schema
81
+ const requestBody = {
87
82
  session: {
88
- username: username || 'anonymous',
83
+ username: userEmail || 'anonymous@example.com',
84
+ platform: platform,
85
+ timestamp: new Date().toISOString(),
89
86
  },
90
87
  };
91
88
 
92
- // Make the request to get the OAuth URL
89
+ console.log(`Making request to: ${PLATFORM_AUTH_CONFIG[platform].authEndpoint}`);
90
+ console.log('Request body:', JSON.stringify(requestBody, null, 2));
91
+
92
+ // Make the request to get the OAuth URL from Onairos proxy
93
93
  const response = await fetch(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
94
94
  method: 'POST',
95
95
  headers: {
96
96
  'Content-Type': 'application/json',
97
+ 'Accept': 'application/json',
97
98
  },
98
- body: JSON.stringify(jsonData),
99
+ body: JSON.stringify(requestBody),
99
100
  });
100
101
 
102
+ if (!response.ok) {
103
+ throw new Error(`HTTP error! status: ${response.status}`);
104
+ }
105
+
101
106
  // Parse the response
102
107
  const data = await response.json();
108
+ console.log(`OAuth response for ${platform}:`, data);
109
+
110
+ // Check for platform-specific response keys according to schema
111
+ let oauthUrl: string | null = null;
103
112
 
104
- // Check if the response contains the OAuth URL
105
- if (platform === 'reddit' && data.redditURL) {
106
- return data.redditURL;
113
+ if (platform === 'youtube' && data.youtubeURL) {
114
+ oauthUrl = data.youtubeURL;
115
+ } else if (platform === 'reddit' && data.redditURL) {
116
+ oauthUrl = data.redditURL;
107
117
  } else if (platform === 'pinterest' && data.pinterestURL) {
108
- return data.pinterestURL;
109
- } else if (platform === 'youtube' && data.youtubeURL) {
110
- return data.youtubeURL;
118
+ oauthUrl = data.pinterestURL;
111
119
  } else if (platform === 'email' && data.emailURL) {
112
- return data.emailURL;
120
+ oauthUrl = data.emailURL;
121
+ } else if (platform === 'instagram' && data.instagramURL) {
122
+ oauthUrl = data.instagramURL;
113
123
  } else if (data.url) {
114
- return data.url;
124
+ // Generic fallback
125
+ oauthUrl = data.url;
115
126
  }
116
127
 
117
- throw new Error(`No OAuth URL found in response for ${platform}`);
128
+ if (!oauthUrl) {
129
+ throw new Error(`No OAuth URL found in response for ${platform}. Response: ${JSON.stringify(data)}`);
130
+ }
131
+
132
+ console.log(`Successfully received OAuth URL for ${platform}: ${oauthUrl}`);
133
+ return oauthUrl;
118
134
  } catch (error) {
119
135
  console.error(`Error initiating OAuth for ${platform}:`, error);
120
136
  throw error;
@@ -128,18 +144,9 @@ export const initiateOAuth = async (platform: string, username: string): Promise
128
144
  */
129
145
  export const initiateNativeAuth = async (platform: string): Promise<boolean> => {
130
146
  try {
131
- // Currently only YouTube (Google Sign-In) is supported
132
- if (platform === 'youtube') {
133
- // This is a placeholder for the actual implementation
134
- // In a real implementation, you would import and use the Google Sign-In SDK
135
- console.log('Initiating native Google Sign-In for YouTube');
136
-
137
- // Simulate a successful authentication
138
- // In a real implementation, this would be the result of the Google Sign-In flow
139
- return true;
140
- }
141
-
142
- throw new Error(`Native authentication not supported for ${platform}`);
147
+ // Currently no platforms use native SDK - all go through Onairos proxy
148
+ console.log(`Native authentication not available for ${platform}, use OAuth flow instead`);
149
+ return false;
143
150
  } catch (error) {
144
151
  console.error(`Error initiating native auth for ${platform}:`, error);
145
152
  throw error;
@@ -153,11 +160,16 @@ export const initiateNativeAuth = async (platform: string): Promise<boolean> =>
153
160
  */
154
161
  export const handleOAuthCallback = (url: string): string | null => {
155
162
  try {
163
+ console.log('Handling OAuth callback URL:', url);
164
+
156
165
  // Parse the URL
157
166
  const parsedUrl = new URL(url);
158
167
 
159
168
  // Extract the authorization code
160
- return parsedUrl.searchParams.get('code');
169
+ const code = parsedUrl.searchParams.get('code');
170
+ console.log('Extracted authorization code:', code);
171
+
172
+ return code;
161
173
  } catch (error) {
162
174
  console.error('Error handling OAuth callback:', error);
163
175
  return null;
@@ -170,6 +182,60 @@ export const handleOAuthCallback = (url: string): string | null => {
170
182
  * @returns True if the URL is an OAuth callback
171
183
  */
172
184
  export const isOAuthCallback = (url: string): boolean => {
173
- // Check if the URL starts with our redirect URI
174
- return url.startsWith('onairosanime://auth/');
185
+ // Updated to use correct deep link scheme
186
+ const isCallback = url.startsWith('onairosevents://auth/callback') ||
187
+ url.includes('/callback') ||
188
+ url.includes('code=') ||
189
+ url.includes('onairos.uk/Home');
190
+
191
+ console.log(`Checking if URL is OAuth callback: ${url} -> ${isCallback}`);
192
+ return isCallback;
193
+ };
194
+
195
+ /**
196
+ * Detects if OAuth flow has completed successfully based on URL patterns
197
+ * @param url The current URL in the WebView
198
+ * @param platform The platform being authenticated
199
+ * @returns True if the OAuth flow has completed successfully
200
+ */
201
+ export const isOAuthSuccess = (url: string, platform: string): boolean => {
202
+ console.log(`Checking OAuth success for ${platform} with URL: ${url}`);
203
+
204
+ // Check for final redirect to Onairos home page (indicates proxy has processed the callback)
205
+ if (url.includes('onairos.uk/Home')) {
206
+ console.log('Detected final redirect to onairos.uk/Home - OAuth success');
207
+ return true;
208
+ }
209
+
210
+ // Platform-specific success patterns
211
+ switch (platform) {
212
+ case 'youtube':
213
+ // YouTube/Google OAuth success patterns
214
+ return url.includes('accounts.google.com/o/oauth2/approval') ||
215
+ url.includes('consent.google.com/ml/save') ||
216
+ url.includes('myaccount.google.com');
217
+
218
+ case 'reddit':
219
+ // Reddit OAuth success patterns
220
+ return url.includes('/api/v1/authorize?done=true') ||
221
+ url.includes('reddit.com/api/v1/authorize/compact');
222
+
223
+ case 'pinterest':
224
+ // Pinterest OAuth success patterns
225
+ return url.includes('/oauth/success') ||
226
+ url.includes('/oauth/complete');
227
+
228
+ case 'instagram':
229
+ // Instagram OAuth success patterns
230
+ return url.includes('/oauth/authorize/?response_type=code') ||
231
+ url.includes('instagram.com/oauth/authorize');
232
+
233
+ case 'email':
234
+ // Email verification success patterns
235
+ return url.includes('/email/verify/success') ||
236
+ url.includes('/email/confirmed');
237
+
238
+ default:
239
+ return false;
240
+ }
175
241
  };