@onairos/react-native 3.0.24 → 3.0.26

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 +196 -94
  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 +95 -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 +197 -95
  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 +92 -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 +188 -83
  35. package/src/components/onboarding/OAuthWebView.tsx +135 -25
  36. package/src/constants/index.ts +3 -3
  37. package/src/services/platformAuthService.ts +111 -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,79 @@ 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
+ console.log(`Response status: ${response.status}`);
103
+ console.log(`Response headers:`, response.headers);
104
+
105
+ if (!response.ok) {
106
+ const errorText = await response.text();
107
+ console.error(`HTTP error! status: ${response.status}, body: ${errorText}`);
108
+ throw new Error(`HTTP error! status: ${response.status} - ${errorText}`);
109
+ }
110
+
101
111
  // Parse the response
102
112
  const data = await response.json();
113
+ console.log(`OAuth response for ${platform}:`, data);
103
114
 
104
- // Check if the response contains the OAuth URL
105
- if (platform === 'reddit' && data.redditURL) {
106
- return data.redditURL;
115
+ // Check for platform-specific response keys according to schema
116
+ let oauthUrl: string | null = null;
117
+
118
+ if (platform === 'youtube' && data.youtubeURL) {
119
+ oauthUrl = data.youtubeURL;
120
+ } else if (platform === 'reddit' && data.redditURL) {
121
+ oauthUrl = data.redditURL;
107
122
  } else if (platform === 'pinterest' && data.pinterestURL) {
108
- return data.pinterestURL;
109
- } else if (platform === 'youtube' && data.youtubeURL) {
110
- return data.youtubeURL;
123
+ oauthUrl = data.pinterestURL;
111
124
  } else if (platform === 'email' && data.emailURL) {
112
- return data.emailURL;
125
+ oauthUrl = data.emailURL;
126
+ } else if (platform === 'instagram' && data.instagramURL) {
127
+ oauthUrl = data.instagramURL;
113
128
  } else if (data.url) {
114
- return data.url;
129
+ // Generic fallback
130
+ oauthUrl = data.url;
131
+ }
132
+
133
+ if (!oauthUrl) {
134
+ throw new Error(`No OAuth URL found in response for ${platform}. Response: ${JSON.stringify(data)}`);
115
135
  }
116
136
 
117
- throw new Error(`No OAuth URL found in response for ${platform}`);
137
+ console.log(`Successfully received OAuth URL for ${platform}: ${oauthUrl}`);
138
+ return oauthUrl;
118
139
  } catch (error) {
119
140
  console.error(`Error initiating OAuth for ${platform}:`, error);
120
141
  throw error;
@@ -128,18 +149,9 @@ export const initiateOAuth = async (platform: string, username: string): Promise
128
149
  */
129
150
  export const initiateNativeAuth = async (platform: string): Promise<boolean> => {
130
151
  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}`);
152
+ // Currently no platforms use native SDK - all go through Onairos proxy
153
+ console.log(`Native authentication not available for ${platform}, use OAuth flow instead`);
154
+ return false;
143
155
  } catch (error) {
144
156
  console.error(`Error initiating native auth for ${platform}:`, error);
145
157
  throw error;
@@ -153,11 +165,16 @@ export const initiateNativeAuth = async (platform: string): Promise<boolean> =>
153
165
  */
154
166
  export const handleOAuthCallback = (url: string): string | null => {
155
167
  try {
168
+ console.log('Handling OAuth callback URL:', url);
169
+
156
170
  // Parse the URL
157
171
  const parsedUrl = new URL(url);
158
172
 
159
173
  // Extract the authorization code
160
- return parsedUrl.searchParams.get('code');
174
+ const code = parsedUrl.searchParams.get('code');
175
+ console.log('Extracted authorization code:', code);
176
+
177
+ return code;
161
178
  } catch (error) {
162
179
  console.error('Error handling OAuth callback:', error);
163
180
  return null;
@@ -170,6 +187,60 @@ export const handleOAuthCallback = (url: string): string | null => {
170
187
  * @returns True if the URL is an OAuth callback
171
188
  */
172
189
  export const isOAuthCallback = (url: string): boolean => {
173
- // Check if the URL starts with our redirect URI
174
- return url.startsWith('onairosanime://auth/');
190
+ // Updated to use correct deep link scheme
191
+ const isCallback = url.startsWith('onairosevents://auth/callback') ||
192
+ url.includes('/callback') ||
193
+ url.includes('code=') ||
194
+ url.includes('onairos.uk/Home');
195
+
196
+ console.log(`Checking if URL is OAuth callback: ${url} -> ${isCallback}`);
197
+ return isCallback;
198
+ };
199
+
200
+ /**
201
+ * Detects if OAuth flow has completed successfully based on URL patterns
202
+ * @param url The current URL in the WebView
203
+ * @param platform The platform being authenticated
204
+ * @returns True if the OAuth flow has completed successfully
205
+ */
206
+ export const isOAuthSuccess = (url: string, platform: string): boolean => {
207
+ console.log(`Checking OAuth success for ${platform} with URL: ${url}`);
208
+
209
+ // Check for final redirect to Onairos home page (indicates proxy has processed the callback)
210
+ if (url.includes('onairos.uk/Home')) {
211
+ console.log('Detected final redirect to onairos.uk/Home - OAuth success');
212
+ return true;
213
+ }
214
+
215
+ // Platform-specific success patterns
216
+ switch (platform) {
217
+ case 'youtube':
218
+ // YouTube/Google OAuth success patterns
219
+ return url.includes('accounts.google.com/o/oauth2/approval') ||
220
+ url.includes('consent.google.com/ml/save') ||
221
+ url.includes('myaccount.google.com');
222
+
223
+ case 'reddit':
224
+ // Reddit OAuth success patterns
225
+ return url.includes('/api/v1/authorize?done=true') ||
226
+ url.includes('reddit.com/api/v1/authorize/compact');
227
+
228
+ case 'pinterest':
229
+ // Pinterest OAuth success patterns
230
+ return url.includes('/oauth/success') ||
231
+ url.includes('/oauth/complete');
232
+
233
+ case 'instagram':
234
+ // Instagram OAuth success patterns
235
+ return url.includes('/oauth/authorize/?response_type=code') ||
236
+ url.includes('instagram.com/oauth/authorize');
237
+
238
+ case 'email':
239
+ // Email verification success patterns
240
+ return url.includes('/email/verify/success') ||
241
+ url.includes('/email/confirmed');
242
+
243
+ default:
244
+ return false;
245
+ }
175
246
  };