@onairos/react-native 3.0.66 โ†’ 3.0.68

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 (29) hide show
  1. package/lib/commonjs/components/EmailVerificationModal.js +7 -6
  2. package/lib/commonjs/components/EmailVerificationModal.js.map +1 -1
  3. package/lib/commonjs/components/TrainingModal.js +17 -9
  4. package/lib/commonjs/components/TrainingModal.js.map +1 -1
  5. package/lib/commonjs/components/UniversalOnboarding.js +243 -44
  6. package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
  7. package/lib/commonjs/index.js +13 -54
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/services/platformAuthService.js +91 -40
  10. package/lib/commonjs/services/platformAuthService.js.map +1 -1
  11. package/lib/module/components/EmailVerificationModal.js +7 -6
  12. package/lib/module/components/EmailVerificationModal.js.map +1 -1
  13. package/lib/module/components/TrainingModal.js +17 -9
  14. package/lib/module/components/TrainingModal.js.map +1 -1
  15. package/lib/module/components/UniversalOnboarding.js +243 -44
  16. package/lib/module/components/UniversalOnboarding.js.map +1 -1
  17. package/lib/module/services/platformAuthService.js +91 -40
  18. package/lib/module/services/platformAuthService.js.map +1 -1
  19. package/lib/typescript/components/EmailVerificationModal.d.ts +1 -0
  20. package/lib/typescript/components/EmailVerificationModal.d.ts.map +1 -1
  21. package/lib/typescript/components/TrainingModal.d.ts.map +1 -1
  22. package/lib/typescript/components/UniversalOnboarding.d.ts.map +1 -1
  23. package/lib/typescript/services/platformAuthService.d.ts +4 -3
  24. package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/components/EmailVerificationModal.tsx +10 -6
  27. package/src/components/TrainingModal.tsx +77 -67
  28. package/src/components/UniversalOnboarding.tsx +242 -45
  29. package/src/services/platformAuthService.ts +97 -38
@@ -503,9 +503,9 @@ export const UniversalOnboarding: React.FC<UniversalOnboardingProps> = ({
503
503
 
504
504
  console.log('๐Ÿ“ง Email validation passed, proceeding...');
505
505
 
506
- // For development mode, just proceed to verification step without API call
507
- if (debug || test) {
508
- console.log('๐Ÿงช Debug/test mode: Skipping API call, proceeding to verification');
506
+ // For test mode, just proceed to verification step without API call
507
+ if (isTestMode) {
508
+ console.log('๐Ÿงช Test mode: Skipping API call, proceeding to verification');
509
509
  setStep('verify');
510
510
  return;
511
511
  }
@@ -538,7 +538,7 @@ export const UniversalOnboarding: React.FC<UniversalOnboardingProps> = ({
538
538
 
539
539
  // Race between API call and timeout
540
540
  const result = await Promise.race([
541
- requestEmailVerification(email.trim()),
541
+ requestEmailVerification(email.trim(), isTestMode),
542
542
  timeoutPromise
543
543
  ]) as any;
544
544
 
@@ -610,14 +610,14 @@ export const UniversalOnboarding: React.FC<UniversalOnboardingProps> = ({
610
610
  }
611
611
  }
612
612
 
613
- // Real API call (production)
614
- const result = await verifyEmailCode(email.trim(), verificationCode.trim());
613
+ // Real API call (production) or test mode
614
+ const result = await verifyEmailCode(email.trim(), verificationCode.trim(), isTestMode);
615
615
 
616
616
  if (result.success) {
617
617
  console.log('โœ… Email verification successful');
618
618
 
619
- // Check if user exists in backend
620
- const existingUser = (result as any).existingUser || false;
619
+ // Check if user exists in backend (properly typed now)
620
+ const existingUser = result.existingUser || false;
621
621
  setIsExistingUser(existingUser);
622
622
 
623
623
  if (existingUser) {
@@ -685,45 +685,240 @@ export const UniversalOnboarding: React.FC<UniversalOnboardingProps> = ({
685
685
  }
686
686
  }, [connections, selectedTier, platformToggles, username, AppName, auto, inferenceData, partner]);
687
687
 
688
- const handleTrainingComplete = useCallback(() => {
688
+ const handleTrainingComplete = useCallback(async () => {
689
689
  console.log('๐ŸŽ‰ Training completed successfully');
690
+ console.log('๐Ÿ” Auto mode enabled:', auto);
691
+ console.log('๐Ÿ” Inference data available:', !!inferenceData);
690
692
 
691
- // Prepare completion data
692
- const completionData = {
693
- pin,
694
- connections,
695
- platformToggles,
696
- selectedTier,
697
- tierData: requestData?.[selectedTier],
698
- sessionSaved: true,
699
- // Add inference data if auto mode is enabled
700
- ...(auto && inferenceData && { inferenceData }),
701
- // Add partner info for special partners
702
- ...(partner && { partner: partner === 'couplebible' ? 'CoupleBible' : partner }),
703
- };
704
-
705
- console.log('Completion data prepared:', completionData);
706
-
707
- // Close the modal first
708
- handleClose();
709
-
710
- // Then call the completion callback
711
- setTimeout(() => {
712
- onComplete('https://api2.onairos.uk', 'dummy-token', completionData);
713
- }, 100);
714
- }, [pin, connections, platformToggles, selectedTier, requestData, auto, inferenceData, partner, handleClose, onComplete]);
693
+ try {
694
+ if (auto && inferenceData) {
695
+ console.log('๐Ÿค– Auto mode: Making API request to get URL and perform inference');
696
+
697
+ // First, get the API URL from backend
698
+ const apiUrlResponse = await fetch('https://api2.onairos.uk/', {
699
+ method: 'POST',
700
+ headers: {
701
+ 'Content-Type': 'application/json',
702
+ },
703
+ body: JSON.stringify({
704
+ Info: {
705
+ storage: 'secure',
706
+ appId: AppName,
707
+ confirmations: Object.keys(requestData || {}),
708
+ EncryptedUserPin: pin, // Use the actual PIN from user
709
+ account: email.trim(),
710
+ proofMode: false,
711
+ }
712
+ })
713
+ });
714
+
715
+ if (!apiUrlResponse.ok) {
716
+ throw new Error(`Failed to get API URL: ${apiUrlResponse.status}`);
717
+ }
718
+
719
+ const { apiUrl, token } = await apiUrlResponse.json();
720
+ console.log('โœ… Received API URL:', apiUrl);
721
+ console.log('โœ… Received token:', token?.substring(0, 20) + '...');
722
+
723
+ // Now make the inference call with the provided data
724
+ const inferenceResponse = await fetch(apiUrl, {
725
+ method: 'POST',
726
+ headers: {
727
+ 'Content-Type': 'application/json',
728
+ 'Authorization': `Bearer ${token}`,
729
+ },
730
+ body: JSON.stringify({
731
+ ...inferenceData,
732
+ userEmail: email.trim(),
733
+ appName: AppName,
734
+ timestamp: new Date().toISOString(),
735
+ })
736
+ });
737
+
738
+ if (!inferenceResponse.ok) {
739
+ throw new Error(`Inference API failed: ${inferenceResponse.status}`);
740
+ }
741
+
742
+ const inferenceResults = await inferenceResponse.json();
743
+ console.log('โœ… Auto mode inference results:', inferenceResults);
744
+
745
+ // Close the modal first
746
+ handleClose();
747
+
748
+ // Complete onboarding with inference results
749
+ setTimeout(() => {
750
+ onComplete(apiUrl, token, {
751
+ pin,
752
+ connections,
753
+ platformToggles,
754
+ selectedTier,
755
+ tierData: requestData?.[selectedTier],
756
+ sessionSaved: true,
757
+ // Add inference data if auto mode is enabled
758
+ ...(auto && inferenceData && { inferenceData }),
759
+ // Add partner info for special partners
760
+ ...(partner && { partner: partner === 'couplebible' ? 'CoupleBible' : partner }),
761
+ autoMode: true,
762
+ inferenceResults,
763
+ apiUrl,
764
+ token,
765
+ });
766
+ }, 100);
767
+
768
+ } else {
769
+ console.log('๐Ÿ“‹ Standard mode: Returning API URL for manual use');
770
+
771
+ // Prepare completion data
772
+ const completionData = {
773
+ pin,
774
+ connections,
775
+ platformToggles,
776
+ selectedTier,
777
+ tierData: requestData?.[selectedTier],
778
+ sessionSaved: true,
779
+ // Add inference data if auto mode is enabled
780
+ ...(auto && inferenceData && { inferenceData }),
781
+ // Add partner info for special partners
782
+ ...(partner && { partner: partner === 'couplebible' ? 'CoupleBible' : partner }),
783
+ autoMode: false,
784
+ };
785
+
786
+ console.log('Completion data prepared:', completionData);
787
+
788
+ // Close the modal first
789
+ handleClose();
790
+
791
+ // Then call the completion callback
792
+ setTimeout(() => {
793
+ onComplete('https://api2.onairos.uk', 'dummy-token', completionData);
794
+ }, 100);
795
+ }
796
+ } catch (error) {
797
+ console.error('โŒ Error in training complete:', error);
798
+
799
+ // Fallback to standard mode
800
+ const completionData = {
801
+ pin,
802
+ connections,
803
+ platformToggles,
804
+ selectedTier,
805
+ tierData: requestData?.[selectedTier],
806
+ sessionSaved: true,
807
+ // Add inference data if auto mode is enabled
808
+ ...(auto && inferenceData && { inferenceData }),
809
+ // Add partner info for special partners
810
+ ...(partner && { partner: partner === 'couplebible' ? 'CoupleBible' : partner }),
811
+ autoMode: false,
812
+ error: error instanceof Error ? error.message : 'Unknown error',
813
+ };
814
+
815
+ console.log('Fallback completion data:', completionData);
816
+
817
+ // Close the modal first
818
+ handleClose();
819
+
820
+ // Then call the completion callback
821
+ setTimeout(() => {
822
+ onComplete('https://api2.onairos.uk', 'dummy-token', completionData);
823
+ }, 100);
824
+ }
825
+ }, [pin, connections, platformToggles, selectedTier, requestData, auto, inferenceData, partner, handleClose, onComplete, AppName, email]);
715
826
 
716
- const handleDataRequestAccept = useCallback(() => {
827
+ const handleDataRequestAccept = useCallback(async () => {
717
828
  console.log('Data request accepted for existing user');
829
+ console.log('๐Ÿ” Auto mode enabled:', auto);
830
+ console.log('๐Ÿ” Inference data available:', !!inferenceData);
718
831
 
719
- // Complete onboarding for existing user
720
- onComplete('https://api2.onairos.uk', 'existing-session-token', {
721
- existingAccount: true,
722
- email: email.trim(),
723
- dataRequestAccepted: true,
724
- requestData,
725
- });
726
- }, [email, onComplete, requestData]);
832
+ try {
833
+ if (auto && inferenceData) {
834
+ console.log('๐Ÿค– Auto mode: Making API request to get URL and perform inference');
835
+
836
+ // First, get the API URL from backend
837
+ const apiUrlResponse = await fetch('https://api2.onairos.uk/', {
838
+ method: 'POST',
839
+ headers: {
840
+ 'Content-Type': 'application/json',
841
+ },
842
+ body: JSON.stringify({
843
+ Info: {
844
+ storage: 'secure', // or whatever storage type
845
+ appId: AppName,
846
+ confirmations: Object.keys(requestData || {}),
847
+ EncryptedUserPin: 'temp-pin', // This would come from user PIN in real flow
848
+ account: email.trim(),
849
+ proofMode: false,
850
+ }
851
+ })
852
+ });
853
+
854
+ if (!apiUrlResponse.ok) {
855
+ throw new Error(`Failed to get API URL: ${apiUrlResponse.status}`);
856
+ }
857
+
858
+ const { apiUrl, token } = await apiUrlResponse.json();
859
+ console.log('โœ… Received API URL:', apiUrl);
860
+ console.log('โœ… Received token:', token?.substring(0, 20) + '...');
861
+
862
+ // Now make the inference call with the provided data
863
+ const inferenceResponse = await fetch(apiUrl, {
864
+ method: 'POST',
865
+ headers: {
866
+ 'Content-Type': 'application/json',
867
+ 'Authorization': `Bearer ${token}`,
868
+ },
869
+ body: JSON.stringify({
870
+ ...inferenceData,
871
+ userEmail: email.trim(),
872
+ appName: AppName,
873
+ timestamp: new Date().toISOString(),
874
+ })
875
+ });
876
+
877
+ if (!inferenceResponse.ok) {
878
+ throw new Error(`Inference API failed: ${inferenceResponse.status}`);
879
+ }
880
+
881
+ const inferenceResults = await inferenceResponse.json();
882
+ console.log('โœ… Auto mode inference results:', inferenceResults);
883
+
884
+ // Complete onboarding with inference results
885
+ onComplete(apiUrl, token, {
886
+ existingAccount: true,
887
+ email: email.trim(),
888
+ dataRequestAccepted: true,
889
+ requestData,
890
+ autoMode: true,
891
+ inferenceResults,
892
+ apiUrl,
893
+ token,
894
+ });
895
+
896
+ } else {
897
+ console.log('๐Ÿ“‹ Standard mode: Returning API URL for manual use');
898
+
899
+ // Standard mode: just return the API URL
900
+ onComplete('https://api2.onairos.uk', 'existing-session-token', {
901
+ existingAccount: true,
902
+ email: email.trim(),
903
+ dataRequestAccepted: true,
904
+ requestData,
905
+ autoMode: false,
906
+ });
907
+ }
908
+ } catch (error) {
909
+ console.error('โŒ Error in data request accept:', error);
910
+
911
+ // Fallback to standard mode
912
+ onComplete('https://api2.onairos.uk', 'existing-session-token', {
913
+ existingAccount: true,
914
+ email: email.trim(),
915
+ dataRequestAccepted: true,
916
+ requestData,
917
+ autoMode: false,
918
+ error: error instanceof Error ? error.message : 'Unknown error',
919
+ });
920
+ }
921
+ }, [email, onComplete, requestData, auto, inferenceData, AppName]);
727
922
 
728
923
  const handleDataRequestDecline = useCallback(() => {
729
924
  console.log('Data request declined');
@@ -844,9 +1039,11 @@ export const UniversalOnboarding: React.FC<UniversalOnboardingProps> = ({
844
1039
  <Text style={styles.emailSubtitle}>
845
1040
  We've sent a 6-digit code to {email}
846
1041
  </Text>
847
- <Text style={styles.developmentNote}>
848
- ๐Ÿ” Development Mode: Any 6-digit code will work
849
- </Text>
1042
+ {isTestMode && (
1043
+ <Text style={styles.developmentNote}>
1044
+ ๐Ÿ” Test Mode: Any 6-digit code will work
1045
+ </Text>
1046
+ )}
850
1047
  </View>
851
1048
 
852
1049
  <View style={styles.emailInputSection}>
@@ -174,6 +174,12 @@ export const initiateOAuth = async (platform: string, username: string, appName?
174
174
  const data = await response.json();
175
175
  console.log(`๐Ÿ“ฅ ${platform} OAuth response data:`, data);
176
176
 
177
+ // Extra logging for Gmail to help debug
178
+ if (platform === 'email') {
179
+ console.log('๐Ÿ” Gmail OAuth response keys:', Object.keys(data));
180
+ console.log('๐Ÿ” Gmail OAuth full response:', JSON.stringify(data, null, 2));
181
+ }
182
+
177
183
  // Check if the response contains the OAuth URL based on platform
178
184
  switch (platform) {
179
185
  case 'reddit':
@@ -186,13 +192,18 @@ export const initiateOAuth = async (platform: string, username: string, appName?
186
192
  if (data.youtubeURL) return data.youtubeURL;
187
193
  break;
188
194
  case 'email':
195
+ // Gmail might return under different field names
189
196
  if (data.emailURL) return data.emailURL;
197
+ if (data.gmailURL) return data.gmailURL;
198
+ if (data.authUrl) return data.authUrl;
199
+ if (data.url) return data.url;
190
200
  break;
191
201
  default:
192
202
  if (data.url) return data.url;
193
203
  break;
194
204
  }
195
205
 
206
+ console.error(`โŒ No OAuth URL found in response for ${platform}. Response:`, data);
196
207
  throw new Error(`No OAuth URL found in response for ${platform}`);
197
208
  } catch (error) {
198
209
  console.error(`Error initiating OAuth for ${platform}:`, error);
@@ -654,15 +665,17 @@ export const updateGoogleClientIds = (config: {
654
665
  * ๐Ÿ“ง EMAIL VERIFICATION FUNCTIONS
655
666
  * Using the correct Onairos email verification endpoints
656
667
  */
657
- export const requestEmailVerification = async (email: string): Promise<{
668
+ export const requestEmailVerification = async (email: string, testMode = false): Promise<{
658
669
  success: boolean;
659
670
  message?: string;
660
671
  error?: string;
661
672
  }> => {
662
673
  try {
663
674
  console.log('๐Ÿ“ง Requesting email verification for:', email);
675
+ console.log('๐Ÿ” Test mode:', testMode);
664
676
 
665
- const response = await fetch('https://api2.onairos.uk/email/verification', {
677
+ // Use the correct endpoint: /email/verify
678
+ const response = await fetch('https://api2.onairos.uk/email/verify', {
666
679
  method: 'POST',
667
680
  headers: {
668
681
  'Content-Type': 'application/json',
@@ -674,10 +687,14 @@ export const requestEmailVerification = async (email: string): Promise<{
674
687
 
675
688
  if (response.ok && result.success) {
676
689
  console.log('โœ… Email verification requested successfully');
677
- console.log('๐Ÿ” Testing mode: Code logged to server console, but accepts any code');
690
+
691
+ const message = testMode
692
+ ? 'Verification code sent to your email (testing mode: any code accepted)'
693
+ : result.message || 'Verification code sent to your email';
694
+
678
695
  return {
679
696
  success: true,
680
- message: result.message || 'Verification code sent to your email (testing mode: any code accepted)',
697
+ message,
681
698
  };
682
699
  } else {
683
700
  console.error('โŒ Email verification request failed:', result.error);
@@ -695,49 +712,72 @@ export const requestEmailVerification = async (email: string): Promise<{
695
712
  }
696
713
  };
697
714
 
698
- export const verifyEmailCode = async (email: string, code: string): Promise<{
715
+ export const verifyEmailCode = async (email: string, code: string, testMode = false): Promise<{
699
716
  success: boolean;
700
717
  message?: string;
701
718
  error?: string;
719
+ existingUser?: boolean;
702
720
  }> => {
703
721
  try {
704
722
  console.log('๐Ÿ” Verifying email code for:', email);
705
- console.log('๐Ÿ” Development mode: All codes will pass through for now');
723
+ console.log('๐Ÿ” Test mode:', testMode);
724
+
725
+ // In test mode, accept any code
726
+ if (testMode) {
727
+ console.log('๐Ÿงช Test mode: All codes will pass through');
728
+ // Simulate 30% chance of existing user in test mode
729
+ const simulateExistingUser = Math.random() < 0.3;
730
+ return {
731
+ success: true,
732
+ message: 'Email verified successfully (test mode: all codes accepted)',
733
+ existingUser: simulateExistingUser,
734
+ };
735
+ }
706
736
 
707
- // For now, allow all codes to pass through
708
- // Still make the API call to set up the routing, but don't rely on response
737
+ // Production mode: Make real API call with proper validation
709
738
  try {
710
- const response = await fetch('https://api2.onairos.uk/email/verification', {
739
+ const response = await fetch('https://api2.onairos.uk/email/verify/confirm', {
711
740
  method: 'POST',
712
741
  headers: {
713
742
  'Content-Type': 'application/json',
714
743
  },
715
- body: JSON.stringify({ email, code, action: 'verify' }),
744
+ body: JSON.stringify({ email, code }),
716
745
  });
717
746
 
718
747
  const result = await response.json();
719
748
  console.log('๐Ÿ“ก Email verification API response:', result);
749
+
750
+ if (response.ok && result.success) {
751
+ console.log('โœ… Email verification successful');
752
+ return {
753
+ success: true,
754
+ message: result.message || 'Email verified successfully',
755
+ existingUser: result.existingUser || false, // Backend should return this flag
756
+ };
757
+ } else {
758
+ console.error('โŒ Email verification failed:', result.error);
759
+ return {
760
+ success: false,
761
+ error: result.error || 'Invalid verification code',
762
+ };
763
+ }
720
764
  } catch (apiError) {
721
- console.warn('โš ๏ธ Email verification API call failed, but continuing with bypass:', apiError);
765
+ console.error('โŒ Email verification API call failed:', apiError);
766
+ return {
767
+ success: false,
768
+ error: 'Network error during verification',
769
+ };
722
770
  }
723
-
724
- // Always return success for now
725
- console.log('โœ… Email verification successful (bypass mode)');
726
- return {
727
- success: true,
728
- message: 'Email verified successfully (development mode: all codes accepted)',
729
- };
730
771
  } catch (error) {
731
772
  console.error('โŒ Email verification error:', error);
732
- // Even on error, return success for now
733
773
  return {
734
- success: true,
735
- message: 'Email verified successfully (development mode: all codes accepted)',
774
+ success: false,
775
+ error: error instanceof Error ? error.message : 'Unknown error',
736
776
  };
737
777
  }
738
778
  };
739
779
 
740
- export const checkEmailVerificationStatus = async (email: string): Promise<{
780
+ export const checkEmailVerificationStatus = async (email: string, testMode = false): Promise<{
741
781
  success: boolean;
742
782
  isPending?: boolean;
743
783
  message?: string;
@@ -745,11 +785,21 @@ export const checkEmailVerificationStatus = async (email: string): Promise<{
745
785
  }> => {
746
786
  try {
747
787
  console.log('๐Ÿ” Checking email verification status for:', email);
748
- console.log('๐Ÿ” Development mode: Always returning no pending verification');
788
+ console.log('๐Ÿ” Test mode:', testMode);
749
789
 
750
- // Make API call to set up routing, but don't rely on response for now
790
+ // In test mode, always return no pending verification
791
+ if (testMode) {
792
+ console.log('๐Ÿงช Test mode: Always returning no pending verification');
793
+ return {
794
+ success: true,
795
+ isPending: false,
796
+ message: 'Status retrieved successfully (test mode)',
797
+ };
798
+ }
799
+
800
+ // Production mode: Make real API call
751
801
  try {
752
- const response = await fetch(`https://api2.onairos.uk/email/verification/status/${encodeURIComponent(email)}`, {
802
+ const response = await fetch(`https://api2.onairos.uk/email/verify/status/${encodeURIComponent(email)}`, {
753
803
  method: 'GET',
754
804
  headers: {
755
805
  'Content-Type': 'application/json',
@@ -758,24 +808,33 @@ export const checkEmailVerificationStatus = async (email: string): Promise<{
758
808
 
759
809
  const result = await response.json();
760
810
  console.log('๐Ÿ“ก Email verification status API response:', result);
811
+
812
+ if (response.ok && result.success) {
813
+ console.log('โœ… Email verification status retrieved');
814
+ return {
815
+ success: true,
816
+ isPending: result.isPending || false,
817
+ message: result.message || 'Status retrieved successfully',
818
+ };
819
+ } else {
820
+ console.error('โŒ Email verification status failed:', result.error);
821
+ return {
822
+ success: false,
823
+ error: result.error || 'Failed to check verification status',
824
+ };
825
+ }
761
826
  } catch (apiError) {
762
- console.warn('โš ๏ธ Email verification status API call failed, but continuing with bypass:', apiError);
827
+ console.error('โŒ Email verification status API call failed:', apiError);
828
+ return {
829
+ success: false,
830
+ error: 'Network error while checking status',
831
+ };
763
832
  }
764
-
765
- // For development, always return no pending verification
766
- console.log('โœ… Email verification status retrieved (bypass mode)');
767
- return {
768
- success: true,
769
- isPending: false, // Always false so verification flow starts fresh
770
- message: 'Status retrieved successfully (development mode)',
771
- };
772
833
  } catch (error) {
773
834
  console.error('โŒ Email verification status error:', error);
774
- // Even on error, return success for development
775
835
  return {
776
- success: true,
777
- isPending: false,
778
- message: 'Status retrieved successfully (development mode)',
836
+ success: false,
837
+ error: error instanceof Error ? error.message : 'Unknown error',
779
838
  };
780
839
  }
781
840
  };