@onairos/react-native 3.4.0 โ†’ 3.5.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.
Files changed (546) hide show
  1. package/README.md +62 -13
  2. package/lib/commonjs/api/index.js +9 -145
  3. package/lib/commonjs/assets/animations/loaderani.json +1 -0
  4. package/lib/commonjs/assets/animations/persona-animation.json +1 -0
  5. package/lib/commonjs/assets/fonts/EBGaramond-VariableFont_wght.ttf +0 -0
  6. package/lib/commonjs/assets/fonts/IBMPlexSans-VariableFont_wdth,wght.ttf +0 -0
  7. package/lib/commonjs/assets/icons/Facebookicon.png +0 -0
  8. package/lib/commonjs/assets/icons/Gmail.png +0 -0
  9. package/lib/commonjs/assets/icons/Linkedinicon.png +0 -0
  10. package/lib/commonjs/assets/icons/Redditicon.png +0 -0
  11. package/lib/commonjs/assets/icons/YouTubeicon2.png +0 -0
  12. package/lib/commonjs/assets/icons/YouTubeicon3.png +0 -0
  13. package/lib/commonjs/assets/icons/chatgpt.png +0 -0
  14. package/lib/commonjs/assets/icons/claude.png +0 -0
  15. package/lib/commonjs/assets/icons/gemini.png +0 -0
  16. package/lib/commonjs/assets/icons/grok.png +0 -0
  17. package/lib/commonjs/assets/images/Checkbox.svg +3 -0
  18. package/lib/commonjs/assets/images/EnochE.svg +19 -0
  19. package/lib/commonjs/assets/images/Enochicon1.png +0 -0
  20. package/lib/commonjs/assets/images/Face_ID_logo.png +0 -0
  21. package/lib/commonjs/assets/images/Facebookicon.png +0 -0
  22. package/lib/commonjs/assets/images/Gmail.png +0 -0
  23. package/lib/commonjs/assets/images/Googlelogo.png +0 -0
  24. package/lib/commonjs/assets/images/Linkedinicon.png +0 -0
  25. package/lib/commonjs/assets/images/Onairoslogo.png +0 -0
  26. package/lib/commonjs/assets/images/Personalityprofile.svg +3 -0
  27. package/lib/commonjs/assets/images/Personalitytraits.svg +3 -0
  28. package/lib/commonjs/assets/images/Redditicon.png +0 -0
  29. package/lib/commonjs/assets/images/Userpreferences.svg +3 -0
  30. package/lib/commonjs/assets/images/YouTubeicon3.png +0 -0
  31. package/lib/commonjs/assets/images/arrow.svg +20 -0
  32. package/lib/commonjs/assets/images/basicproficon.svg +43 -0
  33. package/lib/commonjs/assets/images/basicprofile.svg +3 -0
  34. package/lib/commonjs/assets/images/chatgpt.png +0 -0
  35. package/lib/commonjs/assets/images/checkmark.svg +4 -0
  36. package/lib/commonjs/assets/images/claude.png +0 -0
  37. package/lib/commonjs/assets/images/contentanalysis.svg +3 -0
  38. package/lib/commonjs/assets/images/contenticon.svg +23 -0
  39. package/lib/commonjs/assets/images/gemini.png +0 -0
  40. package/lib/commonjs/assets/images/grok.png +0 -0
  41. package/lib/commonjs/assets/images/persona1.png +0 -0
  42. package/lib/commonjs/assets/images/persona2.png +0 -0
  43. package/lib/commonjs/assets/images/persona3.png +0 -0
  44. package/lib/commonjs/assets/images/persona4.png +0 -0
  45. package/lib/commonjs/assets/images/persona5.png +0 -0
  46. package/lib/commonjs/assets/images/personalityicon.svg +18 -0
  47. package/lib/commonjs/assets/images/x-close.svg +3 -0
  48. package/lib/commonjs/components/BodyText.js +9 -0
  49. package/lib/commonjs/components/BrandMark.js +10 -0
  50. package/lib/commonjs/components/CodeInput.js +9 -0
  51. package/lib/commonjs/components/EmailInput.js +8 -0
  52. package/lib/commonjs/components/GoogleButton.js +9 -0
  53. package/lib/commonjs/components/HeadingGroup.js +9 -0
  54. package/lib/commonjs/components/LLMDataInputModal.js +14 -0
  55. package/lib/commonjs/components/ModalHeader.js +9 -0
  56. package/lib/commonjs/components/ModalSheet.js +9 -0
  57. package/lib/commonjs/components/Onairos.js +14 -374
  58. package/lib/commonjs/components/OnairosButton.js +13 -309
  59. package/lib/commonjs/components/OnairosSignInButton.js +12 -0
  60. package/lib/commonjs/components/Overlay.js +13 -483
  61. package/lib/commonjs/components/PersonaImage.js +10 -0
  62. package/lib/commonjs/components/PersonaLoadingScreen.js +12 -0
  63. package/lib/commonjs/components/PersonalizationConsentScreen.js +13 -0
  64. package/lib/commonjs/components/PinCreationScreen.js +12 -0
  65. package/lib/commonjs/components/PinInput.js +9 -302
  66. package/lib/commonjs/components/PlatformConnectorsStep.js +22 -0
  67. package/lib/commonjs/components/PlatformList.js +10 -137
  68. package/lib/commonjs/components/PlatformToggle.js +9 -0
  69. package/lib/commonjs/components/PrimaryButton.js +10 -0
  70. package/lib/commonjs/components/SignInMatchAnimation.js +9 -0
  71. package/lib/commonjs/components/SignInStep.js +12 -0
  72. package/lib/commonjs/components/UniversalOnboarding.js +29 -1702
  73. package/lib/commonjs/components/VerificationStep.js +11 -0
  74. package/lib/commonjs/components/WelcomeScreen.js +21 -0
  75. package/lib/commonjs/components/icons/Basicproficon.js +8 -0
  76. package/lib/commonjs/components/icons/Basicprofile.js +8 -0
  77. package/lib/commonjs/components/icons/Checkbox.js +8 -0
  78. package/lib/commonjs/components/icons/Checkmark.js +8 -0
  79. package/lib/commonjs/components/icons/Contentanalysis.js +8 -0
  80. package/lib/commonjs/components/icons/Contenticon.js +8 -0
  81. package/lib/commonjs/components/icons/EnochE.js +8 -0
  82. package/lib/commonjs/components/icons/Personalityicon.js +8 -0
  83. package/lib/commonjs/components/icons/Personalityprofile.js +8 -0
  84. package/lib/commonjs/components/icons/Personalitytraits.js +8 -0
  85. package/lib/commonjs/components/icons/Userpreferences.js +8 -0
  86. package/lib/commonjs/components/icons/index.js +17 -0
  87. package/lib/commonjs/components/onboarding/OAuthWebView.js +14 -827
  88. package/lib/commonjs/components/onboarding/OnboardingHeader.js +10 -74
  89. package/lib/commonjs/components/onboarding/PinInput.js +10 -283
  90. package/lib/commonjs/components/onboarding/PlatformConnector.js +11 -249
  91. package/lib/commonjs/config/api.js +7 -0
  92. package/lib/commonjs/constants/index.js +7 -83
  93. package/lib/commonjs/context/AuthContext.js +10 -0
  94. package/lib/commonjs/hooks/useConnectedAccounts.js +9 -0
  95. package/lib/commonjs/hooks/useConnections.js +8 -159
  96. package/lib/commonjs/hooks/useCredentials.js +10 -177
  97. package/lib/commonjs/hooks/useUserConnections.js +10 -0
  98. package/lib/commonjs/index.js +35 -106
  99. package/lib/commonjs/services/SDK_API_KEY_VALIDATION.md +31 -38
  100. package/lib/commonjs/services/apiClient.js +8 -0
  101. package/lib/commonjs/services/apiKeyService.js +9 -946
  102. package/lib/commonjs/services/authService.js +10 -0
  103. package/lib/commonjs/services/biometricPinService.js +8 -0
  104. package/lib/commonjs/services/chatGPTConversationExtractor.js +8 -0
  105. package/lib/commonjs/services/chatGPTConversationService.js +9 -0
  106. package/lib/commonjs/services/claudeConversationExtractor.js +8 -0
  107. package/lib/commonjs/services/claudeConversationService.js +9 -0
  108. package/lib/commonjs/services/connectedAccountsService.js +10 -0
  109. package/lib/commonjs/services/googleAuthService.js +11 -0
  110. package/lib/commonjs/services/imageCompressionService.js +7 -0
  111. package/lib/commonjs/services/jwtStorageService.js +7 -0
  112. package/lib/commonjs/services/linkedinDOMExtractor.js +7 -0
  113. package/lib/commonjs/services/linkedinProfileService.js +9 -0
  114. package/lib/commonjs/services/linkedinScrapingService.js +8 -0
  115. package/lib/commonjs/services/llmDataStorage.js +8 -0
  116. package/lib/commonjs/services/mobileTrainingService.js +8 -0
  117. package/lib/commonjs/services/oauthService.js +11 -390
  118. package/lib/commonjs/services/pinEncryptionService.js +8 -0
  119. package/lib/commonjs/services/pinStorageUtils.js +7 -0
  120. package/lib/commonjs/services/platformAuthService.js +12 -1067
  121. package/lib/commonjs/services/storageService.js +8 -0
  122. package/lib/commonjs/services/trainingApiHelpers.js +7 -0
  123. package/lib/commonjs/services/userConnectionsService.js +10 -0
  124. package/lib/commonjs/services/youtubeMigrationService.js +10 -0
  125. package/lib/commonjs/theme/index.js +7 -0
  126. package/lib/commonjs/types/ambient.d.js +1 -2
  127. package/lib/commonjs/types/declarations.d.js +1 -2
  128. package/lib/commonjs/types/index.js +1 -6
  129. package/lib/commonjs/types/node-fix.d.js +1 -2
  130. package/lib/commonjs/types/node-override.d.js +1 -2
  131. package/lib/commonjs/types/opacity.d.js +1 -2
  132. package/lib/commonjs/types.js +1 -14
  133. package/lib/commonjs/utils/Portal.js +8 -98
  134. package/lib/commonjs/utils/api.js +9 -129
  135. package/lib/commonjs/utils/assetRegistry.js +33 -0
  136. package/lib/commonjs/utils/auth.js +9 -111
  137. package/lib/commonjs/utils/crypto.js +8 -62
  138. package/lib/commonjs/utils/debugHelper.js +1 -64
  139. package/lib/commonjs/utils/encryption.js +7 -76
  140. package/lib/commonjs/utils/eventUtils.js +1 -0
  141. package/lib/commonjs/utils/haptics.js +9 -0
  142. package/lib/commonjs/utils/imagePreloader.js +1 -0
  143. package/lib/commonjs/utils/networkDiagnostics.js +8 -0
  144. package/lib/commonjs/utils/onairosApi.js +9 -350
  145. package/lib/commonjs/utils/programmaticFlow.js +9 -117
  146. package/lib/commonjs/utils/retryHelper.js +1 -220
  147. package/lib/commonjs/utils/secureStorage.js +10 -349
  148. package/lib/commonjs/utils/webviewScripts/chatgpt.js +1 -0
  149. package/lib/commonjs/utils/webviewScripts/claude.js +1 -0
  150. package/lib/commonjs/utils/webviewScripts/index.js +9 -0
  151. package/lib/commonjs/utils/webviewScripts/linkedin.js +1 -0
  152. package/lib/module/api/index.js +1 -139
  153. package/lib/module/assets/animations/loaderani.json +1 -0
  154. package/lib/module/assets/animations/persona-animation.json +1 -0
  155. package/lib/module/assets/fonts/EBGaramond-VariableFont_wght.ttf +0 -0
  156. package/lib/module/assets/fonts/IBMPlexSans-VariableFont_wdth,wght.ttf +0 -0
  157. package/lib/module/assets/icons/Facebookicon.png +0 -0
  158. package/lib/module/assets/icons/Gmail.png +0 -0
  159. package/lib/module/assets/icons/Linkedinicon.png +0 -0
  160. package/lib/module/assets/icons/Redditicon.png +0 -0
  161. package/lib/module/assets/icons/YouTubeicon2.png +0 -0
  162. package/lib/module/assets/icons/YouTubeicon3.png +0 -0
  163. package/lib/module/assets/icons/chatgpt.png +0 -0
  164. package/lib/module/assets/icons/claude.png +0 -0
  165. package/lib/module/assets/icons/farcaster.png +0 -0
  166. package/lib/module/assets/icons/gemini.png +0 -0
  167. package/lib/module/assets/icons/grok.png +0 -0
  168. package/lib/module/assets/icons/instagram.png +0 -0
  169. package/lib/module/assets/icons/pinterest.png +0 -0
  170. package/lib/module/assets/icons/swerv_logo.png +0 -0
  171. package/lib/module/assets/icons/twitter.jpg +0 -0
  172. package/lib/module/assets/images/Checkbox.svg +3 -0
  173. package/lib/module/assets/images/EnochE.svg +19 -0
  174. package/lib/module/assets/images/Enochicon1.png +0 -0
  175. package/lib/module/assets/images/Face_ID_logo.png +0 -0
  176. package/lib/module/assets/images/Facebookicon.png +0 -0
  177. package/lib/module/assets/images/Gmail.png +0 -0
  178. package/lib/module/assets/images/Googlelogo.png +0 -0
  179. package/lib/module/assets/images/Linkedinicon.png +0 -0
  180. package/lib/module/assets/images/Onairoslogo.png +0 -0
  181. package/lib/module/assets/images/Personalityprofile.svg +3 -0
  182. package/lib/module/assets/images/Personalitytraits.svg +3 -0
  183. package/lib/module/assets/images/Redditicon.png +0 -0
  184. package/lib/module/assets/images/Userpreferences.svg +3 -0
  185. package/lib/module/assets/images/YouTubeicon3.png +0 -0
  186. package/lib/module/assets/images/arrow.svg +20 -0
  187. package/lib/module/assets/images/basicproficon.svg +43 -0
  188. package/lib/module/assets/images/basicprofile.svg +3 -0
  189. package/lib/module/assets/images/chatgpt.png +0 -0
  190. package/lib/module/assets/images/checkmark.svg +4 -0
  191. package/lib/module/assets/images/claude.png +0 -0
  192. package/lib/module/assets/images/contentanalysis.svg +3 -0
  193. package/lib/module/assets/images/contenticon.svg +23 -0
  194. package/lib/module/assets/images/gemini.png +0 -0
  195. package/lib/module/assets/images/grok.png +0 -0
  196. package/lib/module/assets/images/persona1.png +0 -0
  197. package/lib/module/assets/images/persona2.png +0 -0
  198. package/lib/module/assets/images/persona3.png +0 -0
  199. package/lib/module/assets/images/persona4.png +0 -0
  200. package/lib/module/assets/images/persona5.png +0 -0
  201. package/lib/module/assets/images/personalityicon.svg +18 -0
  202. package/lib/module/assets/images/x-close.svg +3 -0
  203. package/lib/module/components/BodyText.js +1 -0
  204. package/lib/module/components/BrandMark.js +1 -0
  205. package/lib/module/components/CodeInput.js +1 -0
  206. package/lib/module/components/EmailInput.js +1 -0
  207. package/lib/module/components/GoogleButton.js +1 -0
  208. package/lib/module/components/HeadingGroup.js +1 -0
  209. package/lib/module/components/LLMDataInputModal.js +8 -0
  210. package/lib/module/components/ModalHeader.js +1 -0
  211. package/lib/module/components/ModalSheet.js +1 -0
  212. package/lib/module/components/Onairos.js +1 -367
  213. package/lib/module/components/OnairosButton.js +1 -302
  214. package/lib/module/components/OnairosSignInButton.js +1 -0
  215. package/lib/module/components/Overlay.js +1 -474
  216. package/lib/module/components/PersonaImage.js +1 -0
  217. package/lib/module/components/PersonaLoadingScreen.js +1 -0
  218. package/lib/module/components/PersonalizationConsentScreen.js +1 -0
  219. package/lib/module/components/PinCreationScreen.js +1 -0
  220. package/lib/module/components/PinInput.js +1 -293
  221. package/lib/module/components/PlatformConnectorsStep.js +1 -0
  222. package/lib/module/components/PlatformList.js +1 -129
  223. package/lib/module/components/PlatformToggle.js +1 -0
  224. package/lib/module/components/PrimaryButton.js +1 -0
  225. package/lib/module/components/SignInMatchAnimation.js +1 -0
  226. package/lib/module/components/SignInStep.js +1 -0
  227. package/lib/module/components/UniversalOnboarding.js +1 -1693
  228. package/lib/module/components/VerificationStep.js +1 -0
  229. package/lib/module/components/WelcomeScreen.js +1 -0
  230. package/lib/module/components/icons/Basicproficon.js +1 -0
  231. package/lib/module/components/icons/Basicprofile.js +1 -0
  232. package/lib/module/components/icons/Checkbox.js +1 -0
  233. package/lib/module/components/icons/Checkmark.js +1 -0
  234. package/lib/module/components/icons/Contentanalysis.js +1 -0
  235. package/lib/module/components/icons/Contenticon.js +1 -0
  236. package/lib/module/components/icons/EnochE.js +1 -0
  237. package/lib/module/components/icons/Personalityicon.js +1 -0
  238. package/lib/module/components/icons/Personalityprofile.js +1 -0
  239. package/lib/module/components/icons/Personalitytraits.js +1 -0
  240. package/lib/module/components/icons/Userpreferences.js +1 -0
  241. package/lib/module/components/icons/index.js +1 -0
  242. package/lib/module/components/onboarding/OAuthWebView.js +1 -818
  243. package/lib/module/components/onboarding/OnboardingHeader.js +1 -66
  244. package/lib/module/components/onboarding/PinInput.js +1 -274
  245. package/lib/module/components/onboarding/PlatformConnector.js +1 -240
  246. package/lib/module/config/api.js +1 -0
  247. package/lib/module/constants/index.js +1 -77
  248. package/lib/module/context/AuthContext.js +1 -0
  249. package/lib/module/hooks/useConnectedAccounts.js +1 -0
  250. package/lib/module/hooks/useConnections.js +1 -152
  251. package/lib/module/hooks/useCredentials.js +6 -169
  252. package/lib/module/hooks/useUserConnections.js +1 -0
  253. package/lib/module/index.js +1 -32
  254. package/lib/module/services/SDK_API_KEY_VALIDATION.md +31 -38
  255. package/lib/module/services/apiClient.js +1 -0
  256. package/lib/module/services/apiKeyService.js +1 -919
  257. package/lib/module/services/authService.js +1 -0
  258. package/lib/module/services/biometricPinService.js +1 -0
  259. package/lib/module/services/chatGPTConversationExtractor.js +1 -0
  260. package/lib/module/services/chatGPTConversationService.js +1 -0
  261. package/lib/module/services/claudeConversationExtractor.js +1 -0
  262. package/lib/module/services/claudeConversationService.js +1 -0
  263. package/lib/module/services/connectedAccountsService.js +1 -0
  264. package/lib/module/services/googleAuthService.js +1 -0
  265. package/lib/module/services/imageCompressionService.js +1 -0
  266. package/lib/module/services/jwtStorageService.js +1 -0
  267. package/lib/module/services/linkedinDOMExtractor.js +1 -0
  268. package/lib/module/services/linkedinProfileService.js +1 -0
  269. package/lib/module/services/linkedinScrapingService.js +1 -0
  270. package/lib/module/services/llmDataStorage.js +1 -0
  271. package/lib/module/services/mobileTrainingService.js +1 -0
  272. package/lib/module/services/oauthService.js +1 -380
  273. package/lib/module/services/pinEncryptionService.js +7 -0
  274. package/lib/module/services/pinStorageUtils.js +1 -0
  275. package/lib/module/services/platformAuthService.js +1 -1041
  276. package/lib/module/services/storageService.js +1 -0
  277. package/lib/module/services/trainingApiHelpers.js +1 -0
  278. package/lib/module/services/userConnectionsService.js +1 -0
  279. package/lib/module/services/youtubeMigrationService.js +1 -0
  280. package/lib/module/theme/index.js +1 -0
  281. package/lib/module/types.js +1 -10
  282. package/lib/module/utils/Portal.js +1 -90
  283. package/lib/module/utils/api.js +1 -117
  284. package/lib/module/utils/assetRegistry.js +33 -0
  285. package/lib/module/utils/auth.js +1 -99
  286. package/lib/module/utils/crypto.js +1 -54
  287. package/lib/module/utils/debugHelper.js +1 -54
  288. package/lib/module/utils/encryption.js +1 -67
  289. package/lib/module/utils/eventUtils.js +1 -0
  290. package/lib/module/utils/haptics.js +8 -0
  291. package/lib/module/utils/imagePreloader.js +1 -0
  292. package/lib/module/utils/networkDiagnostics.js +1 -0
  293. package/lib/module/utils/onairosApi.js +1 -333
  294. package/lib/module/utils/programmaticFlow.js +1 -111
  295. package/lib/module/utils/retryHelper.js +1 -211
  296. package/lib/module/utils/secureStorage.js +6 -330
  297. package/lib/module/utils/webviewScripts/chatgpt.js +1 -0
  298. package/lib/module/utils/webviewScripts/claude.js +1 -0
  299. package/lib/module/utils/webviewScripts/index.js +1 -0
  300. package/lib/module/utils/webviewScripts/linkedin.js +1 -0
  301. package/package.json +62 -39
  302. package/lib/commonjs/api/index.js.map +0 -1
  303. package/lib/commonjs/assets/images/email.png +0 -0
  304. package/lib/commonjs/assets/images/linkedin.png +0 -0
  305. package/lib/commonjs/assets/images/reddit.png +0 -0
  306. package/lib/commonjs/assets/images/youtube.png +0 -0
  307. package/lib/commonjs/components/DataRequestModal.js +0 -228
  308. package/lib/commonjs/components/DataRequestModal.js.map +0 -1
  309. package/lib/commonjs/components/DataRequestScreen.js +0 -329
  310. package/lib/commonjs/components/DataRequestScreen.js.map +0 -1
  311. package/lib/commonjs/components/EmailVerificationModal.js +0 -320
  312. package/lib/commonjs/components/EmailVerificationModal.js.map +0 -1
  313. package/lib/commonjs/components/Onairos.js.map +0 -1
  314. package/lib/commonjs/components/OnairosButton.js.map +0 -1
  315. package/lib/commonjs/components/Overlay.js.map +0 -1
  316. package/lib/commonjs/components/PinInput.js.map +0 -1
  317. package/lib/commonjs/components/PlatformList.js.map +0 -1
  318. package/lib/commonjs/components/TrainingModal.js +0 -717
  319. package/lib/commonjs/components/TrainingModal.js.map +0 -1
  320. package/lib/commonjs/components/UniversalOnboarding.js.map +0 -1
  321. package/lib/commonjs/components/UniversalOnboarding.tsx.new +0 -455
  322. package/lib/commonjs/components/onboarding/OAuthWebView.js.map +0 -1
  323. package/lib/commonjs/components/onboarding/OnboardingHeader.js.map +0 -1
  324. package/lib/commonjs/components/onboarding/PinInput.js.map +0 -1
  325. package/lib/commonjs/components/onboarding/PlatformConnector.js.map +0 -1
  326. package/lib/commonjs/components/screens/ConnectorScreen.js +0 -146
  327. package/lib/commonjs/components/screens/ConnectorScreen.js.map +0 -1
  328. package/lib/commonjs/components/screens/LoadingScreen.js +0 -91
  329. package/lib/commonjs/components/screens/LoadingScreen.js.map +0 -1
  330. package/lib/commonjs/components/screens/PinCreationScreen.js +0 -61
  331. package/lib/commonjs/components/screens/PinCreationScreen.js.map +0 -1
  332. package/lib/commonjs/constants/index.js.map +0 -1
  333. package/lib/commonjs/hooks/useConnections.js.map +0 -1
  334. package/lib/commonjs/hooks/useCredentials.js.map +0 -1
  335. package/lib/commonjs/index.js.map +0 -1
  336. package/lib/commonjs/services/apiKeyService.js.map +0 -1
  337. package/lib/commonjs/services/oauthService.js.map +0 -1
  338. package/lib/commonjs/services/platformAuthService.js.map +0 -1
  339. package/lib/commonjs/types/ambient.d.js.map +0 -1
  340. package/lib/commonjs/types/declarations.d.js.map +0 -1
  341. package/lib/commonjs/types/index.d.js.map +0 -1
  342. package/lib/commonjs/types/index.js.map +0 -1
  343. package/lib/commonjs/types/node-fix.d.js.map +0 -1
  344. package/lib/commonjs/types/node-override.d.js.map +0 -1
  345. package/lib/commonjs/types/opacity.d.js.map +0 -1
  346. package/lib/commonjs/types/types.d.js.map +0 -1
  347. package/lib/commonjs/types.js.map +0 -1
  348. package/lib/commonjs/utils/Portal.js.map +0 -1
  349. package/lib/commonjs/utils/api.js.map +0 -1
  350. package/lib/commonjs/utils/auth.js.map +0 -1
  351. package/lib/commonjs/utils/crypto.js.map +0 -1
  352. package/lib/commonjs/utils/debugHelper.js.map +0 -1
  353. package/lib/commonjs/utils/encryption.js.map +0 -1
  354. package/lib/commonjs/utils/onairosApi.js.map +0 -1
  355. package/lib/commonjs/utils/programmaticFlow.js.map +0 -1
  356. package/lib/commonjs/utils/retryHelper.js.map +0 -1
  357. package/lib/commonjs/utils/secureStorage.js.map +0 -1
  358. package/lib/module/api/index.js.map +0 -1
  359. package/lib/module/assets/images/email.png +0 -0
  360. package/lib/module/assets/images/linkedin.png +0 -0
  361. package/lib/module/assets/images/reddit.png +0 -0
  362. package/lib/module/assets/images/youtube.png +0 -0
  363. package/lib/module/components/DataRequestModal.js +0 -220
  364. package/lib/module/components/DataRequestModal.js.map +0 -1
  365. package/lib/module/components/DataRequestScreen.js +0 -321
  366. package/lib/module/components/DataRequestScreen.js.map +0 -1
  367. package/lib/module/components/EmailVerificationModal.js +0 -311
  368. package/lib/module/components/EmailVerificationModal.js.map +0 -1
  369. package/lib/module/components/Onairos.js.map +0 -1
  370. package/lib/module/components/OnairosButton.js.map +0 -1
  371. package/lib/module/components/Overlay.js.map +0 -1
  372. package/lib/module/components/PinInput.js.map +0 -1
  373. package/lib/module/components/PlatformList.js.map +0 -1
  374. package/lib/module/components/TrainingModal.js +0 -708
  375. package/lib/module/components/TrainingModal.js.map +0 -1
  376. package/lib/module/components/UniversalOnboarding.js.map +0 -1
  377. package/lib/module/components/UniversalOnboarding.tsx.new +0 -455
  378. package/lib/module/components/onboarding/OAuthWebView.js.map +0 -1
  379. package/lib/module/components/onboarding/OnboardingHeader.js.map +0 -1
  380. package/lib/module/components/onboarding/PinInput.js.map +0 -1
  381. package/lib/module/components/onboarding/PlatformConnector.js.map +0 -1
  382. package/lib/module/components/screens/ConnectorScreen.js +0 -138
  383. package/lib/module/components/screens/ConnectorScreen.js.map +0 -1
  384. package/lib/module/components/screens/LoadingScreen.js +0 -83
  385. package/lib/module/components/screens/LoadingScreen.js.map +0 -1
  386. package/lib/module/components/screens/PinCreationScreen.js +0 -53
  387. package/lib/module/components/screens/PinCreationScreen.js.map +0 -1
  388. package/lib/module/constants/index.js.map +0 -1
  389. package/lib/module/hooks/useConnections.js.map +0 -1
  390. package/lib/module/hooks/useCredentials.js.map +0 -1
  391. package/lib/module/index.js.map +0 -1
  392. package/lib/module/services/apiKeyService.js.map +0 -1
  393. package/lib/module/services/oauthService.js.map +0 -1
  394. package/lib/module/services/platformAuthService.js.map +0 -1
  395. package/lib/module/types/ambient.d.js.map +0 -1
  396. package/lib/module/types/declarations.d.js.map +0 -1
  397. package/lib/module/types/index.d.js.map +0 -1
  398. package/lib/module/types/index.js.map +0 -1
  399. package/lib/module/types/node-fix.d.js.map +0 -1
  400. package/lib/module/types/node-override.d.js.map +0 -1
  401. package/lib/module/types/opacity.d.js.map +0 -1
  402. package/lib/module/types/types.d.js.map +0 -1
  403. package/lib/module/types.js.map +0 -1
  404. package/lib/module/utils/Portal.js.map +0 -1
  405. package/lib/module/utils/api.js.map +0 -1
  406. package/lib/module/utils/auth.js.map +0 -1
  407. package/lib/module/utils/crypto.js.map +0 -1
  408. package/lib/module/utils/debugHelper.js.map +0 -1
  409. package/lib/module/utils/encryption.js.map +0 -1
  410. package/lib/module/utils/onairosApi.js.map +0 -1
  411. package/lib/module/utils/programmaticFlow.js.map +0 -1
  412. package/lib/module/utils/retryHelper.js.map +0 -1
  413. package/lib/module/utils/secureStorage.js.map +0 -1
  414. package/lib/typescript/api/index.d.ts +0 -8
  415. package/lib/typescript/api/index.d.ts.map +0 -1
  416. package/lib/typescript/components/DataRequestModal.d.ts +0 -11
  417. package/lib/typescript/components/DataRequestModal.d.ts.map +0 -1
  418. package/lib/typescript/components/DataRequestScreen.d.ts +0 -11
  419. package/lib/typescript/components/DataRequestScreen.d.ts.map +0 -1
  420. package/lib/typescript/components/EmailVerificationModal.d.ts +0 -11
  421. package/lib/typescript/components/EmailVerificationModal.d.ts.map +0 -1
  422. package/lib/typescript/components/Onairos.d.ts +0 -4
  423. package/lib/typescript/components/Onairos.d.ts.map +0 -1
  424. package/lib/typescript/components/OnairosButton.d.ts +0 -12
  425. package/lib/typescript/components/OnairosButton.d.ts.map +0 -1
  426. package/lib/typescript/components/Overlay.d.ts +0 -4
  427. package/lib/typescript/components/Overlay.d.ts.map +0 -1
  428. package/lib/typescript/components/PinInput.d.ts +0 -4
  429. package/lib/typescript/components/PinInput.d.ts.map +0 -1
  430. package/lib/typescript/components/PlatformList.d.ts +0 -4
  431. package/lib/typescript/components/PlatformList.d.ts.map +0 -1
  432. package/lib/typescript/components/TrainingModal.d.ts +0 -4
  433. package/lib/typescript/components/TrainingModal.d.ts.map +0 -1
  434. package/lib/typescript/components/UniversalOnboarding.d.ts +0 -4
  435. package/lib/typescript/components/UniversalOnboarding.d.ts.map +0 -1
  436. package/lib/typescript/components/onboarding/OAuthWebView.d.ts +0 -10
  437. package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +0 -1
  438. package/lib/typescript/components/onboarding/OnboardingHeader.d.ts +0 -11
  439. package/lib/typescript/components/onboarding/OnboardingHeader.d.ts.map +0 -1
  440. package/lib/typescript/components/onboarding/PinInput.d.ts +0 -4
  441. package/lib/typescript/components/onboarding/PinInput.d.ts.map +0 -1
  442. package/lib/typescript/components/onboarding/PlatformConnector.d.ts +0 -13
  443. package/lib/typescript/components/onboarding/PlatformConnector.d.ts.map +0 -1
  444. package/lib/typescript/components/screens/ConnectorScreen.d.ts +0 -9
  445. package/lib/typescript/components/screens/ConnectorScreen.d.ts.map +0 -1
  446. package/lib/typescript/components/screens/LoadingScreen.d.ts +0 -9
  447. package/lib/typescript/components/screens/LoadingScreen.d.ts.map +0 -1
  448. package/lib/typescript/components/screens/PinCreationScreen.d.ts +0 -10
  449. package/lib/typescript/components/screens/PinCreationScreen.d.ts.map +0 -1
  450. package/lib/typescript/constants/index.d.ts +0 -53
  451. package/lib/typescript/constants/index.d.ts.map +0 -1
  452. package/lib/typescript/hooks/useConnections.d.ts +0 -9
  453. package/lib/typescript/hooks/useConnections.d.ts.map +0 -1
  454. package/lib/typescript/hooks/useCredentials.d.ts +0 -9
  455. package/lib/typescript/hooks/useCredentials.d.ts.map +0 -1
  456. package/lib/typescript/index.d.ts +0 -18
  457. package/lib/typescript/index.d.ts.map +0 -1
  458. package/lib/typescript/services/apiKeyService.d.ts +0 -132
  459. package/lib/typescript/services/apiKeyService.d.ts.map +0 -1
  460. package/lib/typescript/services/oauthService.d.ts +0 -50
  461. package/lib/typescript/services/oauthService.d.ts.map +0 -1
  462. package/lib/typescript/services/platformAuthService.d.ts +0 -144
  463. package/lib/typescript/services/platformAuthService.d.ts.map +0 -1
  464. package/lib/typescript/types/index.d.ts +0 -231
  465. package/lib/typescript/types/index.d.ts.map +0 -1
  466. package/lib/typescript/types.d.ts +0 -270
  467. package/lib/typescript/types.d.ts.map +0 -1
  468. package/lib/typescript/utils/Portal.d.ts +0 -14
  469. package/lib/typescript/utils/Portal.d.ts.map +0 -1
  470. package/lib/typescript/utils/api.d.ts +0 -6
  471. package/lib/typescript/utils/api.d.ts.map +0 -1
  472. package/lib/typescript/utils/auth.d.ts +0 -6
  473. package/lib/typescript/utils/auth.d.ts.map +0 -1
  474. package/lib/typescript/utils/crypto.d.ts +0 -4
  475. package/lib/typescript/utils/crypto.d.ts.map +0 -1
  476. package/lib/typescript/utils/debugHelper.d.ts +0 -29
  477. package/lib/typescript/utils/debugHelper.d.ts.map +0 -1
  478. package/lib/typescript/utils/encryption.d.ts +0 -19
  479. package/lib/typescript/utils/encryption.d.ts.map +0 -1
  480. package/lib/typescript/utils/onairosApi.d.ts +0 -87
  481. package/lib/typescript/utils/onairosApi.d.ts.map +0 -1
  482. package/lib/typescript/utils/programmaticFlow.d.ts +0 -23
  483. package/lib/typescript/utils/programmaticFlow.d.ts.map +0 -1
  484. package/lib/typescript/utils/retryHelper.d.ts +0 -69
  485. package/lib/typescript/utils/retryHelper.d.ts.map +0 -1
  486. package/lib/typescript/utils/secureStorage.d.ts +0 -94
  487. package/lib/typescript/utils/secureStorage.d.ts.map +0 -1
  488. package/src/api/index.ts +0 -111
  489. package/src/assets/images/email.png +0 -0
  490. package/src/assets/images/linkedin.png +0 -0
  491. package/src/assets/images/onairos_logo.png +0 -0
  492. package/src/assets/images/reddit.png +0 -0
  493. package/src/assets/images/youtube.png +0 -0
  494. package/src/components/DataRequestModal.tsx +0 -227
  495. package/src/components/DataRequestScreen.tsx +0 -356
  496. package/src/components/EmailVerificationModal.tsx +0 -364
  497. package/src/components/Onairos.tsx +0 -425
  498. package/src/components/OnairosButton.tsx +0 -359
  499. package/src/components/Overlay.tsx +0 -506
  500. package/src/components/PinInput.tsx +0 -343
  501. package/src/components/PlatformList.tsx +0 -145
  502. package/src/components/TrainingModal.tsx +0 -737
  503. package/src/components/UniversalOnboarding.tsx +0 -1839
  504. package/src/components/UniversalOnboarding.tsx.new +0 -455
  505. package/src/components/onboarding/OAuthWebView.tsx +0 -838
  506. package/src/components/onboarding/OnboardingHeader.tsx +0 -70
  507. package/src/components/onboarding/PinInput.tsx +0 -356
  508. package/src/components/onboarding/PlatformConnector.tsx +0 -302
  509. package/src/components/screens/ConnectorScreen.tsx +0 -153
  510. package/src/components/screens/LoadingScreen.tsx +0 -100
  511. package/src/components/screens/PinCreationScreen.tsx +0 -67
  512. package/src/constants/index.ts +0 -83
  513. package/src/hooks/useConnections.ts +0 -163
  514. package/src/hooks/useCredentials.ts +0 -175
  515. package/src/index.js +0 -14
  516. package/src/index.ts +0 -50
  517. package/src/services/SDK_API_KEY_VALIDATION.md +0 -428
  518. package/src/services/apiKeyService.ts +0 -979
  519. package/src/services/oauthService.ts +0 -412
  520. package/src/services/platformAuthService.ts +0 -1113
  521. package/src/types/ambient.d.ts +0 -29
  522. package/src/types/declarations.d.ts +0 -26
  523. package/src/types/index.d.ts +0 -274
  524. package/src/types/index.ts +0 -244
  525. package/src/types/node-fix.d.ts +0 -19
  526. package/src/types/node-override.d.ts +0 -24
  527. package/src/types/opacity.d.ts +0 -16
  528. package/src/types/types.d.ts +0 -18
  529. package/src/types.ts +0 -298
  530. package/src/utils/Portal.tsx +0 -83
  531. package/src/utils/api.js +0 -112
  532. package/src/utils/auth.js +0 -104
  533. package/src/utils/crypto.js +0 -60
  534. package/src/utils/debugHelper.ts +0 -53
  535. package/src/utils/encryption.ts +0 -69
  536. package/src/utils/onairosApi.ts +0 -391
  537. package/src/utils/programmaticFlow.ts +0 -113
  538. package/src/utils/retryHelper.ts +0 -275
  539. package/src/utils/secureStorage.ts +0 -361
  540. package/types/index.d.ts +0 -218
  541. package/types/node-env.d.ts +0 -15
  542. /package/{src/assets/images โ†’ lib/commonjs/assets/icons}/farcaster.png +0 -0
  543. /package/{src/assets/images โ†’ lib/commonjs/assets/icons}/instagram.png +0 -0
  544. /package/{src/assets/images โ†’ lib/commonjs/assets/icons}/pinterest.png +0 -0
  545. /package/{src/assets/images โ†’ lib/commonjs/assets/icons}/swerv_logo.png +0 -0
  546. /package/{src/assets/images โ†’ lib/commonjs/assets/icons}/twitter.jpg +0 -0
@@ -1,1113 +0,0 @@
1
- import { Platform, Linking } from 'react-native';
2
- import AsyncStorage from '@react-native-async-storage/async-storage';
3
- import type { PlatformAuthConfig } from '../types';
4
- import { makeDeveloperRequest, getApiConfig, storeJWT, extractUsernameFromJWT } from './apiKeyService';
5
-
6
- // ๐Ÿ”‘ CRITICAL: Use two-tier authentication system
7
- // - Developer API key for email verification requests
8
- // - JWT tokens for user-authenticated requests after email verification
9
-
10
- /**
11
- * Initialize the platform auth service
12
- * This service now uses the two-tier authentication system
13
- */
14
- export const initializePlatformAuthService = async (): Promise<void> => {
15
- try {
16
- // Check if app is already initialized with API key
17
- const existingConfig = getApiConfig();
18
-
19
- if (existingConfig && existingConfig.apiKey) {
20
- console.log('๐Ÿ”‘ Platform auth service using existing app configuration');
21
- console.log(`โœ… Environment: ${existingConfig.environment}`);
22
- return;
23
- }
24
-
25
- // If no app initialization, we can't proceed
26
- console.error('โŒ Platform auth service requires app-level API key initialization');
27
- throw new Error('Platform auth service requires app-level API key initialization. Please call initializeApiKey() first.');
28
- } catch (error) {
29
- console.error('โŒ Failed to initialize platform auth service:', error);
30
- throw error;
31
- }
32
- };
33
-
34
- // Configuration for each platform's authentication
35
- let PLATFORM_AUTH_CONFIG: Record<string, PlatformAuthConfig> = {
36
- instagram: {
37
- hasNativeSDK: false, // Instagram uses OAuth WebView flow
38
- authEndpoint: '/instagram/authorize',
39
- color: '#E1306C',
40
- },
41
- youtube: {
42
- hasNativeSDK: true, // Native Google Sign-In SDK enabled
43
- nativeSDKPackage: '@react-native-google-signin/google-signin',
44
- authEndpoint: '/youtube/authorize',
45
- color: '#FF0000',
46
- clientId: '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com',
47
- redirectUri: 'onairosevents://auth/callback',
48
- scope: 'https://www.googleapis.com/auth/youtube.readonly',
49
- responseType: 'code',
50
- },
51
- reddit: {
52
- hasNativeSDK: false,
53
- authEndpoint: '/reddit/authorize',
54
- color: '#FF4500',
55
- },
56
- pinterest: {
57
- hasNativeSDK: false,
58
- authEndpoint: '/pinterest/authorize',
59
- color: '#E60023',
60
- },
61
- email: {
62
- hasNativeSDK: false,
63
- authEndpoint: '/gmail/authorize',
64
- color: '#4285F4',
65
- },
66
- };
67
-
68
- /**
69
- * Checks if a native SDK is available for the given platform
70
- */
71
- export const hasNativeSDK = (platform: string): boolean => {
72
- const config = PLATFORM_AUTH_CONFIG[platform];
73
- return config?.hasNativeSDK || false;
74
- };
75
-
76
- /**
77
- * Gets the auth endpoint URL for a platform
78
- */
79
- export const getAuthEndpoint = (platform: string): string => {
80
- const config = PLATFORM_AUTH_CONFIG[platform];
81
- return config?.authEndpoint || '';
82
- };
83
-
84
- /**
85
- * Gets the color associated with a platform
86
- */
87
- export const getPlatformColor = (platform: string): string => {
88
- const config = PLATFORM_AUTH_CONFIG[platform];
89
- return config?.color || '#000000';
90
- };
91
-
92
- /**
93
- * Initiates the OAuth flow for a platform
94
- * @param platform The platform to authenticate with
95
- * @param username The username to associate with the authentication
96
- * @param appName The app name to use for the OAuth session (optional)
97
- * @returns A Promise that resolves to the OAuth URL to open in a WebView or null if using native SDK
98
- */
99
- export const initiateOAuth = async (platform: string, username: string, appName?: string): Promise<string | null> => {
100
- try {
101
- console.log('๐Ÿš€ Initiating OAuth for platform:', platform);
102
- console.log('๐Ÿ‘ค Username:', username);
103
- console.log('๐Ÿ“ฑ App name:', appName);
104
-
105
- // Check if the platform is supported
106
- if (!PLATFORM_AUTH_CONFIG[platform]) {
107
- console.error('โŒ Unsupported platform:', platform);
108
- throw new Error(`Unsupported platform: ${platform}`);
109
- }
110
-
111
- // Check if platform has a native SDK
112
- if (PLATFORM_AUTH_CONFIG[platform].hasNativeSDK) {
113
- console.log('๐Ÿ“ฑ Platform uses native SDK, returning null');
114
- // Return null to indicate that we should use the native SDK
115
- return null;
116
- }
117
-
118
- console.log('๐ŸŒ Platform uses OAuth WebView flow');
119
- console.log('๐Ÿ”— Auth endpoint:', PLATFORM_AUTH_CONFIG[platform].authEndpoint);
120
-
121
- // Pre-flight connectivity check
122
- console.log('๐Ÿ” Performing pre-flight connectivity check...');
123
- const connectivityResult = await testApiConnectivity();
124
-
125
- if (!connectivityResult.success) {
126
- console.error('โŒ Pre-flight connectivity check failed:', connectivityResult.error);
127
- throw new Error(`Cannot reach authentication server: ${connectivityResult.error}`);
128
- }
129
-
130
- console.log('โœ… Pre-flight connectivity check passed');
131
-
132
- // Handle Instagram with specific API format
133
- if (platform === 'instagram') {
134
- const state = 'djksbfds';
135
- const jsonData = {
136
- session: {
137
- oauthState: state,
138
- username: username || 'Avatar',
139
- },
140
- };
141
-
142
- console.log('๐Ÿ“ค Sending Instagram OAuth request:', jsonData);
143
-
144
- const response = await makeDeveloperRequest(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
145
- method: 'POST',
146
- body: JSON.stringify(jsonData),
147
- });
148
-
149
- console.log('๐Ÿ“ก Instagram OAuth response status:', response.status);
150
-
151
- if (!response.ok) {
152
- const errorText = await response.text();
153
- console.error('โŒ Instagram OAuth API error:', errorText);
154
- throw new Error(`Instagram OAuth API error: ${response.status} - ${errorText}`);
155
- }
156
-
157
- const responseData = await response.json();
158
- console.log('๐Ÿ“ฅ Instagram OAuth response data:', responseData);
159
-
160
- if (responseData.instagramURL) {
161
- console.log('โœ… Instagram OAuth URL received:', responseData.instagramURL);
162
-
163
- // Validate the URL before returning
164
- if (await validateOAuthUrl(responseData.instagramURL)) {
165
- return responseData.instagramURL;
166
- } else {
167
- throw new Error('Received invalid Instagram OAuth URL');
168
- }
169
- }
170
-
171
- console.error('โŒ No Instagram URL found in response');
172
- throw new Error('No Instagram URL found in response');
173
- }
174
-
175
- // Prepare the request body for other platforms
176
- const jsonData = {
177
- session: {
178
- oauthState: 'djksbfds', // Use same state for all platforms
179
- username: username || 'Avatar',
180
- appName: appName || 'DefaultApp',
181
- },
182
- };
183
-
184
- console.log(`๐Ÿ“ค Sending ${platform} OAuth request:`, jsonData);
185
-
186
- // Make the authenticated request to get the OAuth URL
187
- const response = await makeDeveloperRequest(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
188
- method: 'POST',
189
- body: JSON.stringify(jsonData),
190
- });
191
-
192
- console.log(`๐Ÿ“ก ${platform} OAuth response status:`, response.status);
193
-
194
- if (!response.ok) {
195
- const errorText = await response.text();
196
- console.error(`โŒ ${platform} OAuth API error:`, errorText);
197
- throw new Error(`${platform} OAuth API error: ${response.status} - ${errorText}`);
198
- }
199
-
200
- // Parse the response
201
- const data = await response.json();
202
- console.log(`๐Ÿ“ฅ ${platform} OAuth response data:`, data);
203
-
204
- // Extra logging for Gmail to help debug
205
- if (platform === 'email') {
206
- console.log('๐Ÿ” Gmail OAuth response keys:', Object.keys(data));
207
- console.log('๐Ÿ” Gmail OAuth full response:', JSON.stringify(data, null, 2));
208
- }
209
-
210
- // Check if the response contains the OAuth URL based on platform
211
- let oauthUrl: string | null = null;
212
-
213
- switch (platform) {
214
- case 'reddit':
215
- oauthUrl = data.redditURL;
216
- break;
217
- case 'pinterest':
218
- oauthUrl = data.pinterestURL;
219
- break;
220
- case 'youtube':
221
- oauthUrl = data.youtubeURL;
222
- break;
223
- case 'email':
224
- // Gmail might return under different field names
225
- oauthUrl = data.emailURL || data.gmailURL || data.authUrl || data.url;
226
- break;
227
- default:
228
- oauthUrl = data.url;
229
- break;
230
- }
231
-
232
- if (!oauthUrl) {
233
- console.error(`โŒ No OAuth URL found in response for ${platform}. Response:`, data);
234
- throw new Error(`No OAuth URL found in response for ${platform}`);
235
- }
236
-
237
- console.log(`โœ… ${platform} OAuth URL received:`, oauthUrl);
238
-
239
- // Validate the URL before returning
240
- if (await validateOAuthUrl(oauthUrl)) {
241
- return oauthUrl;
242
- } else {
243
- throw new Error(`Received invalid ${platform} OAuth URL`);
244
- }
245
- } catch (error) {
246
- console.error(`Error initiating OAuth for ${platform}:`, error);
247
- throw error;
248
- }
249
- };
250
-
251
- /**
252
- * Validates an OAuth URL to ensure it's reachable
253
- * @param url The OAuth URL to validate
254
- * @returns Promise<boolean> indicating if the URL is valid and reachable
255
- */
256
- const validateOAuthUrl = async (url: string): Promise<boolean> => {
257
- try {
258
- console.log('๐Ÿ” Validating OAuth URL:', url);
259
-
260
- // Basic URL format validation
261
- if (!url || typeof url !== 'string') {
262
- console.error('โŒ Invalid URL format:', url);
263
- return false;
264
- }
265
-
266
- // Check if URL starts with https
267
- if (!url.startsWith('https://')) {
268
- console.error('โŒ URL must use HTTPS:', url);
269
- return false;
270
- }
271
-
272
- // Try to parse the URL
273
- try {
274
- new URL(url);
275
- } catch (parseError) {
276
- console.error('โŒ URL parsing failed:', parseError);
277
- return false;
278
- }
279
-
280
- // Make a HEAD request to check if the URL is reachable
281
- const controller = new AbortController();
282
- const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
283
-
284
- try {
285
- const response = await fetch(url, {
286
- method: 'HEAD',
287
- signal: controller.signal,
288
- });
289
-
290
- clearTimeout(timeoutId);
291
-
292
- // Accept any response that's not a network error
293
- // OAuth pages might return various status codes
294
- console.log('โœ… OAuth URL validation successful, status:', response.status);
295
- return true;
296
- } catch (fetchError) {
297
- clearTimeout(timeoutId);
298
-
299
- if (fetchError.name === 'AbortError') {
300
- console.warn('โš ๏ธ OAuth URL validation timeout, but proceeding anyway');
301
- return true; // Allow timeout as URLs might be slow to respond
302
- }
303
-
304
- console.warn('โš ๏ธ OAuth URL validation failed, but proceeding anyway:', fetchError.message);
305
- return true; // Allow network errors as they might be temporary
306
- }
307
- } catch (error) {
308
- console.warn('โš ๏ธ OAuth URL validation error, but proceeding anyway:', error);
309
- return true; // Allow validation errors to not block the flow
310
- }
311
- };
312
-
313
- /**
314
- * Initiates the native SDK authentication flow for a platform
315
- * @param platform The platform to authenticate with
316
- * @returns A Promise that resolves to the authentication result
317
- */
318
- export const initiateNativeAuth = async (platform: string, username?: string): Promise<boolean> => {
319
- if (platform === 'youtube') {
320
- console.log('๐Ÿ”— Initiating native Google Sign-In for YouTube');
321
- try {
322
- // Check if Google Sign-In package is available
323
- let GoogleSignin, statusCodes;
324
- try {
325
- const googleSignInModule = require('@react-native-google-signin/google-signin');
326
- GoogleSignin = googleSignInModule.GoogleSignin;
327
- statusCodes = googleSignInModule.statusCodes;
328
- } catch (importError) {
329
- console.error('โŒ Google Sign-In package not available:', importError);
330
- throw new Error('Google Sign-In SDK not installed. Please install @react-native-google-signin/google-signin');
331
- }
332
-
333
- // Configure Google Sign-In with better error handling
334
- try {
335
- const youtubeConfig = PLATFORM_AUTH_CONFIG.youtube;
336
- const webClientId = youtubeConfig.clientId || '1030678346906-lovkuds2ouqmoc8eu5qpo98spa6edv4o.apps.googleusercontent.com';
337
- const iosClientId = youtubeConfig.iosClientId || webClientId;
338
-
339
- await GoogleSignin.configure({
340
- webClientId: webClientId,
341
- iosClientId: iosClientId,
342
- scopes: ['https://www.googleapis.com/auth/youtube.readonly'],
343
- offlineAccess: true,
344
- hostedDomain: '',
345
- forceCodeForRefreshToken: true,
346
- accountName: '',
347
- });
348
- console.log('โœ… Google Sign-In configured successfully with client ID:', webClientId.substring(0, 20) + '...');
349
- } catch (configError) {
350
- console.error('โŒ Google Sign-In configuration failed:', configError);
351
- throw new Error(`Google Sign-In configuration failed: ${configError.message || configError}`);
352
- }
353
-
354
- // Check if Google Play Services are available (Android only)
355
- try {
356
- await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
357
- console.log('โœ… Google Play Services available');
358
- } catch (playServicesError) {
359
- console.error('โŒ Google Play Services error:', playServicesError);
360
- throw new Error(`Google Play Services not available: ${playServicesError.message || playServicesError}`);
361
- }
362
-
363
- // Sign in with Google
364
- let userInfo;
365
- try {
366
- userInfo = await GoogleSignin.signIn();
367
- console.log('โœ… Google Sign-In successful:', userInfo.user?.email);
368
- } catch (signInError) {
369
- console.error('โŒ Google Sign-In failed:', signInError);
370
-
371
- // Handle specific error codes
372
- if (signInError.code === statusCodes.SIGN_IN_CANCELLED) {
373
- throw new Error('Google Sign-In was cancelled by user');
374
- } else if (signInError.code === statusCodes.IN_PROGRESS) {
375
- throw new Error('Google Sign-In already in progress');
376
- } else if (signInError.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
377
- throw new Error('Google Play Services not available or outdated');
378
- } else {
379
- throw new Error(`Google Sign-In failed: ${signInError.message || signInError}`);
380
- }
381
- }
382
-
383
- // Get access token for API calls
384
- const tokens = await GoogleSignin.getTokens();
385
- console.log('๐Ÿ”‘ Got Google tokens');
386
-
387
- // Get current user info with refresh token
388
- const currentUser = await GoogleSignin.getCurrentUser();
389
- console.log('๐Ÿ‘ค Current user info:', currentUser?.user?.email);
390
-
391
- // Extract refresh token from server auth code
392
- let refreshToken = null;
393
- if (currentUser?.serverAuthCode) {
394
- console.log('๐Ÿ”„ Server auth code available for refresh token');
395
- refreshToken = currentUser.serverAuthCode;
396
- }
397
-
398
- if (!refreshToken) {
399
- console.warn('โš ๏ธ No refresh token available - token refresh may fail later');
400
- } else {
401
- console.log('โœ… Refresh token available for YouTube connection');
402
- }
403
-
404
- // Fetch YouTube channel information
405
- let channelName = 'Unknown Channel';
406
- let channelId = null;
407
- try {
408
- console.log('๐Ÿ“บ Fetching YouTube channel information...');
409
- const channelResponse = await fetch('https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true', {
410
- headers: {
411
- 'Authorization': `Bearer ${tokens.accessToken}`,
412
- 'Accept': 'application/json'
413
- }
414
- });
415
-
416
- if (channelResponse.ok) {
417
- const channelData = await channelResponse.json();
418
- if (channelData.items && channelData.items.length > 0) {
419
- channelName = channelData.items[0].snippet.title;
420
- channelId = channelData.items[0].id;
421
- console.log('โœ… YouTube channel found:', channelName);
422
- }
423
- }
424
- } catch (channelError) {
425
- console.log('โš ๏ธ Error fetching YouTube channel info:', channelError);
426
- channelName = userInfo.user?.name || userInfo.user?.email || 'Unknown Channel';
427
- }
428
-
429
- // Get authentication info
430
- let authToken = await AsyncStorage.getItem('onairos_jwt_token') ||
431
- await AsyncStorage.getItem('enoch_token') ||
432
- await AsyncStorage.getItem('auth_token');
433
- const storedUsername = await AsyncStorage.getItem('onairos_username');
434
- const finalUsername = storedUsername || username || userInfo.user?.email || 'youtube_user';
435
-
436
- // Create auth token if needed
437
- if (!authToken || authToken.trim().length < 20) {
438
- console.log('๐Ÿ” Creating authentication token for YouTube...');
439
-
440
- try {
441
- const fallbackEmail = userInfo.user?.email || `${finalUsername}@youtube.temp`;
442
-
443
- // Create user accounts and get JWT token
444
- const onairosSignupResponse = await fetch('https://api2.onairos.uk/register/enoch', {
445
- method: 'POST',
446
- headers: {
447
- 'Content-Type': 'application/json'
448
- },
449
- body: JSON.stringify({
450
- email: fallbackEmail,
451
- username: finalUsername,
452
- name: finalUsername
453
- })
454
- });
455
-
456
- if (onairosSignupResponse.ok) {
457
- const onairosResponseData = await onairosSignupResponse.json();
458
-
459
- // Extract token from response
460
- authToken = onairosResponseData.token || onairosResponseData.data?.token || onairosResponseData.jwt;
461
-
462
- if (authToken) {
463
- // Store tokens
464
- await AsyncStorage.setItem('onairos_jwt_token', authToken);
465
- await AsyncStorage.setItem('enoch_token', authToken);
466
- await AsyncStorage.setItem('auth_token', authToken);
467
- await AsyncStorage.setItem('onairos_username', onairosResponseData.username || finalUsername);
468
-
469
- console.log('โœ… Successfully created and stored authentication token');
470
- }
471
- }
472
- } catch (tokenError) {
473
- console.warn('โš ๏ธ Error creating auth token:', tokenError);
474
- }
475
- }
476
-
477
- console.log('๐Ÿ”— Linking YouTube data to user:', finalUsername);
478
- console.log('๐Ÿ“บ YouTube channel name:', channelName);
479
-
480
- // Send tokens to backend for YouTube data processing
481
- const backendResponse = await fetch('https://api2.onairos.uk/youtube/native-auth', {
482
- method: 'POST',
483
- headers: {
484
- 'Content-Type': 'application/json',
485
- ...(authToken && { 'Authorization': `Bearer ${authToken}` })
486
- },
487
- body: JSON.stringify({
488
- session: {
489
- username: finalUsername,
490
- platform: 'youtube',
491
- timestamp: new Date().toISOString(),
492
- channelName: channelName,
493
- channelId: channelId
494
- },
495
- googleUser: userInfo.user,
496
- accessToken: tokens.accessToken,
497
- idToken: tokens.idToken,
498
- refreshToken: refreshToken, // CRITICAL: Include refresh token
499
- serverAuthCode: currentUser?.serverAuthCode,
500
- userAccountInfo: {
501
- username: finalUsername,
502
- email: userInfo.user?.email,
503
- authToken: authToken,
504
- channelName: channelName,
505
- channelId: channelId,
506
- userIdentifier: authToken ? `user-${authToken.substring(0, 10)}` : `youtube-${userInfo.user?.email}`,
507
- googleId: userInfo.user?.id,
508
- },
509
- tokenExpiry: new Date(Date.now() + 3600 * 1000).toISOString(), // 1 hour from now
510
- requestRefreshToken: true
511
- })
512
- });
513
-
514
- if (backendResponse.ok) {
515
- const responseData = await backendResponse.json();
516
- console.log('โœ… YouTube connection processed by backend:', responseData);
517
- return true;
518
- } else {
519
- const errorData = await backendResponse.text();
520
- console.error('โŒ Backend processing failed:', backendResponse.status, errorData);
521
- return false;
522
- }
523
-
524
- } catch (error: any) {
525
- console.error('โŒ Google Sign-In error:', error);
526
-
527
- const { statusCodes: StatusCodes } = require('@react-native-google-signin/google-signin');
528
-
529
- if (error.code === StatusCodes.SIGN_IN_CANCELLED) {
530
- console.log('User cancelled Google Sign-In');
531
- } else if (error.code === StatusCodes.IN_PROGRESS) {
532
- console.log('Google Sign-In already in progress');
533
- } else if (error.code === StatusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
534
- console.log('Google Play Services not available');
535
- }
536
-
537
- return false;
538
- }
539
- }
540
-
541
- return false;
542
- };
543
-
544
- /**
545
- * Handles the OAuth callback
546
- * @param url The callback URL
547
- * @returns The authorization code extracted from the URL
548
- */
549
- export const handleOAuthCallback = (url: string): string | null => {
550
- try {
551
- // Parse the URL
552
- const parsedUrl = new URL(url);
553
-
554
- // Extract the authorization code
555
- return parsedUrl.searchParams.get('code');
556
- } catch (error) {
557
- console.error('Error handling OAuth callback:', error);
558
- return null;
559
- }
560
- };
561
-
562
- /**
563
- * Checks if a URL is an OAuth callback
564
- * @param url The URL to check
565
- * @returns True if the URL is an OAuth callback
566
- */
567
- export const isOAuthCallback = (url: string): boolean => {
568
- // Check if the URL starts with our redirect URI
569
- return url.startsWith('onairosanime://auth/');
570
- };
571
-
572
- /**
573
- * Test connectivity to the Onairos API server
574
- */
575
- export const testApiConnectivity = async (): Promise<{ success: boolean; error?: string }> => {
576
- try {
577
- console.log('๐Ÿ” Testing connectivity to Onairos API...');
578
-
579
- // Test multiple endpoints for better reliability
580
- const testEndpoints = [
581
- 'https://api2.onairos.uk/health',
582
- 'https://api2.onairos.uk', // Base URL
583
- ];
584
-
585
- let lastError: string | null = null;
586
-
587
- for (const endpoint of testEndpoints) {
588
- try {
589
- console.log(`๐Ÿ” Testing endpoint: ${endpoint}`);
590
-
591
- const controller = new AbortController();
592
- const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
593
-
594
- const response = await fetch(endpoint, {
595
- method: 'GET',
596
- headers: {
597
- 'Content-Type': 'application/json',
598
- 'User-Agent': 'OnairosReactNative/1.0',
599
- },
600
- signal: controller.signal,
601
- });
602
-
603
- clearTimeout(timeoutId);
604
-
605
- console.log(`๐ŸŒ API connectivity test response for ${endpoint}:`, response.status);
606
-
607
- if (response.ok || response.status === 404) {
608
- // Accept 404 as it means the server is reachable
609
- console.log('โœ… API server is reachable');
610
- return { success: true };
611
- } else {
612
- console.log(`โš ๏ธ API server responded with status ${response.status} for ${endpoint}`);
613
- lastError = `API server error: ${response.status}`;
614
- // Continue to next endpoint
615
- }
616
- } catch (fetchError) {
617
- console.log(`โŒ Failed to reach ${endpoint}:`, fetchError);
618
-
619
- if (fetchError.name === 'AbortError') {
620
- lastError = 'Connection timeout - API server took too long to respond';
621
- } else if (fetchError.message.includes('Network request failed')) {
622
- lastError = 'Network error - check your internet connection';
623
- } else if (fetchError.message.includes('not connected to the internet')) {
624
- lastError = 'No internet connection';
625
- } else {
626
- lastError = `Network error: ${fetchError.message}`;
627
- }
628
-
629
- // Continue to next endpoint
630
- }
631
- }
632
-
633
- console.error('โŒ All API connectivity tests failed');
634
- return { success: false, error: lastError || 'Cannot reach API server' };
635
- } catch (error) {
636
- console.error('โŒ API connectivity test failed:', error);
637
- return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
638
- }
639
- };
640
-
641
- /**
642
- * ๐Ÿ”„ REFRESH GOOGLE TOKENS
643
- */
644
- export const refreshGoogleTokens = async (): Promise<{ accessToken: string; idToken?: string } | null> => {
645
- try {
646
- console.log('๐Ÿ”„ Attempting to refresh Google tokens...');
647
-
648
- const { GoogleSignin } = require('@react-native-google-signin/google-signin');
649
-
650
- const currentUser = await GoogleSignin.getCurrentUser();
651
- if (!currentUser) {
652
- console.log('โŒ User not signed in to Google, cannot refresh tokens');
653
- return null;
654
- }
655
-
656
- const tokens = await GoogleSignin.getTokens();
657
- console.log('โœ… Successfully refreshed Google tokens');
658
-
659
- return {
660
- accessToken: tokens.accessToken,
661
- idToken: tokens.idToken
662
- };
663
- } catch (error) {
664
- console.error('โŒ Failed to refresh Google tokens:', error);
665
-
666
- // If refresh fails, try to sign in again
667
- try {
668
- console.log('๐Ÿ”„ Refresh failed, attempting re-authentication...');
669
- const { GoogleSignin } = require('@react-native-google-signin/google-signin');
670
- const userInfo = await GoogleSignin.signIn();
671
- const tokens = await GoogleSignin.getTokens();
672
-
673
- console.log('โœ… Re-authentication successful');
674
- return {
675
- accessToken: tokens.accessToken,
676
- idToken: tokens.idToken
677
- };
678
- } catch (signInError) {
679
- console.error('โŒ Re-authentication also failed:', signInError);
680
- return null;
681
- }
682
- }
683
- };
684
-
685
- /**
686
- * ๐Ÿ”„ REFRESH YOUTUBE TOKENS
687
- */
688
- export const refreshYouTubeTokens = async (): Promise<boolean> => {
689
- try {
690
- console.log('๐Ÿ”„ Refreshing YouTube tokens...');
691
-
692
- // Get fresh tokens from Google SDK
693
- const freshTokens = await refreshGoogleTokens();
694
- if (!freshTokens) {
695
- console.error('โŒ Failed to get fresh tokens from Google SDK');
696
- return false;
697
- }
698
-
699
- // Get current user info
700
- const { GoogleSignin } = require('@react-native-google-signin/google-signin');
701
- const currentUser = await GoogleSignin.getCurrentUser();
702
- if (!currentUser) {
703
- console.error('โŒ No current Google user found');
704
- return false;
705
- }
706
-
707
- // Get stored auth token
708
- const authToken = await AsyncStorage.getItem('onairos_jwt_token') ||
709
- await AsyncStorage.getItem('enoch_token') ||
710
- await AsyncStorage.getItem('auth_token');
711
-
712
- if (!authToken) {
713
- console.error('โŒ No auth token found for YouTube refresh');
714
- return false;
715
- }
716
-
717
- // Send refreshed tokens to backend
718
- const refreshResponse = await fetch('https://api2.onairos.uk/youtube/refresh-token', {
719
- method: 'POST',
720
- headers: {
721
- 'Content-Type': 'application/json',
722
- 'Authorization': `Bearer ${authToken}`
723
- },
724
- body: JSON.stringify({
725
- accessToken: freshTokens.accessToken,
726
- idToken: freshTokens.idToken,
727
- refreshToken: currentUser.serverAuthCode,
728
- userEmail: currentUser.user?.email,
729
- tokenExpiry: new Date(Date.now() + 3600 * 1000).toISOString(),
730
- timestamp: new Date().toISOString()
731
- })
732
- });
733
-
734
- if (refreshResponse.ok) {
735
- const responseData = await refreshResponse.json();
736
- console.log('โœ… YouTube tokens refreshed successfully:', responseData);
737
- return true;
738
- } else {
739
- const errorData = await refreshResponse.text();
740
- console.error('โŒ YouTube token refresh failed:', refreshResponse.status, errorData);
741
- return false;
742
- }
743
- } catch (error) {
744
- console.error('โŒ Error refreshing YouTube tokens:', error);
745
- return false;
746
- }
747
- };
748
-
749
- /**
750
- * ๐ŸŽฏ ENHANCED OAUTH CALLBACK HANDLER
751
- */
752
- export const handleOAuthCallbackUrl = (url: string): { platform?: string; code?: string; success: boolean } => {
753
- try {
754
- console.log('๐Ÿ” Processing OAuth callback URL:', url);
755
-
756
- // Parse the URL
757
- const parsedUrl = new URL(url);
758
-
759
- // Extract platform and code
760
- const platform = parsedUrl.searchParams.get('platform') ||
761
- parsedUrl.pathname.split('/').find(segment =>
762
- ['instagram', 'youtube', 'reddit', 'pinterest', 'email'].includes(segment)
763
- );
764
-
765
- const code = parsedUrl.searchParams.get('code');
766
- const error = parsedUrl.searchParams.get('error');
767
-
768
- if (error) {
769
- console.error('โŒ OAuth error in callback:', error);
770
- return { success: false };
771
- }
772
-
773
- if (code && platform) {
774
- console.log(`โœ… OAuth callback processed: ${platform} with code: ${code.substring(0, 10)}...`);
775
- return { platform, code, success: true };
776
- }
777
-
778
- console.warn('โš ๏ธ OAuth callback missing platform or code');
779
- return { success: false };
780
- } catch (error) {
781
- console.error('โŒ Error processing OAuth callback:', error);
782
- return { success: false };
783
- }
784
- };
785
-
786
- /**
787
- * ๐Ÿ”ง UPDATE GOOGLE CLIENT IDS
788
- * Allows apps to configure their own Google client IDs
789
- */
790
- export const updateGoogleClientIds = (config: {
791
- webClientId?: string;
792
- iosClientId?: string;
793
- }) => {
794
- console.log('๐Ÿ”ง Updating Google client IDs configuration');
795
-
796
- if (config.webClientId || config.iosClientId) {
797
- // Update the YouTube configuration
798
- PLATFORM_AUTH_CONFIG.youtube = {
799
- ...PLATFORM_AUTH_CONFIG.youtube,
800
- clientId: config.webClientId || PLATFORM_AUTH_CONFIG.youtube.clientId,
801
- iosClientId: config.iosClientId || PLATFORM_AUTH_CONFIG.youtube.iosClientId,
802
- };
803
-
804
- console.log('โœ… Google client IDs updated successfully');
805
- console.log(' - Web Client ID:', config.webClientId ? config.webClientId.substring(0, 20) + '...' : 'not provided');
806
- console.log(' - iOS Client ID:', config.iosClientId ? config.iosClientId.substring(0, 20) + '...' : 'not provided');
807
- }
808
- };
809
-
810
- /**
811
- * Request email verification using developer API key
812
- * @param email Email address to verify
813
- * @param testMode Whether to use test mode
814
- * @returns Promise with verification result
815
- */
816
- export const requestEmailVerification = async (
817
- email: string,
818
- testMode: boolean = false
819
- ): Promise<{ success: boolean; message?: string; error?: string }> => {
820
- try {
821
- console.log('๐Ÿ“ง Requesting email verification for:', email);
822
-
823
- const response = await makeDeveloperRequest('/email/verification', {
824
- method: 'POST',
825
- body: JSON.stringify({
826
- email,
827
- action: 'request',
828
- testMode
829
- })
830
- });
831
-
832
- const data = await response.json();
833
-
834
- if (response.ok && data.success) {
835
- console.log('โœ… Email verification requested successfully');
836
- return {
837
- success: true,
838
- message: data.message || 'Verification code sent to your email'
839
- };
840
- } else {
841
- console.error('โŒ Email verification request failed:', data.error);
842
- return {
843
- success: false,
844
- error: data.error || 'Failed to send verification code'
845
- };
846
- }
847
- } catch (error) {
848
- console.error('โŒ Error requesting email verification:', error);
849
- return {
850
- success: false,
851
- error: error instanceof Error ? error.message : 'Network error'
852
- };
853
- }
854
- };
855
-
856
- /**
857
- * Verify email code and store JWT token
858
- * @param email Email address
859
- * @param code Verification code
860
- * @param testMode Whether to use test mode
861
- * @returns Promise with verification result and JWT token
862
- */
863
- export const verifyEmailCode = async (
864
- email: string,
865
- code: string,
866
- testMode: boolean = false
867
- ): Promise<{ success: boolean; message?: string; error?: string; existingUser?: boolean; token?: string }> => {
868
- try {
869
- console.log('๐Ÿ” Verifying email code for:', email);
870
-
871
- const response = await makeDeveloperRequest('/email/verification', {
872
- method: 'POST',
873
- body: JSON.stringify({
874
- email,
875
- action: 'verify',
876
- code,
877
- testMode
878
- })
879
- });
880
-
881
- const data = await response.json();
882
-
883
- if (response.ok && data.success) {
884
- console.log('โœ… Email verification successful');
885
-
886
- // Store JWT token if received
887
- if (data.token || data.jwtToken) {
888
- const jwtToken = data.token || data.jwtToken;
889
- await storeJWT(jwtToken);
890
- console.log('๐ŸŽซ JWT token stored successfully');
891
- }
892
-
893
- return {
894
- success: true,
895
- message: data.message || 'Email verified successfully',
896
- existingUser: data.existingUser || false,
897
- token: data.token || data.jwtToken
898
- };
899
- } else {
900
- console.error('โŒ Email verification failed:', data.error);
901
- return {
902
- success: false,
903
- error: data.error || 'Invalid verification code'
904
- };
905
- }
906
- } catch (error) {
907
- console.error('โŒ Error verifying email code:', error);
908
- return {
909
- success: false,
910
- error: error instanceof Error ? error.message : 'Network error'
911
- };
912
- }
913
- };
914
-
915
- /**
916
- * Check email verification status
917
- * @param email Email address
918
- * @param testMode Whether to use test mode
919
- * @returns Promise with status result
920
- */
921
- export const checkEmailVerificationStatus = async (
922
- email: string,
923
- testMode: boolean = false
924
- ): Promise<{ success: boolean; isPending?: boolean; error?: string }> => {
925
- try {
926
- console.log('๐Ÿ” Checking email verification status for:', email);
927
-
928
- const response = await makeDeveloperRequest('/email/verification/status', {
929
- method: 'POST',
930
- body: JSON.stringify({
931
- email,
932
- testMode
933
- })
934
- });
935
-
936
- const data = await response.json();
937
-
938
- if (response.ok && data.success) {
939
- return {
940
- success: true,
941
- isPending: data.isPending || false
942
- };
943
- } else {
944
- return {
945
- success: false,
946
- error: data.error || 'Failed to check verification status'
947
- };
948
- }
949
- } catch (error) {
950
- console.error('โŒ Error checking email verification status:', error);
951
- return {
952
- success: false,
953
- error: error instanceof Error ? error.message : 'Network error'
954
- };
955
- }
956
- };
957
-
958
- /**
959
- * Disconnect a platform (uses developer API key)
960
- * @param platform Platform to disconnect
961
- * @param username Username associated with the platform
962
- * @returns Promise with disconnect result
963
- */
964
- export const disconnectPlatform = async (platform: string, username: string): Promise<{ success: boolean; error?: string }> => {
965
- try {
966
- console.log('๐Ÿ”Œ Disconnecting platform:', platform, 'for user:', username);
967
-
968
- // Make authenticated API call to disconnect platform
969
- const response = await makeDeveloperRequest('/revoke', {
970
- method: 'POST',
971
- body: JSON.stringify({
972
- platform,
973
- username
974
- })
975
- });
976
-
977
- const data = await response.json();
978
-
979
- if (response.ok && data.success) {
980
- console.log(`โœ… ${platform} disconnected successfully`);
981
- return { success: true };
982
- } else {
983
- console.error(`โŒ Failed to disconnect ${platform}:`, data.error);
984
- return {
985
- success: false,
986
- error: data.error || 'Failed to disconnect platform'
987
- };
988
- }
989
- } catch (error) {
990
- console.error(`โŒ Error disconnecting ${platform}:`, error);
991
- return {
992
- success: false,
993
- error: error instanceof Error ? error.message : 'Network error'
994
- };
995
- }
996
- };
997
-
998
- /**
999
- * Store PIN for user (uses JWT authentication and extracts username from JWT)
1000
- * @param pin User PIN
1001
- * @param username Optional username (if not provided, extracts from JWT)
1002
- * @returns Promise with result
1003
- */
1004
- export const storePIN = async (pin: string, username?: string): Promise<{ success: boolean; error?: string }> => {
1005
- try {
1006
- // Extract username from JWT if not provided
1007
- const userToStore = username || extractUsernameFromJWT();
1008
-
1009
- if (!userToStore) {
1010
- console.error('โŒ No username available - either provide username or ensure JWT token is valid');
1011
- return {
1012
- success: false,
1013
- error: 'No username available for PIN storage'
1014
- };
1015
- }
1016
-
1017
- console.log('๐Ÿ” Storing PIN for user:', userToStore);
1018
-
1019
- // Make authenticated request to store PIN (using developer API key for now)
1020
- const response = await makeDeveloperRequest('/store-pin/web', {
1021
- method: 'POST',
1022
- headers: {
1023
- 'Content-Type': 'application/json',
1024
- },
1025
- body: JSON.stringify({
1026
- username: userToStore,
1027
- pin
1028
- })
1029
- });
1030
-
1031
- const data = await response.json();
1032
-
1033
- if (response.ok && data.success) {
1034
- console.log('โœ… PIN stored successfully for user:', userToStore);
1035
- return { success: true };
1036
- } else {
1037
- console.error('โŒ Failed to store PIN:', data.error);
1038
- return {
1039
- success: false,
1040
- error: data.error || 'Failed to store PIN'
1041
- };
1042
- }
1043
- } catch (error) {
1044
- console.error('โŒ Error storing PIN:', error);
1045
- return {
1046
- success: false,
1047
- error: error instanceof Error ? error.message : 'Network error'
1048
- };
1049
- }
1050
- };
1051
-
1052
- /**
1053
- * ๐ŸŽซ GET STORED JWT TOKEN
1054
- * Helper function to retrieve stored JWT token from email verification or other sources
1055
- */
1056
- export const getStoredJwtToken = async (): Promise<string | null> => {
1057
- try {
1058
- console.log('๐ŸŽซ Retrieving stored JWT token...');
1059
-
1060
- // Try different storage keys in order of preference
1061
- const tokenSources = [
1062
- 'email_verification_token',
1063
- 'onairos_jwt_token',
1064
- 'enoch_token',
1065
- 'auth_token',
1066
- ];
1067
-
1068
- for (const source of tokenSources) {
1069
- const token = await AsyncStorage.getItem(source);
1070
- if (token && token.length > 20) {
1071
- console.log(`โœ… JWT token found in ${source}:`, token.substring(0, 20) + '...');
1072
- return token;
1073
- }
1074
- }
1075
-
1076
- console.warn('โš ๏ธ No JWT token found in storage');
1077
- return null;
1078
- } catch (error) {
1079
- console.error('โŒ Error retrieving JWT token:', error);
1080
- return null;
1081
- }
1082
- };
1083
-
1084
- /**
1085
- * ๐ŸŽซ CLEAR STORED TOKENS
1086
- * Helper function to clear all stored tokens (useful for logout)
1087
- */
1088
- export const clearStoredTokens = async (): Promise<void> => {
1089
- try {
1090
- console.log('๐Ÿงน Clearing all stored tokens...');
1091
-
1092
- const tokenKeys = [
1093
- 'email_verification_token',
1094
- 'onairos_jwt_token',
1095
- 'enoch_token',
1096
- 'auth_token',
1097
- 'email_verification_email',
1098
- 'email_verification_request_id',
1099
- 'email_verification_request_email',
1100
- 'token_timestamp',
1101
- 'user_pin_stored',
1102
- 'pin_storage_timestamp',
1103
- ];
1104
-
1105
- await Promise.all(
1106
- tokenKeys.map(key => AsyncStorage.removeItem(key))
1107
- );
1108
-
1109
- console.log('โœ… All tokens cleared successfully');
1110
- } catch (error) {
1111
- console.error('โŒ Error clearing tokens:', error);
1112
- }
1113
- };