@onairos/react-native 3.7.2 → 3.7.4
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.
- package/lib/commonjs/api/index.js +219 -9
- package/lib/commonjs/components/BodyText.js +27 -9
- package/lib/commonjs/components/BrandMark.js +111 -10
- package/lib/commonjs/components/CodeInput.js +120 -9
- package/lib/commonjs/components/EmailInput.js +30 -8
- package/lib/commonjs/components/GoogleButton.js +56 -9
- package/lib/commonjs/components/HeadingGroup.js +43 -9
- package/lib/commonjs/components/LLMDataInputModal.js +664 -14
- package/lib/commonjs/components/ModalHeader.js +99 -9
- package/lib/commonjs/components/ModalSheet.js +47 -9
- package/lib/commonjs/components/Onairos.js +380 -14
- package/lib/commonjs/components/OnairosButton.js +313 -13
- package/lib/commonjs/components/OnairosSignInButton.js +130 -12
- package/lib/commonjs/components/Overlay.js +465 -13
- package/lib/commonjs/components/PersonaImage.js +137 -10
- package/lib/commonjs/components/PersonaLoadingScreen.js +318 -12
- package/lib/commonjs/components/PersonalizationConsentScreen.js +467 -13
- package/lib/commonjs/components/PinCreationScreen.js +403 -12
- package/lib/commonjs/components/PinInput.js +464 -9
- package/lib/commonjs/components/PlatformConnectorsStep.js +1311 -23
- package/lib/commonjs/components/PlatformList.js +137 -10
- package/lib/commonjs/components/PlatformToggle.js +180 -9
- package/lib/commonjs/components/PrimaryButton.js +180 -10
- package/lib/commonjs/components/SignInMatchAnimation.js +197 -9
- package/lib/commonjs/components/SignInStep.js +345 -12
- package/lib/commonjs/components/UniversalOnboarding.js +2780 -30
- package/lib/commonjs/components/VerificationStep.js +176 -11
- package/lib/commonjs/components/WelcomeScreen.js +461 -22
- package/lib/commonjs/components/icons/Basicproficon.js +37 -8
- package/lib/commonjs/components/icons/Basicprofile.js +21 -8
- package/lib/commonjs/components/icons/Checkbox.js +21 -8
- package/lib/commonjs/components/icons/Checkmark.js +27 -8
- package/lib/commonjs/components/icons/Contentanalysis.js +21 -8
- package/lib/commonjs/components/icons/Contenticon.js +39 -8
- package/lib/commonjs/components/icons/EnochE.js +41 -8
- package/lib/commonjs/components/icons/Personalityicon.js +30 -8
- package/lib/commonjs/components/icons/Personalityprofile.js +21 -8
- package/lib/commonjs/components/icons/Personalitytraits.js +21 -8
- package/lib/commonjs/components/icons/Userpreferences.js +21 -8
- package/lib/commonjs/components/icons/index.js +84 -17
- package/lib/commonjs/components/onboarding/OAuthWebView.js +1754 -18
- package/lib/commonjs/components/onboarding/OnboardingHeader.js +74 -10
- package/lib/commonjs/components/onboarding/PinInput.js +283 -10
- package/lib/commonjs/components/onboarding/PlatformConnector.js +249 -11
- package/lib/commonjs/config/PLATFORM_APIS.md +849 -0
- package/lib/commonjs/config/api.js +56 -7
- package/lib/commonjs/constants/index.js +120 -7
- package/lib/commonjs/context/AuthContext.js +345 -10
- package/lib/commonjs/hooks/useConnectedAccounts.js +111 -9
- package/lib/commonjs/hooks/useConnections.js +102 -8
- package/lib/commonjs/hooks/useCredentials.js +178 -10
- package/lib/commonjs/hooks/useUserConnections.js +148 -10
- package/lib/commonjs/index.js +439 -34
- package/lib/commonjs/services/apiClient.js +298 -8
- package/lib/commonjs/services/biometricPinService.js +180 -8
- package/lib/commonjs/services/chatGPTConversationExtractor.js +155 -8
- package/lib/commonjs/services/chatGPTConversationService.js +275 -9
- package/lib/commonjs/services/claudeConversationExtractor.js +103 -8
- package/lib/commonjs/services/claudeConversationService.js +158 -9
- package/lib/commonjs/services/connectedAccountsService.js +310 -10
- package/lib/commonjs/services/googleAuthService.js +252 -11
- package/lib/commonjs/services/hingeDataExtractor.js +105 -8
- package/lib/commonjs/services/hingeDataService.js +150 -9
- package/lib/commonjs/services/imageCompressionService.js +260 -7
- package/lib/commonjs/services/instagramDataExtractor.js +126 -8
- package/lib/commonjs/services/instagramDataService.js +163 -9
- package/lib/commonjs/services/jwtStorageService.js +276 -7
- package/lib/commonjs/services/linkedinDOMExtractor.js +245 -7
- package/lib/commonjs/services/linkedinProfileService.js +222 -9
- package/lib/commonjs/services/linkedinScrapingService.js +230 -8
- package/lib/commonjs/services/llmDataStorage.js +294 -8
- package/lib/commonjs/services/mobileTrainingService.js +186 -8
- package/lib/commonjs/services/netflixDataExtractor.js +120 -8
- package/lib/commonjs/services/netflixDataService.js +198 -9
- package/lib/commonjs/services/pinEncryptionService.js +84 -8
- package/lib/commonjs/services/pinStorageUtils.js +105 -7
- package/lib/commonjs/services/platformAuthService.js +1484 -12
- package/lib/commonjs/services/sephoraDataExtractor.js +140 -8
- package/lib/commonjs/services/sephoraDataService.js +200 -9
- package/lib/commonjs/services/spotifyDataExtractor.js +148 -8
- package/lib/commonjs/services/spotifyDataService.js +241 -9
- package/lib/commonjs/services/storageService.js +404 -8
- package/lib/commonjs/services/telegramDataExtractor.js +115 -8
- package/lib/commonjs/services/telegramDataService.js +499 -9
- package/lib/commonjs/services/trainingApiHelpers.js +73 -7
- package/lib/commonjs/services/userConnectionsService.js +340 -10
- package/lib/commonjs/services/youtubeMigrationService.js +416 -10
- package/lib/commonjs/theme/index.js +250 -7
- package/lib/commonjs/types/ambient.d.js +2 -1
- package/lib/commonjs/types/declarations.d.js +2 -1
- package/lib/commonjs/types/index.js +6 -1
- package/lib/commonjs/types/node-fix.d.js +2 -1
- package/lib/commonjs/types/node-override.d.js +2 -1
- package/lib/commonjs/types/opacity.d.js +2 -1
- package/lib/commonjs/types.js +14 -1
- package/lib/commonjs/utils/Portal.js +98 -8
- package/lib/commonjs/utils/api.js +130 -9
- package/lib/commonjs/utils/assetRegistry.js +210 -35
- package/lib/commonjs/utils/auth.js +112 -9
- package/lib/commonjs/utils/connectorTests.js +613 -29
- package/lib/commonjs/utils/crypto.js +62 -8
- package/lib/commonjs/utils/debugHelper.js +64 -1
- package/lib/commonjs/utils/encryption.js +76 -7
- package/lib/commonjs/utils/eventUtils.js +288 -1
- package/lib/commonjs/utils/haptics.js +66 -9
- package/lib/commonjs/utils/imagePreloader.js +6 -1
- package/lib/commonjs/utils/networkDiagnostics.js +226 -8
- package/lib/commonjs/utils/onairosApi.js +350 -9
- package/lib/commonjs/utils/programmaticFlow.js +117 -9
- package/lib/commonjs/utils/retryHelper.js +220 -1
- package/lib/commonjs/utils/secureStorage.js +349 -10
- package/lib/commonjs/utils/webviewScripts/chatgpt.js +551 -1
- package/lib/commonjs/utils/webviewScripts/claude.js +376 -1
- package/lib/commonjs/utils/webviewScripts/hinge.js +411 -1
- package/lib/commonjs/utils/webviewScripts/index.js +698 -15
- package/lib/commonjs/utils/webviewScripts/instagram.js +454 -1
- package/lib/commonjs/utils/webviewScripts/linkedin.js +880 -1
- package/lib/commonjs/utils/webviewScripts/netflix.js +382 -1
- package/lib/commonjs/utils/webviewScripts/sephora.js +516 -1
- package/lib/commonjs/utils/webviewScripts/spotify.js +419 -1
- package/lib/commonjs/utils/webviewScripts/telegram.js +678 -1
- package/lib/module/api/index.js +211 -1
- package/lib/module/components/BodyText.js +20 -1
- package/lib/module/components/BrandMark.js +104 -1
- package/lib/module/components/CodeInput.js +113 -1
- package/lib/module/components/EmailInput.js +23 -1
- package/lib/module/components/GoogleButton.js +49 -1
- package/lib/module/components/HeadingGroup.js +36 -1
- package/lib/module/components/LLMDataInputModal.js +656 -7
- package/lib/module/components/ModalHeader.js +92 -1
- package/lib/module/components/ModalSheet.js +39 -1
- package/lib/module/components/Onairos.js +373 -1
- package/lib/module/components/OnairosButton.js +305 -1
- package/lib/module/components/OnairosSignInButton.js +121 -1
- package/lib/module/components/Overlay.js +456 -1
- package/lib/module/components/PersonaImage.js +129 -1
- package/lib/module/components/PersonaLoadingScreen.js +310 -1
- package/lib/module/components/PersonalizationConsentScreen.js +460 -1
- package/lib/module/components/PinCreationScreen.js +396 -1
- package/lib/module/components/PinInput.js +456 -1
- package/lib/module/components/PlatformConnectorsStep.js +1302 -6
- package/lib/module/components/PlatformList.js +129 -1
- package/lib/module/components/PlatformToggle.js +173 -1
- package/lib/module/components/PrimaryButton.js +172 -1
- package/lib/module/components/SignInMatchAnimation.js +189 -1
- package/lib/module/components/SignInStep.js +338 -1
- package/lib/module/components/UniversalOnboarding.js +2770 -1
- package/lib/module/components/VerificationStep.js +168 -1
- package/lib/module/components/WelcomeScreen.js +453 -1
- package/lib/module/components/icons/Basicproficon.js +30 -1
- package/lib/module/components/icons/Basicprofile.js +14 -1
- package/lib/module/components/icons/Checkbox.js +14 -1
- package/lib/module/components/icons/Checkmark.js +20 -1
- package/lib/module/components/icons/Contentanalysis.js +14 -1
- package/lib/module/components/icons/Contenticon.js +32 -1
- package/lib/module/components/icons/EnochE.js +34 -1
- package/lib/module/components/icons/Personalityicon.js +23 -1
- package/lib/module/components/icons/Personalityprofile.js +14 -1
- package/lib/module/components/icons/Personalitytraits.js +14 -1
- package/lib/module/components/icons/Userpreferences.js +14 -1
- package/lib/module/components/icons/index.js +13 -1
- package/lib/module/components/onboarding/OAuthWebView.js +1746 -1
- package/lib/module/components/onboarding/OnboardingHeader.js +66 -1
- package/lib/module/components/onboarding/PinInput.js +274 -1
- package/lib/module/components/onboarding/PlatformConnector.js +240 -1
- package/lib/module/config/PLATFORM_APIS.md +849 -0
- package/lib/module/config/api.js +47 -1
- package/lib/module/constants/index.js +114 -1
- package/lib/module/context/AuthContext.js +335 -1
- package/lib/module/hooks/useConnectedAccounts.js +106 -1
- package/lib/module/hooks/useConnections.js +95 -1
- package/lib/module/hooks/useCredentials.js +171 -6
- package/lib/module/hooks/useUserConnections.js +140 -1
- package/lib/module/index.js +172 -1
- package/lib/module/services/apiClient.js +295 -1
- package/lib/module/services/biometricPinService.js +169 -1
- package/lib/module/services/chatGPTConversationExtractor.js +149 -1
- package/lib/module/services/chatGPTConversationService.js +268 -1
- package/lib/module/services/claudeConversationExtractor.js +97 -1
- package/lib/module/services/claudeConversationService.js +151 -1
- package/lib/module/services/connectedAccountsService.js +293 -1
- package/lib/module/services/googleAuthService.js +241 -1
- package/lib/module/services/hingeDataExtractor.js +99 -1
- package/lib/module/services/hingeDataService.js +143 -1
- package/lib/module/services/imageCompressionService.js +250 -1
- package/lib/module/services/instagramDataExtractor.js +120 -1
- package/lib/module/services/instagramDataService.js +156 -1
- package/lib/module/services/jwtStorageService.js +257 -1
- package/lib/module/services/linkedinDOMExtractor.js +234 -1
- package/lib/module/services/linkedinProfileService.js +210 -1
- package/lib/module/services/linkedinScrapingService.js +219 -1
- package/lib/module/services/llmDataStorage.js +277 -1
- package/lib/module/services/mobileTrainingService.js +173 -1
- package/lib/module/services/netflixDataExtractor.js +114 -1
- package/lib/module/services/netflixDataService.js +191 -1
- package/lib/module/services/pinEncryptionService.js +74 -6
- package/lib/module/services/pinStorageUtils.js +93 -1
- package/lib/module/services/platformAuthService.js +1461 -1
- package/lib/module/services/sephoraDataExtractor.js +134 -1
- package/lib/module/services/sephoraDataService.js +193 -1
- package/lib/module/services/spotifyDataExtractor.js +142 -1
- package/lib/module/services/spotifyDataService.js +234 -1
- package/lib/module/services/storageService.js +383 -1
- package/lib/module/services/telegramDataExtractor.js +109 -1
- package/lib/module/services/telegramDataService.js +493 -1
- package/lib/module/services/trainingApiHelpers.js +67 -1
- package/lib/module/services/userConnectionsService.js +329 -1
- package/lib/module/services/youtubeMigrationService.js +405 -1
- package/lib/module/theme/index.js +245 -1
- package/lib/module/types.js +10 -1
- package/lib/module/utils/Portal.js +90 -1
- package/lib/module/utils/api.js +118 -1
- package/lib/module/utils/assetRegistry.js +200 -34
- package/lib/module/utils/auth.js +100 -1
- package/lib/module/utils/connectorTests.js +600 -27
- package/lib/module/utils/crypto.js +54 -1
- package/lib/module/utils/debugHelper.js +54 -1
- package/lib/module/utils/encryption.js +67 -1
- package/lib/module/utils/eventUtils.js +270 -1
- package/lib/module/utils/haptics.js +59 -8
- package/lib/module/utils/imagePreloader.js +3 -1
- package/lib/module/utils/networkDiagnostics.js +217 -1
- package/lib/module/utils/onairosApi.js +333 -1
- package/lib/module/utils/programmaticFlow.js +111 -1
- package/lib/module/utils/retryHelper.js +211 -1
- package/lib/module/utils/secureStorage.js +330 -6
- package/lib/module/utils/webviewScripts/chatgpt.js +545 -1
- package/lib/module/utils/webviewScripts/claude.js +370 -1
- package/lib/module/utils/webviewScripts/hinge.js +405 -1
- package/lib/module/utils/webviewScripts/index.js +434 -1
- package/lib/module/utils/webviewScripts/instagram.js +448 -1
- package/lib/module/utils/webviewScripts/linkedin.js +874 -1
- package/lib/module/utils/webviewScripts/netflix.js +376 -1
- package/lib/module/utils/webviewScripts/sephora.js +510 -1
- package/lib/module/utils/webviewScripts/spotify.js +413 -1
- package/lib/module/utils/webviewScripts/telegram.js +672 -1
- package/package.json +2 -2
|
@@ -1 +1,217 @@
|
|
|
1
|
-
import{Platform}from'react-native';function _0x2a23(_0x1a3eeb,_0x2a23da){_0x1a3eeb=_0x1a3eeb-0x0;const _0x41a92b=_0x1a3e();let _0x2b0201=_0x41a92b[_0x1a3eeb];return _0x2b0201;}import{API_CONFIG}from'../config/api';export const runFullDiagnostics=async()=>{const _0x65da6d={'IMcqO':'offline','TKhOy':_0x2a23(0x0),'xehuf':function(_0x19dae2,_0x378477){return _0x19dae2+_0x378477;},'FizOg':'═══════════════════════════════════════════','vmgcS':_0x2a23(0x1),'dHhBT':_0x2a23(0x2),'adtBw':function(_0x35a74e,_0x4065f3,_0x436c8b){return _0x35a74e(_0x4065f3,_0x436c8b);},'vaify':_0x2a23(0x3),'kPjTo':function(_0x46bfe3,_0x512ea0){return _0x46bfe3-_0x512ea0;},'OTsGb':function(_0x31f805,_0x23409d){return _0x31f805!==_0x23409d;},'NETSI':'cEeRv','yBBEk':'3|1|2|4|0','RkJuy':function(_0x57a0a6,_0x491865){return _0x57a0a6-_0x491865;},'LgjTn':_0x2a23(0x4),'kJexw':_0x2a23(0x5),'pwHIm':'diagnostic_test','masGz':'youtube','yQGtw':function(_0x19a40b,_0x4ff0d2){return _0x19a40b-_0x4ff0d2;},'eDqTj':function(_0x4cee51,_0x446efa){return _0x4cee51===_0x446efa;},'fuDyt':'FMhhE','wjRaA':'WwXjv','ouNrC':_0x2a23(0x6),'eGbFO':_0x2a23(0x7),'sfSYp':_0x2a23(0x8),'yDMVn':function(_0x57949f,_0x4fb729){return _0x57949f===_0x4fb729;},'uhTzB':_0x2a23(0x9),'PhqIH':_0x2a23(0xa),'gVCKk':_0x2a23(0xb),'RCtey':_0x2a23(0xc),'fWoyl':'onAdn','LcXsy':'Device\x20has\x20no\x20internet\x20-\x20check\x20WiFi/cellular','oKrVj':_0x2a23(0xd)};console[_0x2a23(0xe)](_0x65da6d[_0x2a23(0xf)]),console[_0x2a23(0xe)]('🔍\x20ONAIROS\x20SDK\x20NETWORK\x20DIAGNOSTICS'),console['log'](_0x65da6d[_0x2a23(0xf)]);const _0x247d4f={'timestamp':new Date()[_0x2a23(0x10)](),'platform':Platform['OS'],'platformVersion':Platform[_0x2a23(0x11)],'tests':{'googleReachable':![],'apiReachable':![],'apiPostWorks':![],'youtubeOAuthWorks':![]},'errors':[],'recommendations':[],'rawResults':{}};console[_0x2a23(0xe)](_0x2a23(0x12)+Platform['OS']+'\x20'+Platform[_0x2a23(0x11)]),console[_0x2a23(0xe)](_0x65da6d[_0x2a23(0x13)]),console['log'](_0x65da6d[_0x2a23(0x14)]);try{const _0x39ba42=Date[_0x2a23(0x15)](),_0x42e145=await _0x65da6d[_0x2a23(0x16)](fetch,_0x2a23(0x17),{'method':_0x65da6d['vaify']}),_0x22f73a=_0x65da6d[_0x2a23(0x18)](Date[_0x2a23(0x15)](),_0x39ba42);_0x247d4f['tests'][_0x2a23(0x19)]=!![],_0x247d4f[_0x2a23(0x1a)][_0x2a23(0x1b)]={'status':_0x42e145[_0x2a23(0x1c)],'time':_0x22f73a},console[_0x2a23(0xe)](_0x2a23(0x1d)+_0x22f73a+_0x2a23(0x1e));}catch(_0x18f761){if(_0x65da6d[_0x2a23(0x1f)](_0x2a23(0x20),_0x65da6d['NETSI'])){const _0xe48d70=_0x65da6d[_0x2a23(0x21)][_0x2a23(0x22)]('|');let _0x299f8c=0x0;while(!![]){switch(_0xe48d70[_0x299f8c++]){case'0':_0x247d4f[_0x2a23(0x23)]['push'](_0x2a23(0x24));continue;case'1':_0x247d4f['errors']['push']('Google\x20unreachable:\x20'+_0x18f761[_0x2a23(0x25)]);continue;case'2':_0x247d4f[_0x2a23(0x1a)]['google']={'error':_0x18f761[_0x2a23(0x25)]};continue;case'3':_0x247d4f[_0x2a23(0x26)][_0x2a23(0x19)]=![];continue;case'4':console['log']('\x20\x20\x20❌\x20FAIL\x20-\x20'+_0x18f761[_0x2a23(0x25)]);continue;}break;}}else _0x434651[_0x2a23(0x23)]['push'](_0x2a23(0x27));}console[_0x2a23(0xe)]('\x0a🧪\x20Test\x202:\x20API\x20Reachability\x20(API\x20server/health)');try{const _0x344b1b=Date[_0x2a23(0x15)](),_0x54ccac=await fetch(API_CONFIG['BASE_URL']+_0x2a23(0x28),{'method':'GET','headers':{'Accept':'application/json'}}),_0x21b835=_0x65da6d[_0x2a23(0x29)](Date['now'](),_0x344b1b),_0x24a4a5=await _0x54ccac[_0x2a23(0x2a)]()['catch'](()=>_0x2a23(0x2b));_0x247d4f[_0x2a23(0x26)][_0x2a23(0x2c)]=_0x54ccac['ok'],_0x247d4f[_0x2a23(0x1a)][_0x2a23(0x2d)]={'status':_0x54ccac[_0x2a23(0x1c)],'time':_0x21b835,'body':_0x24a4a5[_0x2a23(0x2e)](0x0,0xc8)},_0x54ccac['ok']?console['log'](_0x2a23(0x2f)+_0x21b835+_0x2a23(0x1e)):_0x65da6d['LgjTn']===_0x65da6d['LgjTn']?(console[_0x2a23(0xe)](_0x2a23(0x30)+_0x54ccac[_0x2a23(0x1c)]),_0x247d4f[_0x2a23(0x31)]['push'](_0x2a23(0x32)+_0x54ccac[_0x2a23(0x1c)])):(_0x350521[_0x2a23(0xe)](_0x2a23(0x30)+_0x967c00[_0x2a23(0x1c)]),_0xe0b573[_0x2a23(0x31)][_0x2a23(0x33)](_0x2a23(0x32)+_0x5704db['status']));}catch(_0x334e29){_0x247d4f[_0x2a23(0x26)]['apiReachable']=![],_0x247d4f[_0x2a23(0x31)]['push'](_0x2a23(0x34)+_0x334e29[_0x2a23(0x25)]),_0x247d4f[_0x2a23(0x1a)][_0x2a23(0x2d)]={'error':_0x334e29[_0x2a23(0x25)]},console[_0x2a23(0xe)](_0x2a23(0x35)+_0x334e29[_0x2a23(0x25)]),_0x247d4f['tests']['googleReachable']&&(_0x65da6d['kJexw']==='JdHxJ'?_0x4d3de9[_0x2a23(0xe)](_0x2a23(0x2f)+_0x20feeb+_0x2a23(0x1e)):_0x247d4f['recommendations'][_0x2a23(0x33)](_0x2a23(0x27)));}console['log']('\n\uD83E\uDDEA Test 3: POST Request (OAuth simulation)');try{const _0x336625=Date[_0x2a23(0x15)](),_0x1be305=await fetch(API_CONFIG[_0x2a23(0x36)]+_0x2a23(0x37),{'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/json'},'body':JSON[_0x2a23(0x38)]({'session':{'username':_0x65da6d[_0x2a23(0x39)],'platform':_0x65da6d[_0x2a23(0x3a)],'timestamp':new Date()['toISOString']()}})}),_0x2e2944=_0x65da6d['yQGtw'](Date['now'](),_0x336625),_0x526c17=await _0x1be305[_0x2a23(0x2a)]()['catch'](()=>_0x2a23(0x2b));_0x247d4f['rawResults'][_0x2a23(0x3b)]={'status':_0x1be305[_0x2a23(0x1c)],'time':_0x2e2944,'body':_0x526c17[_0x2a23(0x2e)](0x0,0x1f4)},_0x247d4f[_0x2a23(0x26)][_0x2a23(0x3c)]=!![],console[_0x2a23(0xe)]('\x20\x20\x20✅\x20PASS\x20-\x20POST\x20request\x20succeeded,\x20status:\x20'+_0x1be305['status']+'\x20('+_0x2e2944+_0x2a23(0x1e));try{const _0x7a629=JSON['parse'](_0x526c17);_0x7a629[_0x2a23(0x3d)]&&(_0x247d4f[_0x2a23(0x26)][_0x2a23(0x3e)]=!![],console[_0x2a23(0xe)]('\x20\x20\x20✅\x20BONUS\x20-\x20Got\x20YouTube\x20OAuth\x20URL!'));}catch{}}catch(_0x3365cd){if(_0x65da6d[_0x2a23(0x3f)](_0x65da6d['fuDyt'],_0x65da6d[_0x2a23(0x40)]))return _0x65da6d[_0x2a23(0x41)];else{const _0x34ae6=_0x65da6d['ouNrC'][_0x2a23(0x22)]('|');let _0x35f2a5=0x0;while(!![]){switch(_0x34ae6[_0x35f2a5++]){case'0':_0x247d4f[_0x2a23(0x26)]['apiPostWorks']=![];continue;case'1':console[_0x2a23(0xe)](_0x2a23(0x35)+_0x3365cd['message']);continue;case'2':_0x247d4f[_0x2a23(0x23)][_0x2a23(0x33)]('POST requests failing. This is the exact issue affecting OAuth.');continue;case'3':_0x247d4f[_0x2a23(0x1a)][_0x2a23(0x3b)]={'error':_0x3365cd[_0x2a23(0x25)]};continue;case'4':_0x247d4f[_0x2a23(0x31)]['push']('POST\x20request\x20failed:\x20'+_0x3365cd['message']);continue;}break;}}}console[_0x2a23(0xe)](_0x2a23(0x42)),console['log'](_0x65da6d[_0x2a23(0x43)]),console[_0x2a23(0xe)](_0x65da6d['vmgcS']);const _0x351128=Object[_0x2a23(0x44)](_0x247d4f['tests'])['filter'](Boolean)[_0x2a23(0x45)],_0x3d5fea=Object[_0x2a23(0x46)](_0x247d4f[_0x2a23(0x26)])[_0x2a23(0x45)];console[_0x2a23(0xe)](_0x2a23(0x47)+_0x351128+'/'+_0x3d5fea);if(_0x65da6d[_0x2a23(0x3f)](_0x351128,_0x3d5fea)){if(_0x65da6d['OTsGb'](_0x65da6d[_0x2a23(0x48)],_0x65da6d['sfSYp']))return _0x65da6d['TKhOy'];else console[_0x2a23(0xe)](_0x2a23(0x49));}else console['log'](_0x2a23(0x4a)),_0x65da6d[_0x2a23(0x4b)](Platform['OS'],_0x65da6d[_0x2a23(0x4c)])&&!_0x247d4f['tests'][_0x2a23(0x2c)]&&_0x247d4f[_0x2a23(0x23)][_0x2a23(0x33)](_0x65da6d['PhqIH'],_0x65da6d[_0x2a23(0x4d)]),!_0x247d4f[_0x2a23(0x26)][_0x2a23(0x19)]&&(_0x65da6d['RCtey']!==_0x65da6d[_0x2a23(0x4e)]?_0x247d4f[_0x2a23(0x23)]['push'](_0x65da6d['LcXsy']):(_0x4d327d[_0x2a23(0x26)][_0x2a23(0x3e)]=!![],_0x2d021a[_0x2a23(0xe)]('\x20\x20\x20✅\x20BONUS\x20-\x20Got\x20YouTube\x20OAuth\x20URL!'))),console[_0x2a23(0xe)](_0x65da6d[_0x2a23(0x4f)]),_0x247d4f[_0x2a23(0x23)][_0x2a23(0x50)]((_0x401d77,_0x38d207)=>{console[_0x2a23(0xe)](_0x2a23(0x51)+_0x65da6d['xehuf'](_0x38d207,0x1)+'.\x20'+_0x401d77);});return console[_0x2a23(0xe)](_0x2a23(0x52)),console[_0x2a23(0xe)]('Full\x20results\x20object\x20logged\x20below\x20for\x20debugging:'),console[_0x2a23(0xe)](JSON[_0x2a23(0x38)](_0x247d4f,null,0x2)),_0x247d4f;};function _0x1a3e(){const _0x591621=['api_unreachable','───────────────────────────────────────────','\x0a🧪\x20Test\x201:\x20Internet\x20Connectivity\x20(google.com)','HEAD','PyvQH','IIbZU','0|4|3|1|2','📋\x20SUMMARY','hDvvq','ios','iOS:\x20Add\x20NSAppTransportSecurity\x20to\x20Info.plist','iOS:\x20Try\x20on\x20physical\x20device\x20instead\x20of\x20simulator','blayd','\x0a📌\x20RECOMMENDATIONS:','log','FizOg','toISOString','Version','📱\x20Platform:\x20','vmgcS','dHhBT','now','adtBw','https://www.google.com','kPjTo','googleReachable','rawResults','google','status','\x20\x20\x20✅\x20PASS\x20-\x20Google\x20reachable\x20(','ms)','OTsGb','FIcLv','yBBEk','split','recommendations','Check\x20internet\x20connection\x20on\x20device','message','tests','Internet\x20works\x20but\x20API\x20blocked.\x20Check:\x20VPN,\x20Firewall,\x20iOS\x20ATS\x20settings','/health','RkJuy','text','Unable\x20to\x20read','apiReachable','apiHealth','substring','\x20\x20\x20✅\x20PASS\x20-\x20API\x20reachable\x20(','\x20\x20\x20⚠️\x20PARTIAL\x20-\x20API\x20responded\x20with\x20','errors','API\x20returned\x20status\x20','push','API\x20unreachable:\x20','\x20\x20\x20❌\x20FAIL\x20-\x20','BASE_URL','/youtube/authorize','stringify','pwHIm','masGz','apiPost','apiPostWorks','youtubeURL','youtubeOAuthWorks','eDqTj','wjRaA','IMcqO','\x0a───────────────────────────────────────────','eGbFO','values','length','keys','\x0aTests\x20Passed:\x20','sfSYp','\x0a✅\x20ALL\x20TESTS\x20PASSED\x20-\x20SDK\x20should\x20work\x20correctly','\x0a⚠️\x20SOME\x20TESTS\x20FAILED\x20-\x20See\x20recommendations\x20below:','yDMVn','uhTzB','gVCKk','fWoyl','oKrVj','forEach','\x20\x20\x20','\x0a═══════════════════════════════════════════','zOkLA','Xjlbs','qbRfN','Grzuu','online','qvNhu','offline','RjTmr','AMQqW','ptsFN','eezYj','uuyRW','MzAAX','cRdlw','JIpmq','AQOca','sgWAG','parse','\x20\x20\x20✅\x20BONUS\x20-\x20Got\x20YouTube\x20OAuth\x20URL!','JWHAj'];_0x1a3e=function(){return _0x591621;};return _0x1a3e();}export const isApiReachable=async()=>{const _0x7f3281={'AJHho':function(_0x14a8bf,_0x2a485c,_0xfd5dff){return _0x14a8bf(_0x2a485c,_0xfd5dff);},'Xjlbs':function(_0x1600f4,_0xcd44c4){return _0x1600f4!==_0xcd44c4;},'qbRfN':_0x2a23(0x53),'etOFM':'otvxK'};try{const _0x2c20f1=await _0x7f3281['AJHho'](fetch,API_CONFIG['BASE_URL']+_0x2a23(0x28),{'method':'GET'});return _0x2c20f1['ok'];}catch{if(_0x7f3281[_0x2a23(0x54)](_0x7f3281[_0x2a23(0x55)],_0x7f3281['etOFM']))return![];else _0x50371d[_0x2a23(0xe)]('\x20\x20\x20'+(_0x540c7d+0x1)+'.\x20'+_0x3d16cc);}};export const getNetworkStatus=async()=>{const _0x141dda={'RjTmr':function(_0x56863f,_0x2c0dc7,_0xe14a7f){return _0x56863f(_0x2c0dc7,_0xe14a7f);},'AMQqW':_0x2a23(0x17),'ptsFN':_0x2a23(0x3),'eezYj':function(_0x516069,_0x247133){return _0x516069(_0x247133);},'uuyRW':function(_0x5c3b7b,_0x312717){return _0x5c3b7b===_0x312717;},'cRdlw':_0x2a23(0x56),'JIpmq':_0x2a23(0x57),'AQOca':_0x2a23(0x58),'sgWAG':_0x2a23(0x0),'JWHAj':_0x2a23(0x59)};try{await _0x141dda[_0x2a23(0x5a)](fetch,_0x141dda[_0x2a23(0x5b)],{'method':_0x141dda[_0x2a23(0x5c)]});const _0x1b21cb=await _0x141dda[_0x2a23(0x5d)](fetch,API_CONFIG['BASE_URL']+_0x2a23(0x28));if(_0x1b21cb['ok']){if(_0x141dda[_0x2a23(0x5e)](_0x2a23(0x5f),_0x141dda[_0x2a23(0x60)]))_0x28a30b[_0x2a23(0xe)](_0x2a23(0x49));else return _0x141dda[_0x2a23(0x61)];}else{if(_0x141dda[_0x2a23(0x5e)]('qvNhu',_0x141dda[_0x2a23(0x62)]))return _0x141dda[_0x2a23(0x63)];else{const _0x14d835=_0xa6c3ff[_0x2a23(0x64)](_0x3bc9ef);_0x14d835[_0x2a23(0x3d)]&&(_0x5863e4[_0x2a23(0x26)][_0x2a23(0x3e)]=!![],_0x5d9976[_0x2a23(0xe)](_0x2a23(0x65)));}}}catch{return _0x141dda[_0x2a23(0x66)];}};
|
|
1
|
+
/**
|
|
2
|
+
* Network Diagnostics Utility for Onairos SDK
|
|
3
|
+
*
|
|
4
|
+
* Use this to diagnose network issues with OAuth flows.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { runFullDiagnostics } from '@onairos/react-native';
|
|
9
|
+
*
|
|
10
|
+
* const results = await runFullDiagnostics();
|
|
11
|
+
* console.log(results);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { Platform } from 'react-native';
|
|
16
|
+
import { API_CONFIG } from '../config/api';
|
|
17
|
+
/**
|
|
18
|
+
* Run comprehensive network diagnostics
|
|
19
|
+
* Call this to test if the SDK can connect to required services
|
|
20
|
+
*/
|
|
21
|
+
export const runFullDiagnostics = async () => {
|
|
22
|
+
console.log('═══════════════════════════════════════════');
|
|
23
|
+
console.log('🔍 ONAIROS SDK NETWORK DIAGNOSTICS');
|
|
24
|
+
console.log('═══════════════════════════════════════════');
|
|
25
|
+
const result = {
|
|
26
|
+
timestamp: new Date().toISOString(),
|
|
27
|
+
platform: Platform.OS,
|
|
28
|
+
platformVersion: Platform.Version,
|
|
29
|
+
tests: {
|
|
30
|
+
googleReachable: false,
|
|
31
|
+
apiReachable: false,
|
|
32
|
+
apiPostWorks: false,
|
|
33
|
+
youtubeOAuthWorks: false
|
|
34
|
+
},
|
|
35
|
+
errors: [],
|
|
36
|
+
recommendations: [],
|
|
37
|
+
rawResults: {}
|
|
38
|
+
};
|
|
39
|
+
console.log(`📱 Platform: ${Platform.OS} ${Platform.Version}`);
|
|
40
|
+
console.log('───────────────────────────────────────────');
|
|
41
|
+
|
|
42
|
+
// Test 1: Can we reach the internet at all? (Google)
|
|
43
|
+
console.log('\n🧪 Test 1: Internet Connectivity (google.com)');
|
|
44
|
+
try {
|
|
45
|
+
const googleStart = Date.now();
|
|
46
|
+
const googleRes = await fetch('https://www.google.com', {
|
|
47
|
+
method: 'HEAD'
|
|
48
|
+
});
|
|
49
|
+
const googleTime = Date.now() - googleStart;
|
|
50
|
+
result.tests.googleReachable = true;
|
|
51
|
+
result.rawResults.google = {
|
|
52
|
+
status: googleRes.status,
|
|
53
|
+
time: googleTime
|
|
54
|
+
};
|
|
55
|
+
console.log(` ✅ PASS - Google reachable (${googleTime}ms)`);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
result.tests.googleReachable = false;
|
|
58
|
+
result.errors.push(`Google unreachable: ${error.message}`);
|
|
59
|
+
result.rawResults.google = {
|
|
60
|
+
error: error.message
|
|
61
|
+
};
|
|
62
|
+
console.log(` ❌ FAIL - ${error.message}`);
|
|
63
|
+
result.recommendations.push('Check internet connection on device');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Test 2: Can we reach API server?
|
|
67
|
+
console.log('\n🧪 Test 2: API Reachability (API server/health)');
|
|
68
|
+
try {
|
|
69
|
+
const apiStart = Date.now();
|
|
70
|
+
const apiRes = await fetch(`${API_CONFIG.BASE_URL}/health`, {
|
|
71
|
+
method: 'GET',
|
|
72
|
+
headers: {
|
|
73
|
+
'Accept': 'application/json'
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const apiTime = Date.now() - apiStart;
|
|
77
|
+
const apiBody = await apiRes.text().catch(() => 'Unable to read');
|
|
78
|
+
result.tests.apiReachable = apiRes.ok;
|
|
79
|
+
result.rawResults.apiHealth = {
|
|
80
|
+
status: apiRes.status,
|
|
81
|
+
time: apiTime,
|
|
82
|
+
body: apiBody.substring(0, 200)
|
|
83
|
+
};
|
|
84
|
+
if (apiRes.ok) {
|
|
85
|
+
console.log(` ✅ PASS - API reachable (${apiTime}ms)`);
|
|
86
|
+
} else {
|
|
87
|
+
console.log(` ⚠️ PARTIAL - API responded with ${apiRes.status}`);
|
|
88
|
+
result.errors.push(`API returned status ${apiRes.status}`);
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
result.tests.apiReachable = false;
|
|
92
|
+
result.errors.push(`API unreachable: ${error.message}`);
|
|
93
|
+
result.rawResults.apiHealth = {
|
|
94
|
+
error: error.message
|
|
95
|
+
};
|
|
96
|
+
console.log(` ❌ FAIL - ${error.message}`);
|
|
97
|
+
if (result.tests.googleReachable) {
|
|
98
|
+
result.recommendations.push('Internet works but API blocked. Check: VPN, Firewall, iOS ATS settings');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Test 3: Can we make POST requests?
|
|
103
|
+
console.log('\n🧪 Test 3: POST Request (OAuth simulation)');
|
|
104
|
+
try {
|
|
105
|
+
const postStart = Date.now();
|
|
106
|
+
const postRes = await fetch(`${API_CONFIG.BASE_URL}/youtube/authorize`, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
'Accept': 'application/json'
|
|
111
|
+
},
|
|
112
|
+
body: JSON.stringify({
|
|
113
|
+
session: {
|
|
114
|
+
username: 'diagnostic_test',
|
|
115
|
+
platform: 'youtube',
|
|
116
|
+
timestamp: new Date().toISOString()
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
const postTime = Date.now() - postStart;
|
|
121
|
+
const postBody = await postRes.text().catch(() => 'Unable to read');
|
|
122
|
+
result.rawResults.apiPost = {
|
|
123
|
+
status: postRes.status,
|
|
124
|
+
time: postTime,
|
|
125
|
+
body: postBody.substring(0, 500)
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// Any response is good - we're testing if the request gets through
|
|
129
|
+
result.tests.apiPostWorks = true;
|
|
130
|
+
console.log(` ✅ PASS - POST request succeeded, status: ${postRes.status} (${postTime}ms)`);
|
|
131
|
+
|
|
132
|
+
// Check if we got an OAuth URL back
|
|
133
|
+
try {
|
|
134
|
+
const data = JSON.parse(postBody);
|
|
135
|
+
if (data.youtubeURL) {
|
|
136
|
+
result.tests.youtubeOAuthWorks = true;
|
|
137
|
+
console.log(` ✅ BONUS - Got YouTube OAuth URL!`);
|
|
138
|
+
}
|
|
139
|
+
} catch {
|
|
140
|
+
// Not JSON or no URL - that's fine for this test
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
result.tests.apiPostWorks = false;
|
|
144
|
+
result.errors.push(`POST request failed: ${error.message}`);
|
|
145
|
+
result.rawResults.apiPost = {
|
|
146
|
+
error: error.message
|
|
147
|
+
};
|
|
148
|
+
console.log(` ❌ FAIL - ${error.message}`);
|
|
149
|
+
result.recommendations.push('POST requests failing. This is the exact issue affecting OAuth.');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Generate recommendations
|
|
153
|
+
console.log('\n───────────────────────────────────────────');
|
|
154
|
+
console.log('📋 SUMMARY');
|
|
155
|
+
console.log('───────────────────────────────────────────');
|
|
156
|
+
const passCount = Object.values(result.tests).filter(Boolean).length;
|
|
157
|
+
const totalTests = Object.keys(result.tests).length;
|
|
158
|
+
console.log(`\nTests Passed: ${passCount}/${totalTests}`);
|
|
159
|
+
if (passCount === totalTests) {
|
|
160
|
+
console.log('\n✅ ALL TESTS PASSED - SDK should work correctly');
|
|
161
|
+
} else {
|
|
162
|
+
console.log('\n⚠️ SOME TESTS FAILED - See recommendations below:');
|
|
163
|
+
|
|
164
|
+
// Add platform-specific recommendations
|
|
165
|
+
if (Platform.OS === 'ios' && !result.tests.apiReachable) {
|
|
166
|
+
result.recommendations.push('iOS: Add NSAppTransportSecurity to Info.plist', 'iOS: Try on physical device instead of simulator');
|
|
167
|
+
}
|
|
168
|
+
if (!result.tests.googleReachable) {
|
|
169
|
+
result.recommendations.push('Device has no internet - check WiFi/cellular');
|
|
170
|
+
}
|
|
171
|
+
console.log('\n📌 RECOMMENDATIONS:');
|
|
172
|
+
result.recommendations.forEach((rec, i) => {
|
|
173
|
+
console.log(` ${i + 1}. ${rec}`);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
console.log('\n═══════════════════════════════════════════');
|
|
177
|
+
console.log('Full results object logged below for debugging:');
|
|
178
|
+
console.log(JSON.stringify(result, null, 2));
|
|
179
|
+
return result;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Quick connectivity check - returns true if API is reachable
|
|
184
|
+
*/
|
|
185
|
+
export const isApiReachable = async () => {
|
|
186
|
+
try {
|
|
187
|
+
const response = await fetch(`${API_CONFIG.BASE_URL}/health`, {
|
|
188
|
+
method: 'GET'
|
|
189
|
+
});
|
|
190
|
+
return response.ok;
|
|
191
|
+
} catch {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Get a simple status string for display to users
|
|
198
|
+
*/
|
|
199
|
+
export const getNetworkStatus = async () => {
|
|
200
|
+
try {
|
|
201
|
+
// Check Google first
|
|
202
|
+
await fetch('https://www.google.com', {
|
|
203
|
+
method: 'HEAD'
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Check our API
|
|
207
|
+
const apiRes = await fetch(`${API_CONFIG.BASE_URL}/health`);
|
|
208
|
+
if (apiRes.ok) {
|
|
209
|
+
return 'online';
|
|
210
|
+
} else {
|
|
211
|
+
return 'api_unreachable';
|
|
212
|
+
}
|
|
213
|
+
} catch {
|
|
214
|
+
return 'offline';
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
//# sourceMappingURL=networkDiagnostics.js.map
|
|
@@ -1 +1,333 @@
|
|
|
1
|
-
function _0x554c(_0x375775,_0x554c7d){_0x375775=_0x375775-0x0;const _0x7c0cd0=_0x3757();let _0x2adf40=_0x7c0cd0[_0x375775];return _0x2adf40;}import NetInfo from'@react-native-community/netinfo';import{logDebug}from'./debugHelper';import{getJWT,makeUserRequest,makeDeveloperRequest,isUserAuthenticated,extractUsernameFromJWT}from'../services/apiKeyService';export class ApiError extends Error{constructor(_0x122ae4,_0x2b22c7,_0x57765e,_0x1776b2){const _0x419d79={'bYJtW':_0x554c(0x0),'VIvpg':_0x554c(0x1)},_0x1e1bc4=_0x419d79[_0x554c(0x2)][_0x554c(0x3)]('|');let _0x2d167a=0x0;while(!![]){switch(_0x1e1bc4[_0x2d167a++]){case'0':super(_0x122ae4);continue;case'1':this[_0x554c(0x4)]=_0x419d79[_0x554c(0x5)];continue;case'2':this[_0x554c(0x6)]=_0x57765e;continue;case'3':this['details']=_0x1776b2;continue;case'4':this['type']=_0x2b22c7;continue;}break;}}}const checkNetworkConnection=async()=>{const _0xf7a8f3={'JqyvU':function(_0x4c7488,_0x116ab7){return _0x4c7488===_0x116ab7;}},_0x4d725a=await NetInfo[_0x554c(0x7)]();return _0xf7a8f3[_0x554c(0x8)](_0x4d725a[_0x554c(0x9)],!![]);},makeUserApiRequest=async(_0x256465,_0x1c84c7,_0x1b371c={})=>{const _0x5a5547={'vevZc':function(_0x1b1285,_0x7fee68,_0x1804f0){return _0x1b1285(_0x7fee68,_0x1804f0);},'mmGnb':_0x554c(0xa),'CbXej':'Unknown\x20error','SbbwS':function(_0x1c7c33){return _0x1c7c33();},'RSUvm':_0x554c(0xb),'NqaTF':_0x554c(0xc),'USIbJ':'User\x20not\x20authenticated.\x20Please\x20verify\x20email\x20first.','jLsCj':function(_0x16bb68,_0x41da4b){return _0x16bb68===_0x41da4b;},'SruXT':_0x554c(0xd),'kFucP':_0x554c(0xe),'bLYfQ':_0x554c(0xf),'MnSYD':function(_0x1d55fe,_0x230906){return _0x1d55fe===_0x230906;},'HvDwN':_0x554c(0x10),'ihnFw':function(_0x28ab59,_0x33b83e){return _0x28ab59===_0x33b83e;},'qMuvC':function(_0x57fb37,_0x2a0c2c){return _0x57fb37>=_0x2a0c2c;},'mgmDf':_0x554c(0x11),'pGKSe':_0x554c(0x12),'REQGU':function(_0x4a8317,_0x41f530){return _0x4a8317===_0x41f530;},'JboIj':function(_0x97e1e2,_0x469c81){return _0x97e1e2===_0x469c81;},'bTNwf':'API\x20request\x20failed','HPNEH':function(_0x3b7119,_0x3edbf9){return _0x3b7119===_0x3edbf9;},'oSeWq':function(_0x135c80,_0x198872){return _0x135c80===_0x198872;},'yXUxk':function(_0x28df35,_0x4bc5b6){return _0x28df35 instanceof _0x4bc5b6;},'ONacN':function(_0x27ca3e,_0x21e34c){return _0x27ca3e===_0x21e34c;},'QofSS':_0x554c(0x13),'exoPS':_0x554c(0x14),'WpXVu':function(_0xdd6088,_0x53624d,_0x352c34){return _0xdd6088(_0x53624d,_0x352c34);},'VcHDX':_0x554c(0x15),'QSLFD':_0x554c(0x16)},{data:_0x315a04,headers:headers={},debug:debug=![]}=_0x1b371c;try{const _0x2ec285=await _0x5a5547[_0x554c(0x17)](checkNetworkConnection);if(!_0x2ec285)throw new ApiError(_0x5a5547['RSUvm'],_0x5a5547[_0x554c(0x18)]);if(!_0x5a5547['SbbwS'](isUserAuthenticated))throw new ApiError(_0x5a5547[_0x554c(0x19)],_0x554c(0x1a));debug&&(_0x5a5547[_0x554c(0x1b)](_0x5a5547[_0x554c(0x1c)],_0x5a5547['SruXT'])?_0x5a5547[_0x554c(0x1d)](logDebug,_0x5a5547[_0x554c(0x1e)],{'endpoint':_0x256465,'method':_0x1c84c7,'headers':{...headers,'Authorization':_0x5a5547[_0x554c(0x1f)]},'data':_0x315a04||null}):_0x5a5547[_0x554c(0x1d)](_0x142333,_0x5a5547[_0x554c(0x20)],{'status':_0xfe1e01['status'],'data':_0x11e1fd}));const _0x7fc576=await _0x5a5547['vevZc'](makeUserRequest,_0x256465,{'method':_0x1c84c7,'headers':headers,..._0x315a04?{'body':JSON[_0x554c(0x21)](_0x315a04)}:{}}),_0x5f5d9a=await _0x7fc576[_0x554c(0x22)]();debug&&logDebug(_0x5a5547[_0x554c(0x20)],{'status':_0x7fc576[_0x554c(0x23)],'data':_0x5f5d9a});if(!_0x7fc576['ok']){if(_0x5a5547[_0x554c(0x24)](_0x5a5547[_0x554c(0x25)],_0x554c(0x26)))_0x5a5547[_0x554c(0x1d)](_0x2001e6,_0x554c(0x15),{'endpoint':_0x3f2910,'method':_0x3bc42d,'error':_0x4ed539['message']||_0x5a5547[_0x554c(0x27)]});else{var _0x165f68,_0x243592,_0x44bce1;const _0x4db5c3=_0x5a5547[_0x554c(0x1b)](_0x7fc576[_0x554c(0x23)],0x191)||_0x5a5547['ihnFw'](_0x7fc576[_0x554c(0x23)],0x193)?'auth_error':_0x7fc576[_0x554c(0x23)]===0x190?_0x554c(0x28):_0x5a5547[_0x554c(0x29)](_0x7fc576[_0x554c(0x23)],0x1f4)?_0x5a5547[_0x554c(0x2a)]:_0x5a5547[_0x554c(0x2b)];throw new ApiError((_0x5a5547[_0x554c(0x2c)](_0x165f68=_0x5f5d9a[_0x554c(0x2d)],null)||_0x5a5547[_0x554c(0x2e)](_0x165f68,void 0x0)?void 0x0:_0x165f68['message'])||_0x5a5547['bTNwf'],_0x4db5c3,_0x5a5547[_0x554c(0x2f)](_0x243592=_0x5f5d9a[_0x554c(0x2d)],null)||_0x243592===void 0x0?void 0x0:_0x243592[_0x554c(0x6)],_0x5a5547[_0x554c(0x30)](_0x44bce1=_0x5f5d9a[_0x554c(0x2d)],null)||_0x5a5547[_0x554c(0x31)](_0x44bce1,void 0x0)?void 0x0:_0x44bce1[_0x554c(0x32)]);}}return _0x5f5d9a;}catch(_0x35d6b5){if(_0x5a5547[_0x554c(0x33)](_0x35d6b5,ApiError))throw _0x35d6b5;if(_0x5a5547[_0x554c(0x34)](_0x35d6b5['name'],_0x5a5547[_0x554c(0x35)]))throw new ApiError(_0x554c(0x36),_0x5a5547['exoPS']);debug&&_0x5a5547[_0x554c(0x37)](logDebug,_0x5a5547[_0x554c(0x38)],{'endpoint':_0x256465,'method':_0x1c84c7,'error':_0x35d6b5[_0x554c(0x39)]||_0x554c(0x3a)});throw new ApiError(_0x35d6b5[_0x554c(0x39)]||_0x5a5547['QSLFD'],_0x5a5547[_0x554c(0x2b)]);}},makeDeveloperApiRequest=async(_0x454ee7,_0xa52c7b,_0x942017={})=>{const _0x4cab26={'OgNHC':'Developer\x20API\x20Request','GFJlJ':_0x554c(0xf),'nPIix':function(_0x39ca3e,_0x450562){return _0x39ca3e||_0x450562;},'xZrVs':function(_0x564c0e,_0x492113){return _0x564c0e===_0x492113;},'qzKtL':_0x554c(0x13),'AYRbj':_0x554c(0x14),'vPxsX':function(_0xd3c4cb,_0x43d7a8,_0xab9b65){return _0xd3c4cb(_0x43d7a8,_0xab9b65);},'OVJUW':_0x554c(0x15),'gUzTz':_0x554c(0x3a),'oHLOz':_0x554c(0x16),'pBRSt':'unknown_error','aCGPv':_0x554c(0x3b),'aaQfc':_0x554c(0x1a),'gPCMh':function(_0x26bea7,_0x570c1e,_0x346924,_0x370c3e){return _0x26bea7(_0x570c1e,_0x346924,_0x370c3e);},'FBULR':_0x554c(0x36),'HprRq':'nfjaX','FeZTA':function(_0xc02c05,_0x521d6b){return _0xc02c05!==_0x521d6b;},'NhRJD':_0x554c(0x3c),'xqpek':_0x554c(0xb),'hNoQs':_0x554c(0xc),'kNoWm':function(_0x261f54,_0x269004){return _0x261f54===_0x269004;},'mlhCH':_0x554c(0x3d),'rnUHY':_0x554c(0x3e),'oMZvS':'fwmCR','GtXuS':function(_0x541584,_0x26592b,_0x3e6067){return _0x541584(_0x26592b,_0x3e6067);},'nyERO':function(_0x49651b,_0x4eb573){return _0x49651b===_0x4eb573;},'FGGWx':_0x554c(0x28),'kSTnH':function(_0x218d7e,_0x7182ad){return _0x218d7e>=_0x7182ad;},'mpAOL':'server_error','dRQPU':function(_0x29e6b8,_0x11d9bb){return _0x29e6b8===_0x11d9bb;},'ZKabk':function(_0x3e66c8,_0x4327f4){return _0x3e66c8===_0x4327f4;},'vACCJ':function(_0x167641,_0x30c195){return _0x167641===_0x30c195;},'Nrbxh':function(_0x54e518,_0x466523){return _0x54e518 instanceof _0x466523;},'BSVvM':_0x554c(0x3f)},{data:_0x7acb03,headers:headers={},debug:debug=![]}=_0x942017;try{if(_0x554c(0x40)===_0x4cab26[_0x554c(0x41)])_0x2d7e7b(_0x4cab26[_0x554c(0x42)],{'endpoint':_0x726bc9,'method':_0x5d13df,'headers':{..._0xcdf92c,'Authorization':_0x4cab26[_0x554c(0x43)]},'data':_0x4cab26[_0x554c(0x44)](_0x3ffbfb,null)});else{const _0x4f7c2d=await checkNetworkConnection();if(!_0x4f7c2d){if(_0x4cab26[_0x554c(0x45)](_0x4cab26[_0x554c(0x46)],_0x4cab26['NhRJD'])){if(_0x35313e instanceof _0x173a94)throw _0x5c7507;if(_0x4cab26[_0x554c(0x47)](_0x54268c[_0x554c(0x4)],_0x4cab26[_0x554c(0x48)]))throw new _0x146805(_0x554c(0x36),_0x4cab26[_0x554c(0x49)]);_0x5615aa&&_0x4cab26[_0x554c(0x4a)](_0xe281a9,_0x4cab26['OVJUW'],{'endpoint':_0x48b220,'method':_0x22da39,'error':_0x2b65c7['message']||_0x4cab26[_0x554c(0x4b)]});throw new _0x1e99aa(_0x9ead99[_0x554c(0x39)]||_0x4cab26[_0x554c(0x4c)],_0x4cab26['pBRSt']);}else throw new ApiError(_0x4cab26[_0x554c(0x4d)],_0x4cab26[_0x554c(0x4e)]);}if(debug){if(_0x4cab26[_0x554c(0x4f)](_0x4cab26[_0x554c(0x50)],_0x4cab26[_0x554c(0x51)]))throw new _0x1338bc(_0x4cab26[_0x554c(0x52)],_0x4cab26[_0x554c(0x53)]);else logDebug(_0x4cab26['OgNHC'],{'endpoint':_0x454ee7,'method':_0xa52c7b,'headers':{...headers,'Authorization':_0x4cab26[_0x554c(0x43)]},'data':_0x7acb03||null});}const _0x470d09=await _0x4cab26['vPxsX'](makeDeveloperRequest,_0x454ee7,{'method':_0xa52c7b,'headers':headers,..._0x7acb03?{'body':JSON[_0x554c(0x21)](_0x7acb03)}:{}}),_0x27fdba=await _0x470d09[_0x554c(0x22)]();if(debug){if(_0x4cab26['oMZvS']===_0x554c(0x54))return _0x4cab26['gPCMh'](_0xcfc42a,'platforms/'+_0x1dfb37+'/data','GET',{'debug':_0x230c57['debug']});else _0x4cab26[_0x554c(0x55)](logDebug,_0x554c(0x56),{'status':_0x470d09['status'],'data':_0x27fdba});}if(!_0x470d09['ok']){var _0x4b4401,_0x424634,_0x1926b5;const _0x5a71a6=_0x4cab26['xZrVs'](_0x470d09[_0x554c(0x23)],0x191)||_0x470d09[_0x554c(0x23)]===0x193?_0x554c(0x1a):_0x4cab26[_0x554c(0x57)](_0x470d09[_0x554c(0x23)],0x190)?_0x4cab26[_0x554c(0x58)]:_0x4cab26['kSTnH'](_0x470d09['status'],0x1f4)?_0x4cab26[_0x554c(0x59)]:_0x4cab26[_0x554c(0x5a)];throw new ApiError((_0x4cab26[_0x554c(0x5b)](_0x4b4401=_0x27fdba['error'],null)||_0x4b4401===void 0x0?void 0x0:_0x4b4401[_0x554c(0x39)])||_0x554c(0x5c),_0x5a71a6,_0x4cab26[_0x554c(0x5d)](_0x424634=_0x27fdba['error'],null)||_0x4cab26[_0x554c(0x5e)](_0x424634,void 0x0)?void 0x0:_0x424634[_0x554c(0x6)],_0x4cab26[_0x554c(0x47)](_0x1926b5=_0x27fdba['error'],null)||_0x4cab26[_0x554c(0x4f)](_0x1926b5,void 0x0)?void 0x0:_0x1926b5[_0x554c(0x32)]);}return _0x27fdba;}}catch(_0x185125){if(_0x4cab26['Nrbxh'](_0x185125,ApiError))throw _0x185125;if(_0x185125['name']===_0x4cab26[_0x554c(0x48)]){if(_0x4cab26[_0x554c(0x5b)](_0x4cab26['BSVvM'],_0x4cab26[_0x554c(0x5f)]))throw new ApiError(_0x4cab26[_0x554c(0x60)],_0x4cab26[_0x554c(0x49)]);else throw new _0x43e9b7(_0x4cab26[_0x554c(0x60)],_0x4cab26[_0x554c(0x49)]);}debug&&logDebug(_0x554c(0x61),{'endpoint':_0x454ee7,'method':_0xa52c7b,'error':_0x185125[_0x554c(0x39)]||_0x554c(0x3a)});throw new ApiError(_0x185125[_0x554c(0x39)]||_0x554c(0x16),_0x4cab26['pBRSt']);}};export const validateCredentials=async(_0x145180,_0x3bb4d0={'debug':![]})=>{const _0x26c3ea={'mARbv':function(_0x31c331,_0x3e2aea){return _0x31c331===_0x3e2aea;},'IlCar':'AKulM','BeNyF':function(_0x1811fe,_0x1ccc85,_0x11b890,_0x45ee09){return _0x1811fe(_0x1ccc85,_0x11b890,_0x45ee09);},'gzMGx':'auth/validate','Aaajs':function(_0x4ad23a,_0x2d66dc){return _0x4ad23a===_0x2d66dc;},'YhWsl':function(_0x497ced,_0x23f0c2){return _0x497ced===_0x23f0c2;}};try{if(_0x26c3ea[_0x554c(0x62)](_0x26c3ea[_0x554c(0x63)],_0x554c(0x64))){var _0x5484d2,_0x1b3638;const _0x10106b=await _0x26c3ea[_0x554c(0x65)](makeUserApiRequest,_0x26c3ea[_0x554c(0x66)],'POST',{'data':{'username':_0x145180},'debug':_0x3bb4d0[_0x554c(0x67)]});return{'isValid':_0x10106b[_0x554c(0x68)]&&_0x26c3ea[_0x554c(0x69)](_0x26c3ea[_0x554c(0x69)](_0x5484d2=_0x10106b[_0x554c(0x6a)],null)||_0x26c3ea['Aaajs'](_0x5484d2,void 0x0)?void 0x0:_0x5484d2[_0x554c(0x6b)],!![]),'message':_0x26c3ea[_0x554c(0x6c)](_0x1b3638=_0x10106b[_0x554c(0x2d)],null)||_0x1b3638===void 0x0?void 0x0:_0x1b3638[_0x554c(0x39)]};}else return _0x573b55();}catch(_0x360c63){return{'isValid':![],'message':_0x360c63[_0x554c(0x39)]};}};export const createAccount=async(_0x35849d,_0x2a28e2={'debug':![]})=>{const _0x26edaf={'GWthL':function(_0x2abdec,_0x526052,_0x4f5eb3,_0x219552){return _0x2abdec(_0x526052,_0x4f5eb3,_0x219552);}};return _0x26edaf['GWthL'](makeDeveloperApiRequest,'auth/register','POST',{'data':{'username':_0x35849d[_0x554c(0x6d)],'platforms':_0x35849d[_0x554c(0x6e)]},'debug':_0x2a28e2[_0x554c(0x67)]});};export const authenticate=async(_0x4ac713,_0x297195={'debug':![]})=>{const _0x1ed4bd={'ZCfGI':function(_0x556fdf,_0x109272,_0x23aacd,_0x1c6d56){return _0x556fdf(_0x109272,_0x23aacd,_0x1c6d56);},'IKSPM':'auth/login'};return _0x1ed4bd[_0x554c(0x6f)](makeUserApiRequest,_0x1ed4bd['IKSPM'],'POST',{'data':{'username':_0x4ac713['username'],'pin':_0x4ac713[_0x554c(0x70)]},'debug':_0x297195['debug']});};export const refreshToken=async(_0x13a1e4,_0x47a41c={'debug':![]})=>{const _0x2b3fac={'TsdRD':function(_0x48e825,_0x431e33,_0x405d7a,_0xade1fb){return _0x48e825(_0x431e33,_0x405d7a,_0xade1fb);},'ncRdH':_0x554c(0x71)};return _0x2b3fac[_0x554c(0x72)](makeUserApiRequest,_0x2b3fac['ncRdH'],'POST',{'data':{'refreshToken':_0x13a1e4},'debug':_0x47a41c[_0x554c(0x67)]});};export const getPlatformData=async(_0x3a4235,_0x5d0438={'debug':![]})=>{const _0x4d2443={'nYefn':function(_0x2f5da6,_0x2577c2,_0x2d444d,_0x13e8eb){return _0x2f5da6(_0x2577c2,_0x2d444d,_0x13e8eb);}};return _0x4d2443['nYefn'](makeUserApiRequest,'platforms/'+_0x3a4235+_0x554c(0x73),'GET',{'debug':_0x5d0438[_0x554c(0x67)]});};export const getUserProfile=async(_0x5da498={'debug':![]})=>{const _0x4842f5={'CKsFf':function(_0x445315,_0x46278f,_0x2be730,_0x52e636){return _0x445315(_0x46278f,_0x2be730,_0x52e636);},'dobul':'user/profile'};return _0x4842f5[_0x554c(0x74)](makeUserApiRequest,_0x4842f5['dobul'],'GET',{'debug':_0x5da498['debug']});};export const updatePlatformConnections=async(_0xb7a867,_0x1a6aaf={'debug':![]})=>{const _0x3464f3={'ZXwxt':function(_0xc71b58,_0x263156,_0x27ad8b,_0x3ddf5e){return _0xc71b58(_0x263156,_0x27ad8b,_0x3ddf5e);}};return _0x3464f3[_0x554c(0x75)](makeUserApiRequest,_0x554c(0x76),'PUT',{'data':{'platforms':_0xb7a867},'debug':_0x1a6aaf[_0x554c(0x67)]});};export const storePIN=async(_0x5e4495,_0x412b1e={})=>{const _0x49f83a={'LFMOu':_0x554c(0x36),'LCidY':_0x554c(0x14),'mEsTK':function(_0xfd3c0a){return _0xfd3c0a();},'FrAsx':_0x554c(0x77),'tUrsU':'No\x20username\x20available\x20-\x20either\x20provide\x20username\x20or\x20ensure\x20JWT\x20token\x20is\x20valid','asaHd':_0x554c(0x1a)},{debug:debug=![],username:_0x45632f}=_0x412b1e,_0x4fa96d=_0x45632f||_0x49f83a[_0x554c(0x78)](extractUsernameFromJWT);if(!_0x4fa96d){if(_0x49f83a[_0x554c(0x79)]!==_0x49f83a[_0x554c(0x79)])throw new _0x47779a(_0x49f83a[_0x554c(0x7a)],_0x49f83a[_0x554c(0x7b)]);else throw new ApiError(_0x49f83a['tUrsU'],_0x49f83a['asaHd']);}return makeUserApiRequest('store-pin/mobile','POST',{'data':{'username':_0x4fa96d,'pin':_0x5e4495},'debug':debug});};function _0x3757(){const _0x487ee5=['0|4|2|3|1','ApiError','bYJtW','split','name','VIvpg','code','fetch','JqyvU','isConnected','User\x20API\x20Response','No\x20network\x20connection\x20available','network_error','wMkVv','User\x20API\x20Request','[REDACTED]','PNaRs','server_error','unknown_error','AbortError','timeout_error','User\x20API\x20Error','An\x20unexpected\x20error\x20occurred','SbbwS','NqaTF','USIbJ','auth_error','jLsCj','SruXT','vevZc','kFucP','bLYfQ','mmGnb','stringify','json','status','MnSYD','HvDwN','BzZJK','CbXej','validation_error','qMuvC','mgmDf','pGKSe','REQGU','error','JboIj','HPNEH','ihnFw','oSeWq','details','yXUxk','ONacN','QofSS','Request\x20timed\x20out','WpXVu','VcHDX','message','Unknown\x20error','No\x20username\x20available\x20-\x20either\x20provide\x20username\x20or\x20ensure\x20JWT\x20token\x20is\x20valid','fJtXl','FiAfs','HlVby','yltoy','JQgxm','HprRq','OgNHC','GFJlJ','nPIix','FeZTA','NhRJD','xZrVs','qzKtL','AYRbj','vPxsX','gUzTz','oHLOz','xqpek','hNoQs','kNoWm','mlhCH','rnUHY','aCGPv','aaQfc','zvsxU','GtXuS','Developer\x20API\x20Response','nyERO','FGGWx','mpAOL','pBRSt','dRQPU','API\x20request\x20failed','ZKabk','vACCJ','BSVvM','FBULR','Developer\x20API\x20Error','mARbv','IlCar','AKulM','BeNyF','gzMGx','debug','success','Aaajs','data','isValid','YhWsl','username','platforms','ZCfGI','userPin','auth/refresh','TsdRD','/data','CKsFf','ZXwxt','user/platforms','tnunr','mEsTK','FrAsx','LFMOu','LCidY','xBAIL','eSBcQ'];_0x3757=function(){return _0x487ee5;};return _0x3757();}export const getCurrentUserToken=async()=>{const _0x470717={'xBAIL':function(_0x2e66dd){return _0x2e66dd();}};return await _0x470717[_0x554c(0x7c)](getJWT);};export const isCurrentUserAuthenticated=()=>{const _0x2bed06={'eSBcQ':function(_0x41e33a){return _0x41e33a();}};return _0x2bed06[_0x554c(0x7d)](isUserAuthenticated);};
|
|
1
|
+
import NetInfo from '@react-native-community/netinfo';
|
|
2
|
+
import { logDebug } from './debugHelper';
|
|
3
|
+
import { getJWT, makeUserRequest, makeDeveloperRequest, isUserAuthenticated, extractUsernameFromJWT } from '../services/apiKeyService';
|
|
4
|
+
|
|
5
|
+
// API response types
|
|
6
|
+
|
|
7
|
+
// Error types
|
|
8
|
+
|
|
9
|
+
// API error structure
|
|
10
|
+
export class ApiError extends Error {
|
|
11
|
+
constructor(message, type, code, details) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.type = type;
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.details = details;
|
|
16
|
+
this.name = 'ApiError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Check if the device has an active network connection
|
|
22
|
+
*/
|
|
23
|
+
const checkNetworkConnection = async () => {
|
|
24
|
+
const networkState = await NetInfo.fetch();
|
|
25
|
+
return networkState.isConnected === true;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Make user-authenticated API request using JWT token
|
|
30
|
+
*/
|
|
31
|
+
const makeUserApiRequest = async (endpoint, method, options = {}) => {
|
|
32
|
+
const {
|
|
33
|
+
data,
|
|
34
|
+
headers = {},
|
|
35
|
+
debug = false
|
|
36
|
+
} = options;
|
|
37
|
+
try {
|
|
38
|
+
// Check for network connectivity
|
|
39
|
+
const isConnected = await checkNetworkConnection();
|
|
40
|
+
if (!isConnected) {
|
|
41
|
+
throw new ApiError('No network connection available', 'network_error');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Check if user is authenticated
|
|
45
|
+
if (!isUserAuthenticated()) {
|
|
46
|
+
throw new ApiError('User not authenticated. Please verify email first.', 'auth_error');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Log request information if debug mode is enabled
|
|
50
|
+
if (debug) {
|
|
51
|
+
logDebug('User API Request', {
|
|
52
|
+
endpoint,
|
|
53
|
+
method,
|
|
54
|
+
headers: {
|
|
55
|
+
...headers,
|
|
56
|
+
Authorization: '[REDACTED]'
|
|
57
|
+
},
|
|
58
|
+
data: data || null
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Make authenticated request using JWT token
|
|
63
|
+
const response = await makeUserRequest(endpoint, {
|
|
64
|
+
method,
|
|
65
|
+
headers,
|
|
66
|
+
...(data ? {
|
|
67
|
+
body: JSON.stringify(data)
|
|
68
|
+
} : {})
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Parse response as JSON
|
|
72
|
+
const responseData = await response.json();
|
|
73
|
+
|
|
74
|
+
// Log response if debug mode is enabled
|
|
75
|
+
if (debug) {
|
|
76
|
+
logDebug('User API Response', {
|
|
77
|
+
status: response.status,
|
|
78
|
+
data: responseData
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Handle API error responses
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
var _responseData$error, _responseData$error2, _responseData$error3;
|
|
85
|
+
const errorType = response.status === 401 || response.status === 403 ? 'auth_error' : response.status === 400 ? 'validation_error' : response.status >= 500 ? 'server_error' : 'unknown_error';
|
|
86
|
+
throw new ApiError(((_responseData$error = responseData.error) === null || _responseData$error === void 0 ? void 0 : _responseData$error.message) || 'API request failed', errorType, (_responseData$error2 = responseData.error) === null || _responseData$error2 === void 0 ? void 0 : _responseData$error2.code, (_responseData$error3 = responseData.error) === null || _responseData$error3 === void 0 ? void 0 : _responseData$error3.details);
|
|
87
|
+
}
|
|
88
|
+
return responseData;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
// Handle specific error types
|
|
91
|
+
if (error instanceof ApiError) {
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
if (error.name === 'AbortError') {
|
|
95
|
+
throw new ApiError('Request timed out', 'timeout_error');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Log error if debug mode is enabled
|
|
99
|
+
if (debug) {
|
|
100
|
+
logDebug('User API Error', {
|
|
101
|
+
endpoint,
|
|
102
|
+
method,
|
|
103
|
+
error: error.message || 'Unknown error'
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Return a generic error for all other cases
|
|
108
|
+
throw new ApiError(error.message || 'An unexpected error occurred', 'unknown_error');
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Make developer-authenticated API request using API key
|
|
114
|
+
*/
|
|
115
|
+
const makeDeveloperApiRequest = async (endpoint, method, options = {}) => {
|
|
116
|
+
const {
|
|
117
|
+
data,
|
|
118
|
+
headers = {},
|
|
119
|
+
debug = false
|
|
120
|
+
} = options;
|
|
121
|
+
try {
|
|
122
|
+
// Check for network connectivity
|
|
123
|
+
const isConnected = await checkNetworkConnection();
|
|
124
|
+
if (!isConnected) {
|
|
125
|
+
throw new ApiError('No network connection available', 'network_error');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Log request information if debug mode is enabled
|
|
129
|
+
if (debug) {
|
|
130
|
+
logDebug('Developer API Request', {
|
|
131
|
+
endpoint,
|
|
132
|
+
method,
|
|
133
|
+
headers: {
|
|
134
|
+
...headers,
|
|
135
|
+
Authorization: '[REDACTED]'
|
|
136
|
+
},
|
|
137
|
+
data: data || null
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Make authenticated request using developer API key
|
|
142
|
+
const response = await makeDeveloperRequest(endpoint, {
|
|
143
|
+
method,
|
|
144
|
+
headers,
|
|
145
|
+
...(data ? {
|
|
146
|
+
body: JSON.stringify(data)
|
|
147
|
+
} : {})
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Parse response as JSON
|
|
151
|
+
const responseData = await response.json();
|
|
152
|
+
|
|
153
|
+
// Log response if debug mode is enabled
|
|
154
|
+
if (debug) {
|
|
155
|
+
logDebug('Developer API Response', {
|
|
156
|
+
status: response.status,
|
|
157
|
+
data: responseData
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Handle API error responses
|
|
162
|
+
if (!response.ok) {
|
|
163
|
+
var _responseData$error4, _responseData$error5, _responseData$error6;
|
|
164
|
+
const errorType = response.status === 401 || response.status === 403 ? 'auth_error' : response.status === 400 ? 'validation_error' : response.status >= 500 ? 'server_error' : 'unknown_error';
|
|
165
|
+
throw new ApiError(((_responseData$error4 = responseData.error) === null || _responseData$error4 === void 0 ? void 0 : _responseData$error4.message) || 'API request failed', errorType, (_responseData$error5 = responseData.error) === null || _responseData$error5 === void 0 ? void 0 : _responseData$error5.code, (_responseData$error6 = responseData.error) === null || _responseData$error6 === void 0 ? void 0 : _responseData$error6.details);
|
|
166
|
+
}
|
|
167
|
+
return responseData;
|
|
168
|
+
} catch (error) {
|
|
169
|
+
// Handle specific error types
|
|
170
|
+
if (error instanceof ApiError) {
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
if (error.name === 'AbortError') {
|
|
174
|
+
throw new ApiError('Request timed out', 'timeout_error');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Log error if debug mode is enabled
|
|
178
|
+
if (debug) {
|
|
179
|
+
logDebug('Developer API Error', {
|
|
180
|
+
endpoint,
|
|
181
|
+
method,
|
|
182
|
+
error: error.message || 'Unknown error'
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Return a generic error for all other cases
|
|
187
|
+
throw new ApiError(error.message || 'An unexpected error occurred', 'unknown_error');
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Validate user credentials with the API (uses JWT)
|
|
193
|
+
*/
|
|
194
|
+
export const validateCredentials = async (username, options = {
|
|
195
|
+
debug: false
|
|
196
|
+
}) => {
|
|
197
|
+
try {
|
|
198
|
+
var _response$data, _response$error;
|
|
199
|
+
const response = await makeUserApiRequest('auth/validate', 'POST', {
|
|
200
|
+
data: {
|
|
201
|
+
username
|
|
202
|
+
},
|
|
203
|
+
debug: options.debug
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
isValid: response.success && ((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.isValid) === true,
|
|
207
|
+
message: (_response$error = response.error) === null || _response$error === void 0 ? void 0 : _response$error.message
|
|
208
|
+
};
|
|
209
|
+
} catch (error) {
|
|
210
|
+
return {
|
|
211
|
+
isValid: false,
|
|
212
|
+
message: error.message
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Create a new user account (uses developer API key)
|
|
219
|
+
*/
|
|
220
|
+
export const createAccount = async (credentials, options = {
|
|
221
|
+
debug: false
|
|
222
|
+
}) => {
|
|
223
|
+
return makeDeveloperApiRequest('auth/register', 'POST', {
|
|
224
|
+
data: {
|
|
225
|
+
username: credentials.username,
|
|
226
|
+
platforms: credentials.platforms
|
|
227
|
+
},
|
|
228
|
+
debug: options.debug
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Authenticate with the API using credentials (uses JWT)
|
|
234
|
+
*/
|
|
235
|
+
export const authenticate = async (credentials, options = {
|
|
236
|
+
debug: false
|
|
237
|
+
}) => {
|
|
238
|
+
return makeUserApiRequest('auth/login', 'POST', {
|
|
239
|
+
data: {
|
|
240
|
+
username: credentials.username,
|
|
241
|
+
pin: credentials.userPin
|
|
242
|
+
},
|
|
243
|
+
debug: options.debug
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Refresh authentication token (uses JWT)
|
|
249
|
+
*/
|
|
250
|
+
export const refreshToken = async (refreshToken, options = {
|
|
251
|
+
debug: false
|
|
252
|
+
}) => {
|
|
253
|
+
return makeUserApiRequest('auth/refresh', 'POST', {
|
|
254
|
+
data: {
|
|
255
|
+
refreshToken
|
|
256
|
+
},
|
|
257
|
+
debug: options.debug
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Get user's connected platform data (uses JWT)
|
|
263
|
+
*/
|
|
264
|
+
export const getPlatformData = async (platform, options = {
|
|
265
|
+
debug: false
|
|
266
|
+
}) => {
|
|
267
|
+
return makeUserApiRequest(`platforms/${platform}/data`, 'GET', {
|
|
268
|
+
debug: options.debug
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Get user profile information (uses JWT)
|
|
274
|
+
*/
|
|
275
|
+
export const getUserProfile = async (options = {
|
|
276
|
+
debug: false
|
|
277
|
+
}) => {
|
|
278
|
+
return makeUserApiRequest('user/profile', 'GET', {
|
|
279
|
+
debug: options.debug
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Update user platform connections (uses JWT)
|
|
285
|
+
*/
|
|
286
|
+
export const updatePlatformConnections = async (platforms, options = {
|
|
287
|
+
debug: false
|
|
288
|
+
}) => {
|
|
289
|
+
return makeUserApiRequest('user/platforms', 'PUT', {
|
|
290
|
+
data: {
|
|
291
|
+
platforms
|
|
292
|
+
},
|
|
293
|
+
debug: options.debug
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Store user PIN (uses JWT and extracts username from JWT)
|
|
299
|
+
*/
|
|
300
|
+
export const storePIN = async (pin, options = {}) => {
|
|
301
|
+
const {
|
|
302
|
+
debug = false,
|
|
303
|
+
username
|
|
304
|
+
} = options;
|
|
305
|
+
|
|
306
|
+
// Extract username from JWT if not provided
|
|
307
|
+
const userToStore = username || extractUsernameFromJWT();
|
|
308
|
+
if (!userToStore) {
|
|
309
|
+
throw new ApiError('No username available - either provide username or ensure JWT token is valid', 'auth_error');
|
|
310
|
+
}
|
|
311
|
+
return makeUserApiRequest('store-pin/mobile', 'POST', {
|
|
312
|
+
data: {
|
|
313
|
+
username: userToStore,
|
|
314
|
+
pin
|
|
315
|
+
},
|
|
316
|
+
debug
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Get current JWT token
|
|
322
|
+
*/
|
|
323
|
+
export const getCurrentUserToken = async () => {
|
|
324
|
+
return await getJWT();
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Check if user is authenticated with JWT
|
|
329
|
+
*/
|
|
330
|
+
export const isCurrentUserAuthenticated = () => {
|
|
331
|
+
return isUserAuthenticated();
|
|
332
|
+
};
|
|
333
|
+
//# sourceMappingURL=onairosApi.js.map
|