@onairos/react-native 3.0.71 → 3.0.72

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 (47) hide show
  1. package/lib/commonjs/components/Onairos.js +294 -155
  2. package/lib/commonjs/components/Onairos.js.map +1 -1
  3. package/lib/commonjs/components/OnairosButton.js +1 -1
  4. package/lib/commonjs/components/OnairosButton.js.map +1 -1
  5. package/lib/commonjs/components/UniversalOnboarding.js +6 -6
  6. package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
  7. package/lib/commonjs/components/onboarding/OAuthWebView.js +188 -52
  8. package/lib/commonjs/components/onboarding/OAuthWebView.js.map +1 -1
  9. package/lib/commonjs/index.js +66 -0
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/services/apiKeyService.js +325 -0
  12. package/lib/commonjs/services/apiKeyService.js.map +1 -0
  13. package/lib/commonjs/services/platformAuthService.js +104 -113
  14. package/lib/commonjs/services/platformAuthService.js.map +1 -1
  15. package/lib/module/components/Onairos.js +297 -158
  16. package/lib/module/components/Onairos.js.map +1 -1
  17. package/lib/module/components/OnairosButton.js +1 -1
  18. package/lib/module/components/OnairosButton.js.map +1 -1
  19. package/lib/module/components/UniversalOnboarding.js +6 -6
  20. package/lib/module/components/UniversalOnboarding.js.map +1 -1
  21. package/lib/module/components/onboarding/OAuthWebView.js +188 -52
  22. package/lib/module/components/onboarding/OAuthWebView.js.map +1 -1
  23. package/lib/module/index.js +4 -1
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/services/apiKeyService.js +310 -0
  26. package/lib/module/services/apiKeyService.js.map +1 -0
  27. package/lib/module/services/platformAuthService.js +104 -113
  28. package/lib/module/services/platformAuthService.js.map +1 -1
  29. package/lib/typescript/components/Onairos.d.ts +6 -5
  30. package/lib/typescript/components/Onairos.d.ts.map +1 -1
  31. package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +1 -1
  32. package/lib/typescript/index.d.ts +3 -2
  33. package/lib/typescript/index.d.ts.map +1 -1
  34. package/lib/typescript/services/apiKeyService.d.ts +48 -0
  35. package/lib/typescript/services/apiKeyService.d.ts.map +1 -0
  36. package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
  37. package/lib/typescript/types.d.ts +36 -3
  38. package/lib/typescript/types.d.ts.map +1 -1
  39. package/package.json +1 -1
  40. package/src/components/Onairos.tsx +336 -184
  41. package/src/components/OnairosButton.tsx +1 -1
  42. package/src/components/UniversalOnboarding.tsx +6 -6
  43. package/src/components/onboarding/OAuthWebView.tsx +236 -71
  44. package/src/index.ts +19 -0
  45. package/src/services/apiKeyService.ts +325 -0
  46. package/src/services/platformAuthService.ts +111 -130
  47. package/src/types.ts +40 -3
@@ -1,29 +1,19 @@
1
1
  import { Platform, Linking } from 'react-native';
2
2
  import AsyncStorage from '@react-native-async-storage/async-storage';
3
-
4
- // Define types for platform auth configuration
5
- interface PlatformAuthConfig {
6
- hasNativeSDK: boolean;
7
- nativeSDKPackage?: string;
8
- authEndpoint: string;
9
- color: string;
10
- clientId?: string;
11
- redirectUri?: string;
12
- scope?: string;
13
- responseType?: string;
14
- }
3
+ import type { PlatformAuthConfig } from '../types';
4
+ import { makeAuthenticatedRequest, getApiConfig } from './apiKeyService';
15
5
 
16
6
  // Configuration for each platform's authentication
17
7
  let PLATFORM_AUTH_CONFIG: Record<string, PlatformAuthConfig> = {
18
8
  instagram: {
19
9
  hasNativeSDK: false, // Instagram uses OAuth WebView flow
20
- authEndpoint: 'https://api2.onairos.uk/instagram/authorize',
10
+ authEndpoint: '/instagram/authorize',
21
11
  color: '#E1306C',
22
12
  },
23
13
  youtube: {
24
14
  hasNativeSDK: true, // Native Google Sign-In SDK enabled
25
15
  nativeSDKPackage: '@react-native-google-signin/google-signin',
26
- authEndpoint: 'https://api2.onairos.uk/youtube/authorize',
16
+ authEndpoint: '/youtube/authorize',
27
17
  color: '#FF0000',
28
18
  clientId: '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com',
29
19
  redirectUri: 'onairosevents://auth/callback',
@@ -32,17 +22,17 @@ let PLATFORM_AUTH_CONFIG: Record<string, PlatformAuthConfig> = {
32
22
  },
33
23
  reddit: {
34
24
  hasNativeSDK: false,
35
- authEndpoint: 'https://api2.onairos.uk/reddit/authorize',
25
+ authEndpoint: '/reddit/authorize',
36
26
  color: '#FF4500',
37
27
  },
38
28
  pinterest: {
39
29
  hasNativeSDK: false,
40
- authEndpoint: 'https://api2.onairos.uk/pinterest/authorize',
30
+ authEndpoint: '/pinterest/authorize',
41
31
  color: '#E60023',
42
32
  },
43
33
  email: {
44
34
  hasNativeSDK: false,
45
- authEndpoint: 'https://api2.onairos.uk/gmail/authorize',
35
+ authEndpoint: '/gmail/authorize',
46
36
  color: '#4285F4',
47
37
  },
48
38
  };
@@ -123,34 +113,12 @@ export const initiateOAuth = async (platform: string, username: string, appName?
123
113
 
124
114
  console.log('📤 Sending Instagram OAuth request:', jsonData);
125
115
 
126
- const controller = new AbortController();
127
- const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
128
-
129
- let response: Response;
130
- try {
131
- response = await fetch('https://api2.onairos.uk/instagram/authorize', {
132
- method: 'POST',
133
- headers: {
134
- 'Content-Type': 'application/json',
135
- 'User-Agent': 'OnairosReactNative/1.0',
136
- },
137
- body: JSON.stringify(jsonData),
138
- signal: controller.signal,
139
- });
140
- } catch (fetchError) {
141
- clearTimeout(timeoutId);
142
-
143
- if (fetchError.name === 'AbortError') {
144
- throw new Error(`Request timeout: Instagram OAuth server took too long to respond`);
145
- }
146
-
147
- throw new Error(`Network error: ${fetchError.message || 'Failed to connect to Instagram OAuth server'}`);
148
- }
149
-
150
- clearTimeout(timeoutId);
116
+ const response = await makeAuthenticatedRequest(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
117
+ method: 'POST',
118
+ body: JSON.stringify(jsonData),
119
+ });
151
120
 
152
121
  console.log('📡 Instagram OAuth response status:', response.status);
153
- console.log('📡 Instagram OAuth response headers:', response.headers);
154
122
 
155
123
  if (!response.ok) {
156
124
  const errorText = await response.text();
@@ -187,35 +155,13 @@ export const initiateOAuth = async (platform: string, username: string, appName?
187
155
 
188
156
  console.log(`📤 Sending ${platform} OAuth request:`, jsonData);
189
157
 
190
- // Make the request to get the OAuth URL with enhanced error handling
191
- const controller = new AbortController();
192
- const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
193
-
194
- let response: Response;
195
- try {
196
- response = await fetch(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
197
- method: 'POST',
198
- headers: {
199
- 'Content-Type': 'application/json',
200
- 'User-Agent': 'OnairosReactNative/1.0',
201
- },
202
- body: JSON.stringify(jsonData),
203
- signal: controller.signal,
204
- });
205
- } catch (fetchError) {
206
- clearTimeout(timeoutId);
207
-
208
- if (fetchError.name === 'AbortError') {
209
- throw new Error(`Request timeout: ${platform} OAuth server took too long to respond`);
210
- }
211
-
212
- throw new Error(`Network error: ${fetchError.message || 'Failed to connect to OAuth server'}`);
213
- }
214
-
215
- clearTimeout(timeoutId);
158
+ // Make the authenticated request to get the OAuth URL
159
+ const response = await makeAuthenticatedRequest(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
160
+ method: 'POST',
161
+ body: JSON.stringify(jsonData),
162
+ });
216
163
 
217
164
  console.log(`📡 ${platform} OAuth response status:`, response.status);
218
- console.log(`📡 ${platform} OAuth response headers:`, response.headers);
219
165
 
220
166
  if (!response.ok) {
221
167
  const errorText = await response.text();
@@ -837,42 +783,62 @@ export const requestEmailVerification = async (email: string, testMode = false):
837
783
  }> => {
838
784
  try {
839
785
  console.log('📧 Requesting email verification for:', email);
840
- console.log('🔍 Test mode:', testMode);
841
-
842
- // Use the correct endpoint: /email/verify
843
- const response = await fetch('https://api2.onairos.uk/email/verify', {
844
- method: 'POST',
845
- headers: {
846
- 'Content-Type': 'application/json',
847
- },
848
- body: JSON.stringify({ email }),
849
- });
786
+ console.log('🧪 Test mode:', testMode);
850
787
 
851
- const result = await response.json();
788
+ if (!email || !email.includes('@')) {
789
+ return {
790
+ success: false,
791
+ error: 'Valid email address is required',
792
+ };
793
+ }
852
794
 
853
- if (response.ok && result.success) {
854
- console.log('✅ Email verification requested successfully');
855
-
856
- const message = testMode
857
- ? 'Verification code sent to your email (testing mode: any code accepted)'
858
- : result.message || 'Verification code sent to your email';
859
-
795
+ // In test mode, always return success
796
+ if (testMode) {
797
+ console.log('🧪 Test mode: Always returning success');
860
798
  return {
861
799
  success: true,
862
- message,
800
+ message: 'Email verification sent successfully (test mode)',
863
801
  };
864
- } else {
865
- console.error('❌ Email verification request failed:', result.error);
802
+ }
803
+
804
+ // Production mode: Make real API call with API key authentication
805
+ try {
806
+ const response = await makeAuthenticatedRequest('/email/verification', {
807
+ method: 'POST',
808
+ body: JSON.stringify({
809
+ email,
810
+ action: 'request',
811
+ }),
812
+ });
813
+
814
+ const result = await response.json();
815
+ console.log('📡 Email verification API response:', result);
816
+
817
+ if (response.ok && result.success) {
818
+ console.log('✅ Email verification request sent');
819
+ return {
820
+ success: true,
821
+ message: result.message || 'Email verification sent successfully',
822
+ };
823
+ } else {
824
+ console.error('❌ Email verification request failed:', result.error);
825
+ return {
826
+ success: false,
827
+ error: result.error || 'Failed to send verification email',
828
+ };
829
+ }
830
+ } catch (apiError) {
831
+ console.error('❌ Email verification API call failed:', apiError);
866
832
  return {
867
833
  success: false,
868
- error: result.error || 'Failed to send verification code',
834
+ error: 'Network error while sending verification email',
869
835
  };
870
836
  }
871
837
  } catch (error) {
872
838
  console.error('❌ Email verification request error:', error);
873
839
  return {
874
840
  success: false,
875
- error: error instanceof Error ? error.message : 'Network error',
841
+ error: error instanceof Error ? error.message : 'Unknown error',
876
842
  };
877
843
  }
878
844
  };
@@ -885,28 +851,42 @@ export const verifyEmailCode = async (email: string, code: string, testMode = fa
885
851
  }> => {
886
852
  try {
887
853
  console.log('🔍 Verifying email code for:', email);
888
- console.log('🔍 Test mode:', testMode);
854
+ console.log('🔑 Code length:', code.length);
855
+ console.log('🧪 Test mode:', testMode);
889
856
 
890
- // In test mode, accept any code
857
+ if (!email || !email.includes('@')) {
858
+ return {
859
+ success: false,
860
+ error: 'Valid email address is required',
861
+ };
862
+ }
863
+
864
+ if (!code || code.length < 4) {
865
+ return {
866
+ success: false,
867
+ error: 'Valid verification code is required',
868
+ };
869
+ }
870
+
871
+ // In test mode, always return success
891
872
  if (testMode) {
892
- console.log('🧪 Test mode: All codes will pass through');
893
- // Simulate 30% chance of existing user in test mode
894
- const simulateExistingUser = Math.random() < 0.3;
873
+ console.log('🧪 Test mode: Always returning success');
895
874
  return {
896
875
  success: true,
897
- message: 'Email verified successfully (test mode: all codes accepted)',
898
- existingUser: simulateExistingUser,
876
+ message: 'Email verification successful (test mode)',
877
+ existingUser: false,
899
878
  };
900
879
  }
901
880
 
902
- // Production mode: Make real API call with proper validation
881
+ // Production mode: Make real API call with API key authentication
903
882
  try {
904
- const response = await fetch('https://api2.onairos.uk/email/verify/confirm', {
883
+ const response = await makeAuthenticatedRequest('/email/verification', {
905
884
  method: 'POST',
906
- headers: {
907
- 'Content-Type': 'application/json',
908
- },
909
- body: JSON.stringify({ email, code }),
885
+ body: JSON.stringify({
886
+ email,
887
+ code,
888
+ action: 'verify',
889
+ }),
910
890
  });
911
891
 
912
892
  const result = await response.json();
@@ -916,21 +896,21 @@ export const verifyEmailCode = async (email: string, code: string, testMode = fa
916
896
  console.log('✅ Email verification successful');
917
897
  return {
918
898
  success: true,
919
- message: result.message || 'Email verified successfully',
920
- existingUser: result.existingUser || false, // Backend should return this flag
899
+ message: result.message || 'Email verification successful',
900
+ existingUser: result.existingUser || false,
921
901
  };
922
902
  } else {
923
903
  console.error('❌ Email verification failed:', result.error);
924
904
  return {
925
905
  success: false,
926
- error: result.error || 'Invalid verification code',
906
+ error: result.error || 'Email verification failed',
927
907
  };
928
908
  }
929
909
  } catch (apiError) {
930
910
  console.error('❌ Email verification API call failed:', apiError);
931
911
  return {
932
912
  success: false,
933
- error: 'Network error during verification',
913
+ error: 'Network error during email verification',
934
914
  };
935
915
  }
936
916
  } catch (error) {
@@ -962,13 +942,10 @@ export const checkEmailVerificationStatus = async (email: string, testMode = fal
962
942
  };
963
943
  }
964
944
 
965
- // Production mode: Make real API call
945
+ // Production mode: Make real API call with API key authentication
966
946
  try {
967
- const response = await fetch(`https://api2.onairos.uk/email/verify/status/${encodeURIComponent(email)}`, {
947
+ const response = await makeAuthenticatedRequest(`/email/verify/status/${encodeURIComponent(email)}`, {
968
948
  method: 'GET',
969
- headers: {
970
- 'Content-Type': 'application/json',
971
- },
972
949
  });
973
950
 
974
951
  const result = await response.json();
@@ -1014,41 +991,45 @@ export const disconnectPlatform = async (platform: string, username: string): Pr
1014
991
  error?: string;
1015
992
  }> => {
1016
993
  try {
1017
- console.log(`🔌 Disconnecting ${platform} for user:`, username);
994
+ console.log('🔌 Disconnecting platform:', platform, 'for user:', username);
1018
995
 
1019
- const response = await fetch('https://api2.onairos.uk/revoke', {
996
+ if (!platform || !username) {
997
+ return {
998
+ success: false,
999
+ error: 'Platform and username are required',
1000
+ };
1001
+ }
1002
+
1003
+ // Make authenticated API call to disconnect platform
1004
+ const response = await makeAuthenticatedRequest('/revoke', {
1020
1005
  method: 'POST',
1021
- headers: {
1022
- 'Content-Type': 'application/json',
1023
- },
1024
1006
  body: JSON.stringify({
1025
- Info: {
1026
- connection: platform.charAt(0).toUpperCase() + platform.slice(1), // Capitalize platform name
1027
- username: username,
1028
- },
1007
+ platform,
1008
+ username,
1029
1009
  }),
1030
1010
  });
1031
1011
 
1032
1012
  const result = await response.json();
1013
+ console.log('📡 Platform disconnect API response:', result);
1033
1014
 
1034
1015
  if (response.ok && result.success) {
1035
- console.log(`✅ ${platform} disconnected successfully`);
1016
+ console.log('✅ Platform disconnected successfully');
1036
1017
  return {
1037
1018
  success: true,
1038
- message: result.message || `${platform} disconnected successfully`,
1019
+ message: result.message || 'Platform disconnected successfully',
1039
1020
  };
1040
1021
  } else {
1041
- console.error(`❌ ${platform} disconnection failed:`, result.error);
1022
+ console.error('❌ Platform disconnect failed:', result.error);
1042
1023
  return {
1043
1024
  success: false,
1044
- error: result.error || `Failed to disconnect ${platform}`,
1025
+ error: result.error || 'Failed to disconnect platform',
1045
1026
  };
1046
1027
  }
1047
1028
  } catch (error) {
1048
- console.error(`❌ ${platform} disconnection error:`, error);
1029
+ console.error('❌ Platform disconnect error:', error);
1049
1030
  return {
1050
1031
  success: false,
1051
- error: error instanceof Error ? error.message : 'Network error',
1032
+ error: error instanceof Error ? error.message : 'Platform disconnect failed',
1052
1033
  };
1053
1034
  }
1054
1035
  };
package/src/types.ts CHANGED
@@ -20,9 +20,33 @@ export interface TestModeOptions {
20
20
  skipRealConnections?: boolean; // Allow mock platform connections
21
21
  }
22
22
 
23
+ export interface ApiKeyConfig {
24
+ apiKey: string;
25
+ environment?: 'production' | 'staging' | 'development';
26
+ enableLogging?: boolean;
27
+ }
28
+
29
+ export interface ApiKeyValidationResult {
30
+ isValid: boolean;
31
+ error?: string;
32
+ permissions?: string[];
33
+ rateLimits?: {
34
+ remaining: number;
35
+ resetTime: number;
36
+ };
37
+ }
38
+
39
+ export interface OnairosConfig {
40
+ apiKey: string;
41
+ environment?: 'production' | 'staging' | 'development';
42
+ enableLogging?: boolean;
43
+ timeout?: number;
44
+ retryAttempts?: number;
45
+ }
46
+
23
47
  export interface UniversalOnboardingProps {
24
48
  visible: boolean;
25
- onClose: () => void;
49
+ onClose: (result?: any) => void;
26
50
  AppName: string;
27
51
  appIcon?: any; // Optional app icon (React Native ImageSourcePropType)
28
52
  requestData: {
@@ -35,17 +59,19 @@ export interface UniversalOnboardingProps {
35
59
  sentiment_analysis?: DataRequest;
36
60
  [key: string]: DataTier | DataRequest | undefined;
37
61
  };
38
- returnLink: string;
62
+ returnLink?: string;
63
+ prefillUrl?: string;
39
64
  onComplete: (apiUrl: string, token: string, data: any) => void;
40
65
  embedd?: boolean;
41
66
  debug?: boolean;
42
- test?: boolean | TestModeOptions; // Enhanced test mode with options
67
+ testMode?: TestModeOptions | boolean;
43
68
  buttonType?: 'default' | 'pill';
44
69
  buttonForm?: 'signup' | 'login';
45
70
  preferredPlatform?: string;
46
71
  inferenceData?: any; // Data used for AI inference API requests
47
72
  auto?: boolean; // If true, use inferenceData for automatic API requests
48
73
  partner?: string; // Partner identifier (e.g., "couplebible")
74
+ config?: OnairosConfig; // Add API configuration
49
75
  }
50
76
 
51
77
  export interface ConnectionStatus {
@@ -148,6 +174,17 @@ export interface PlatformConfig {
148
174
  description?: string;
149
175
  }
150
176
 
177
+ export interface PlatformAuthConfig {
178
+ hasNativeSDK: boolean;
179
+ nativeSDKPackage?: string;
180
+ authEndpoint: string;
181
+ color: string;
182
+ clientId?: string;
183
+ redirectUri?: string;
184
+ scope?: string;
185
+ responseType?: string;
186
+ }
187
+
151
188
  export interface ApiResponse<T> {
152
189
  success: boolean;
153
190
  data?: T;