@onairos/react-native 3.4.1 → 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 (544) 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/apiClient.js +8 -0
  100. package/lib/commonjs/services/apiKeyService.js +9 -952
  101. package/lib/commonjs/services/authService.js +10 -0
  102. package/lib/commonjs/services/biometricPinService.js +8 -0
  103. package/lib/commonjs/services/chatGPTConversationExtractor.js +8 -0
  104. package/lib/commonjs/services/chatGPTConversationService.js +9 -0
  105. package/lib/commonjs/services/claudeConversationExtractor.js +8 -0
  106. package/lib/commonjs/services/claudeConversationService.js +9 -0
  107. package/lib/commonjs/services/connectedAccountsService.js +10 -0
  108. package/lib/commonjs/services/googleAuthService.js +11 -0
  109. package/lib/commonjs/services/imageCompressionService.js +7 -0
  110. package/lib/commonjs/services/jwtStorageService.js +7 -0
  111. package/lib/commonjs/services/linkedinDOMExtractor.js +7 -0
  112. package/lib/commonjs/services/linkedinProfileService.js +9 -0
  113. package/lib/commonjs/services/linkedinScrapingService.js +8 -0
  114. package/lib/commonjs/services/llmDataStorage.js +8 -0
  115. package/lib/commonjs/services/mobileTrainingService.js +8 -0
  116. package/lib/commonjs/services/oauthService.js +11 -390
  117. package/lib/commonjs/services/pinEncryptionService.js +8 -0
  118. package/lib/commonjs/services/pinStorageUtils.js +7 -0
  119. package/lib/commonjs/services/platformAuthService.js +12 -1067
  120. package/lib/commonjs/services/storageService.js +8 -0
  121. package/lib/commonjs/services/trainingApiHelpers.js +7 -0
  122. package/lib/commonjs/services/userConnectionsService.js +10 -0
  123. package/lib/commonjs/services/youtubeMigrationService.js +10 -0
  124. package/lib/commonjs/theme/index.js +7 -0
  125. package/lib/commonjs/types/ambient.d.js +1 -2
  126. package/lib/commonjs/types/declarations.d.js +1 -2
  127. package/lib/commonjs/types/index.js +1 -6
  128. package/lib/commonjs/types/node-fix.d.js +1 -2
  129. package/lib/commonjs/types/node-override.d.js +1 -2
  130. package/lib/commonjs/types/opacity.d.js +1 -2
  131. package/lib/commonjs/types.js +1 -14
  132. package/lib/commonjs/utils/Portal.js +8 -98
  133. package/lib/commonjs/utils/api.js +9 -129
  134. package/lib/commonjs/utils/assetRegistry.js +33 -0
  135. package/lib/commonjs/utils/auth.js +9 -111
  136. package/lib/commonjs/utils/crypto.js +8 -62
  137. package/lib/commonjs/utils/debugHelper.js +1 -64
  138. package/lib/commonjs/utils/encryption.js +7 -76
  139. package/lib/commonjs/utils/eventUtils.js +1 -0
  140. package/lib/commonjs/utils/haptics.js +9 -0
  141. package/lib/commonjs/utils/imagePreloader.js +1 -0
  142. package/lib/commonjs/utils/networkDiagnostics.js +8 -0
  143. package/lib/commonjs/utils/onairosApi.js +9 -350
  144. package/lib/commonjs/utils/programmaticFlow.js +9 -117
  145. package/lib/commonjs/utils/retryHelper.js +1 -220
  146. package/lib/commonjs/utils/secureStorage.js +10 -349
  147. package/lib/commonjs/utils/webviewScripts/chatgpt.js +1 -0
  148. package/lib/commonjs/utils/webviewScripts/claude.js +1 -0
  149. package/lib/commonjs/utils/webviewScripts/index.js +9 -0
  150. package/lib/commonjs/utils/webviewScripts/linkedin.js +1 -0
  151. package/lib/module/api/index.js +1 -139
  152. package/lib/module/assets/animations/loaderani.json +1 -0
  153. package/lib/module/assets/animations/persona-animation.json +1 -0
  154. package/lib/module/assets/fonts/EBGaramond-VariableFont_wght.ttf +0 -0
  155. package/lib/module/assets/fonts/IBMPlexSans-VariableFont_wdth,wght.ttf +0 -0
  156. package/lib/module/assets/icons/Facebookicon.png +0 -0
  157. package/lib/module/assets/icons/Gmail.png +0 -0
  158. package/lib/module/assets/icons/Linkedinicon.png +0 -0
  159. package/lib/module/assets/icons/Redditicon.png +0 -0
  160. package/lib/module/assets/icons/YouTubeicon2.png +0 -0
  161. package/lib/module/assets/icons/YouTubeicon3.png +0 -0
  162. package/lib/module/assets/icons/chatgpt.png +0 -0
  163. package/lib/module/assets/icons/claude.png +0 -0
  164. package/lib/module/assets/icons/farcaster.png +0 -0
  165. package/lib/module/assets/icons/gemini.png +0 -0
  166. package/lib/module/assets/icons/grok.png +0 -0
  167. package/lib/module/assets/icons/instagram.png +0 -0
  168. package/lib/module/assets/icons/pinterest.png +0 -0
  169. package/lib/module/assets/icons/swerv_logo.png +0 -0
  170. package/lib/module/assets/icons/twitter.jpg +0 -0
  171. package/lib/module/assets/images/Checkbox.svg +3 -0
  172. package/lib/module/assets/images/EnochE.svg +19 -0
  173. package/lib/module/assets/images/Enochicon1.png +0 -0
  174. package/lib/module/assets/images/Face_ID_logo.png +0 -0
  175. package/lib/module/assets/images/Facebookicon.png +0 -0
  176. package/lib/module/assets/images/Gmail.png +0 -0
  177. package/lib/module/assets/images/Googlelogo.png +0 -0
  178. package/lib/module/assets/images/Linkedinicon.png +0 -0
  179. package/lib/module/assets/images/Onairoslogo.png +0 -0
  180. package/lib/module/assets/images/Personalityprofile.svg +3 -0
  181. package/lib/module/assets/images/Personalitytraits.svg +3 -0
  182. package/lib/module/assets/images/Redditicon.png +0 -0
  183. package/lib/module/assets/images/Userpreferences.svg +3 -0
  184. package/lib/module/assets/images/YouTubeicon3.png +0 -0
  185. package/lib/module/assets/images/arrow.svg +20 -0
  186. package/lib/module/assets/images/basicproficon.svg +43 -0
  187. package/lib/module/assets/images/basicprofile.svg +3 -0
  188. package/lib/module/assets/images/chatgpt.png +0 -0
  189. package/lib/module/assets/images/checkmark.svg +4 -0
  190. package/lib/module/assets/images/claude.png +0 -0
  191. package/lib/module/assets/images/contentanalysis.svg +3 -0
  192. package/lib/module/assets/images/contenticon.svg +23 -0
  193. package/lib/module/assets/images/gemini.png +0 -0
  194. package/lib/module/assets/images/grok.png +0 -0
  195. package/lib/module/assets/images/persona1.png +0 -0
  196. package/lib/module/assets/images/persona2.png +0 -0
  197. package/lib/module/assets/images/persona3.png +0 -0
  198. package/lib/module/assets/images/persona4.png +0 -0
  199. package/lib/module/assets/images/persona5.png +0 -0
  200. package/lib/module/assets/images/personalityicon.svg +18 -0
  201. package/lib/module/assets/images/x-close.svg +3 -0
  202. package/lib/module/components/BodyText.js +1 -0
  203. package/lib/module/components/BrandMark.js +1 -0
  204. package/lib/module/components/CodeInput.js +1 -0
  205. package/lib/module/components/EmailInput.js +1 -0
  206. package/lib/module/components/GoogleButton.js +1 -0
  207. package/lib/module/components/HeadingGroup.js +1 -0
  208. package/lib/module/components/LLMDataInputModal.js +8 -0
  209. package/lib/module/components/ModalHeader.js +1 -0
  210. package/lib/module/components/ModalSheet.js +1 -0
  211. package/lib/module/components/Onairos.js +1 -367
  212. package/lib/module/components/OnairosButton.js +1 -302
  213. package/lib/module/components/OnairosSignInButton.js +1 -0
  214. package/lib/module/components/Overlay.js +1 -474
  215. package/lib/module/components/PersonaImage.js +1 -0
  216. package/lib/module/components/PersonaLoadingScreen.js +1 -0
  217. package/lib/module/components/PersonalizationConsentScreen.js +1 -0
  218. package/lib/module/components/PinCreationScreen.js +1 -0
  219. package/lib/module/components/PinInput.js +1 -293
  220. package/lib/module/components/PlatformConnectorsStep.js +1 -0
  221. package/lib/module/components/PlatformList.js +1 -129
  222. package/lib/module/components/PlatformToggle.js +1 -0
  223. package/lib/module/components/PrimaryButton.js +1 -0
  224. package/lib/module/components/SignInMatchAnimation.js +1 -0
  225. package/lib/module/components/SignInStep.js +1 -0
  226. package/lib/module/components/UniversalOnboarding.js +1 -1693
  227. package/lib/module/components/VerificationStep.js +1 -0
  228. package/lib/module/components/WelcomeScreen.js +1 -0
  229. package/lib/module/components/icons/Basicproficon.js +1 -0
  230. package/lib/module/components/icons/Basicprofile.js +1 -0
  231. package/lib/module/components/icons/Checkbox.js +1 -0
  232. package/lib/module/components/icons/Checkmark.js +1 -0
  233. package/lib/module/components/icons/Contentanalysis.js +1 -0
  234. package/lib/module/components/icons/Contenticon.js +1 -0
  235. package/lib/module/components/icons/EnochE.js +1 -0
  236. package/lib/module/components/icons/Personalityicon.js +1 -0
  237. package/lib/module/components/icons/Personalityprofile.js +1 -0
  238. package/lib/module/components/icons/Personalitytraits.js +1 -0
  239. package/lib/module/components/icons/Userpreferences.js +1 -0
  240. package/lib/module/components/icons/index.js +1 -0
  241. package/lib/module/components/onboarding/OAuthWebView.js +1 -818
  242. package/lib/module/components/onboarding/OnboardingHeader.js +1 -66
  243. package/lib/module/components/onboarding/PinInput.js +1 -274
  244. package/lib/module/components/onboarding/PlatformConnector.js +1 -240
  245. package/lib/module/config/api.js +1 -0
  246. package/lib/module/constants/index.js +1 -77
  247. package/lib/module/context/AuthContext.js +1 -0
  248. package/lib/module/hooks/useConnectedAccounts.js +1 -0
  249. package/lib/module/hooks/useConnections.js +1 -152
  250. package/lib/module/hooks/useCredentials.js +6 -169
  251. package/lib/module/hooks/useUserConnections.js +1 -0
  252. package/lib/module/index.js +1 -32
  253. package/lib/module/services/apiClient.js +1 -0
  254. package/lib/module/services/apiKeyService.js +1 -925
  255. package/lib/module/services/authService.js +1 -0
  256. package/lib/module/services/biometricPinService.js +1 -0
  257. package/lib/module/services/chatGPTConversationExtractor.js +1 -0
  258. package/lib/module/services/chatGPTConversationService.js +1 -0
  259. package/lib/module/services/claudeConversationExtractor.js +1 -0
  260. package/lib/module/services/claudeConversationService.js +1 -0
  261. package/lib/module/services/connectedAccountsService.js +1 -0
  262. package/lib/module/services/googleAuthService.js +1 -0
  263. package/lib/module/services/imageCompressionService.js +1 -0
  264. package/lib/module/services/jwtStorageService.js +1 -0
  265. package/lib/module/services/linkedinDOMExtractor.js +1 -0
  266. package/lib/module/services/linkedinProfileService.js +1 -0
  267. package/lib/module/services/linkedinScrapingService.js +1 -0
  268. package/lib/module/services/llmDataStorage.js +1 -0
  269. package/lib/module/services/mobileTrainingService.js +1 -0
  270. package/lib/module/services/oauthService.js +1 -380
  271. package/lib/module/services/pinEncryptionService.js +7 -0
  272. package/lib/module/services/pinStorageUtils.js +1 -0
  273. package/lib/module/services/platformAuthService.js +1 -1041
  274. package/lib/module/services/storageService.js +1 -0
  275. package/lib/module/services/trainingApiHelpers.js +1 -0
  276. package/lib/module/services/userConnectionsService.js +1 -0
  277. package/lib/module/services/youtubeMigrationService.js +1 -0
  278. package/lib/module/theme/index.js +1 -0
  279. package/lib/module/types.js +1 -10
  280. package/lib/module/utils/Portal.js +1 -90
  281. package/lib/module/utils/api.js +1 -117
  282. package/lib/module/utils/assetRegistry.js +33 -0
  283. package/lib/module/utils/auth.js +1 -99
  284. package/lib/module/utils/crypto.js +1 -54
  285. package/lib/module/utils/debugHelper.js +1 -54
  286. package/lib/module/utils/encryption.js +1 -67
  287. package/lib/module/utils/eventUtils.js +1 -0
  288. package/lib/module/utils/haptics.js +8 -0
  289. package/lib/module/utils/imagePreloader.js +1 -0
  290. package/lib/module/utils/networkDiagnostics.js +1 -0
  291. package/lib/module/utils/onairosApi.js +1 -333
  292. package/lib/module/utils/programmaticFlow.js +1 -111
  293. package/lib/module/utils/retryHelper.js +1 -211
  294. package/lib/module/utils/secureStorage.js +6 -330
  295. package/lib/module/utils/webviewScripts/chatgpt.js +1 -0
  296. package/lib/module/utils/webviewScripts/claude.js +1 -0
  297. package/lib/module/utils/webviewScripts/index.js +1 -0
  298. package/lib/module/utils/webviewScripts/linkedin.js +1 -0
  299. package/package.json +62 -39
  300. package/lib/commonjs/api/index.js.map +0 -1
  301. package/lib/commonjs/assets/images/email.png +0 -0
  302. package/lib/commonjs/assets/images/linkedin.png +0 -0
  303. package/lib/commonjs/assets/images/reddit.png +0 -0
  304. package/lib/commonjs/assets/images/youtube.png +0 -0
  305. package/lib/commonjs/components/DataRequestModal.js +0 -228
  306. package/lib/commonjs/components/DataRequestModal.js.map +0 -1
  307. package/lib/commonjs/components/DataRequestScreen.js +0 -329
  308. package/lib/commonjs/components/DataRequestScreen.js.map +0 -1
  309. package/lib/commonjs/components/EmailVerificationModal.js +0 -320
  310. package/lib/commonjs/components/EmailVerificationModal.js.map +0 -1
  311. package/lib/commonjs/components/Onairos.js.map +0 -1
  312. package/lib/commonjs/components/OnairosButton.js.map +0 -1
  313. package/lib/commonjs/components/Overlay.js.map +0 -1
  314. package/lib/commonjs/components/PinInput.js.map +0 -1
  315. package/lib/commonjs/components/PlatformList.js.map +0 -1
  316. package/lib/commonjs/components/TrainingModal.js +0 -717
  317. package/lib/commonjs/components/TrainingModal.js.map +0 -1
  318. package/lib/commonjs/components/UniversalOnboarding.js.map +0 -1
  319. package/lib/commonjs/components/UniversalOnboarding.tsx.new +0 -455
  320. package/lib/commonjs/components/onboarding/OAuthWebView.js.map +0 -1
  321. package/lib/commonjs/components/onboarding/OnboardingHeader.js.map +0 -1
  322. package/lib/commonjs/components/onboarding/PinInput.js.map +0 -1
  323. package/lib/commonjs/components/onboarding/PlatformConnector.js.map +0 -1
  324. package/lib/commonjs/components/screens/ConnectorScreen.js +0 -146
  325. package/lib/commonjs/components/screens/ConnectorScreen.js.map +0 -1
  326. package/lib/commonjs/components/screens/LoadingScreen.js +0 -91
  327. package/lib/commonjs/components/screens/LoadingScreen.js.map +0 -1
  328. package/lib/commonjs/components/screens/PinCreationScreen.js +0 -61
  329. package/lib/commonjs/components/screens/PinCreationScreen.js.map +0 -1
  330. package/lib/commonjs/constants/index.js.map +0 -1
  331. package/lib/commonjs/hooks/useConnections.js.map +0 -1
  332. package/lib/commonjs/hooks/useCredentials.js.map +0 -1
  333. package/lib/commonjs/index.js.map +0 -1
  334. package/lib/commonjs/services/apiKeyService.js.map +0 -1
  335. package/lib/commonjs/services/oauthService.js.map +0 -1
  336. package/lib/commonjs/services/platformAuthService.js.map +0 -1
  337. package/lib/commonjs/types/ambient.d.js.map +0 -1
  338. package/lib/commonjs/types/declarations.d.js.map +0 -1
  339. package/lib/commonjs/types/index.d.js.map +0 -1
  340. package/lib/commonjs/types/index.js.map +0 -1
  341. package/lib/commonjs/types/node-fix.d.js.map +0 -1
  342. package/lib/commonjs/types/node-override.d.js.map +0 -1
  343. package/lib/commonjs/types/opacity.d.js.map +0 -1
  344. package/lib/commonjs/types/types.d.js.map +0 -1
  345. package/lib/commonjs/types.js.map +0 -1
  346. package/lib/commonjs/utils/Portal.js.map +0 -1
  347. package/lib/commonjs/utils/api.js.map +0 -1
  348. package/lib/commonjs/utils/auth.js.map +0 -1
  349. package/lib/commonjs/utils/crypto.js.map +0 -1
  350. package/lib/commonjs/utils/debugHelper.js.map +0 -1
  351. package/lib/commonjs/utils/encryption.js.map +0 -1
  352. package/lib/commonjs/utils/onairosApi.js.map +0 -1
  353. package/lib/commonjs/utils/programmaticFlow.js.map +0 -1
  354. package/lib/commonjs/utils/retryHelper.js.map +0 -1
  355. package/lib/commonjs/utils/secureStorage.js.map +0 -1
  356. package/lib/module/api/index.js.map +0 -1
  357. package/lib/module/assets/images/email.png +0 -0
  358. package/lib/module/assets/images/linkedin.png +0 -0
  359. package/lib/module/assets/images/reddit.png +0 -0
  360. package/lib/module/assets/images/youtube.png +0 -0
  361. package/lib/module/components/DataRequestModal.js +0 -220
  362. package/lib/module/components/DataRequestModal.js.map +0 -1
  363. package/lib/module/components/DataRequestScreen.js +0 -321
  364. package/lib/module/components/DataRequestScreen.js.map +0 -1
  365. package/lib/module/components/EmailVerificationModal.js +0 -311
  366. package/lib/module/components/EmailVerificationModal.js.map +0 -1
  367. package/lib/module/components/Onairos.js.map +0 -1
  368. package/lib/module/components/OnairosButton.js.map +0 -1
  369. package/lib/module/components/Overlay.js.map +0 -1
  370. package/lib/module/components/PinInput.js.map +0 -1
  371. package/lib/module/components/PlatformList.js.map +0 -1
  372. package/lib/module/components/TrainingModal.js +0 -708
  373. package/lib/module/components/TrainingModal.js.map +0 -1
  374. package/lib/module/components/UniversalOnboarding.js.map +0 -1
  375. package/lib/module/components/UniversalOnboarding.tsx.new +0 -455
  376. package/lib/module/components/onboarding/OAuthWebView.js.map +0 -1
  377. package/lib/module/components/onboarding/OnboardingHeader.js.map +0 -1
  378. package/lib/module/components/onboarding/PinInput.js.map +0 -1
  379. package/lib/module/components/onboarding/PlatformConnector.js.map +0 -1
  380. package/lib/module/components/screens/ConnectorScreen.js +0 -138
  381. package/lib/module/components/screens/ConnectorScreen.js.map +0 -1
  382. package/lib/module/components/screens/LoadingScreen.js +0 -83
  383. package/lib/module/components/screens/LoadingScreen.js.map +0 -1
  384. package/lib/module/components/screens/PinCreationScreen.js +0 -53
  385. package/lib/module/components/screens/PinCreationScreen.js.map +0 -1
  386. package/lib/module/constants/index.js.map +0 -1
  387. package/lib/module/hooks/useConnections.js.map +0 -1
  388. package/lib/module/hooks/useCredentials.js.map +0 -1
  389. package/lib/module/index.js.map +0 -1
  390. package/lib/module/services/apiKeyService.js.map +0 -1
  391. package/lib/module/services/oauthService.js.map +0 -1
  392. package/lib/module/services/platformAuthService.js.map +0 -1
  393. package/lib/module/types/ambient.d.js.map +0 -1
  394. package/lib/module/types/declarations.d.js.map +0 -1
  395. package/lib/module/types/index.d.js.map +0 -1
  396. package/lib/module/types/index.js.map +0 -1
  397. package/lib/module/types/node-fix.d.js.map +0 -1
  398. package/lib/module/types/node-override.d.js.map +0 -1
  399. package/lib/module/types/opacity.d.js.map +0 -1
  400. package/lib/module/types/types.d.js.map +0 -1
  401. package/lib/module/types.js.map +0 -1
  402. package/lib/module/utils/Portal.js.map +0 -1
  403. package/lib/module/utils/api.js.map +0 -1
  404. package/lib/module/utils/auth.js.map +0 -1
  405. package/lib/module/utils/crypto.js.map +0 -1
  406. package/lib/module/utils/debugHelper.js.map +0 -1
  407. package/lib/module/utils/encryption.js.map +0 -1
  408. package/lib/module/utils/onairosApi.js.map +0 -1
  409. package/lib/module/utils/programmaticFlow.js.map +0 -1
  410. package/lib/module/utils/retryHelper.js.map +0 -1
  411. package/lib/module/utils/secureStorage.js.map +0 -1
  412. package/lib/typescript/api/index.d.ts +0 -8
  413. package/lib/typescript/api/index.d.ts.map +0 -1
  414. package/lib/typescript/components/DataRequestModal.d.ts +0 -11
  415. package/lib/typescript/components/DataRequestModal.d.ts.map +0 -1
  416. package/lib/typescript/components/DataRequestScreen.d.ts +0 -11
  417. package/lib/typescript/components/DataRequestScreen.d.ts.map +0 -1
  418. package/lib/typescript/components/EmailVerificationModal.d.ts +0 -11
  419. package/lib/typescript/components/EmailVerificationModal.d.ts.map +0 -1
  420. package/lib/typescript/components/Onairos.d.ts +0 -4
  421. package/lib/typescript/components/Onairos.d.ts.map +0 -1
  422. package/lib/typescript/components/OnairosButton.d.ts +0 -12
  423. package/lib/typescript/components/OnairosButton.d.ts.map +0 -1
  424. package/lib/typescript/components/Overlay.d.ts +0 -4
  425. package/lib/typescript/components/Overlay.d.ts.map +0 -1
  426. package/lib/typescript/components/PinInput.d.ts +0 -4
  427. package/lib/typescript/components/PinInput.d.ts.map +0 -1
  428. package/lib/typescript/components/PlatformList.d.ts +0 -4
  429. package/lib/typescript/components/PlatformList.d.ts.map +0 -1
  430. package/lib/typescript/components/TrainingModal.d.ts +0 -4
  431. package/lib/typescript/components/TrainingModal.d.ts.map +0 -1
  432. package/lib/typescript/components/UniversalOnboarding.d.ts +0 -4
  433. package/lib/typescript/components/UniversalOnboarding.d.ts.map +0 -1
  434. package/lib/typescript/components/onboarding/OAuthWebView.d.ts +0 -10
  435. package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +0 -1
  436. package/lib/typescript/components/onboarding/OnboardingHeader.d.ts +0 -11
  437. package/lib/typescript/components/onboarding/OnboardingHeader.d.ts.map +0 -1
  438. package/lib/typescript/components/onboarding/PinInput.d.ts +0 -4
  439. package/lib/typescript/components/onboarding/PinInput.d.ts.map +0 -1
  440. package/lib/typescript/components/onboarding/PlatformConnector.d.ts +0 -13
  441. package/lib/typescript/components/onboarding/PlatformConnector.d.ts.map +0 -1
  442. package/lib/typescript/components/screens/ConnectorScreen.d.ts +0 -9
  443. package/lib/typescript/components/screens/ConnectorScreen.d.ts.map +0 -1
  444. package/lib/typescript/components/screens/LoadingScreen.d.ts +0 -9
  445. package/lib/typescript/components/screens/LoadingScreen.d.ts.map +0 -1
  446. package/lib/typescript/components/screens/PinCreationScreen.d.ts +0 -10
  447. package/lib/typescript/components/screens/PinCreationScreen.d.ts.map +0 -1
  448. package/lib/typescript/constants/index.d.ts +0 -53
  449. package/lib/typescript/constants/index.d.ts.map +0 -1
  450. package/lib/typescript/hooks/useConnections.d.ts +0 -9
  451. package/lib/typescript/hooks/useConnections.d.ts.map +0 -1
  452. package/lib/typescript/hooks/useCredentials.d.ts +0 -9
  453. package/lib/typescript/hooks/useCredentials.d.ts.map +0 -1
  454. package/lib/typescript/index.d.ts +0 -18
  455. package/lib/typescript/index.d.ts.map +0 -1
  456. package/lib/typescript/services/apiKeyService.d.ts +0 -132
  457. package/lib/typescript/services/apiKeyService.d.ts.map +0 -1
  458. package/lib/typescript/services/oauthService.d.ts +0 -50
  459. package/lib/typescript/services/oauthService.d.ts.map +0 -1
  460. package/lib/typescript/services/platformAuthService.d.ts +0 -144
  461. package/lib/typescript/services/platformAuthService.d.ts.map +0 -1
  462. package/lib/typescript/types/index.d.ts +0 -231
  463. package/lib/typescript/types/index.d.ts.map +0 -1
  464. package/lib/typescript/types.d.ts +0 -270
  465. package/lib/typescript/types.d.ts.map +0 -1
  466. package/lib/typescript/utils/Portal.d.ts +0 -14
  467. package/lib/typescript/utils/Portal.d.ts.map +0 -1
  468. package/lib/typescript/utils/api.d.ts +0 -6
  469. package/lib/typescript/utils/api.d.ts.map +0 -1
  470. package/lib/typescript/utils/auth.d.ts +0 -6
  471. package/lib/typescript/utils/auth.d.ts.map +0 -1
  472. package/lib/typescript/utils/crypto.d.ts +0 -4
  473. package/lib/typescript/utils/crypto.d.ts.map +0 -1
  474. package/lib/typescript/utils/debugHelper.d.ts +0 -29
  475. package/lib/typescript/utils/debugHelper.d.ts.map +0 -1
  476. package/lib/typescript/utils/encryption.d.ts +0 -19
  477. package/lib/typescript/utils/encryption.d.ts.map +0 -1
  478. package/lib/typescript/utils/onairosApi.d.ts +0 -87
  479. package/lib/typescript/utils/onairosApi.d.ts.map +0 -1
  480. package/lib/typescript/utils/programmaticFlow.d.ts +0 -23
  481. package/lib/typescript/utils/programmaticFlow.d.ts.map +0 -1
  482. package/lib/typescript/utils/retryHelper.d.ts +0 -69
  483. package/lib/typescript/utils/retryHelper.d.ts.map +0 -1
  484. package/lib/typescript/utils/secureStorage.d.ts +0 -94
  485. package/lib/typescript/utils/secureStorage.d.ts.map +0 -1
  486. package/src/api/index.ts +0 -111
  487. package/src/assets/images/email.png +0 -0
  488. package/src/assets/images/linkedin.png +0 -0
  489. package/src/assets/images/onairos_logo.png +0 -0
  490. package/src/assets/images/reddit.png +0 -0
  491. package/src/assets/images/youtube.png +0 -0
  492. package/src/components/DataRequestModal.tsx +0 -227
  493. package/src/components/DataRequestScreen.tsx +0 -356
  494. package/src/components/EmailVerificationModal.tsx +0 -364
  495. package/src/components/Onairos.tsx +0 -425
  496. package/src/components/OnairosButton.tsx +0 -359
  497. package/src/components/Overlay.tsx +0 -506
  498. package/src/components/PinInput.tsx +0 -343
  499. package/src/components/PlatformList.tsx +0 -145
  500. package/src/components/TrainingModal.tsx +0 -737
  501. package/src/components/UniversalOnboarding.tsx +0 -1839
  502. package/src/components/UniversalOnboarding.tsx.new +0 -455
  503. package/src/components/onboarding/OAuthWebView.tsx +0 -838
  504. package/src/components/onboarding/OnboardingHeader.tsx +0 -70
  505. package/src/components/onboarding/PinInput.tsx +0 -356
  506. package/src/components/onboarding/PlatformConnector.tsx +0 -302
  507. package/src/components/screens/ConnectorScreen.tsx +0 -153
  508. package/src/components/screens/LoadingScreen.tsx +0 -100
  509. package/src/components/screens/PinCreationScreen.tsx +0 -67
  510. package/src/constants/index.ts +0 -83
  511. package/src/hooks/useConnections.ts +0 -163
  512. package/src/hooks/useCredentials.ts +0 -175
  513. package/src/index.js +0 -14
  514. package/src/index.ts +0 -50
  515. package/src/services/SDK_API_KEY_VALIDATION.md +0 -421
  516. package/src/services/apiKeyService.ts +0 -984
  517. package/src/services/oauthService.ts +0 -412
  518. package/src/services/platformAuthService.ts +0 -1113
  519. package/src/types/ambient.d.ts +0 -29
  520. package/src/types/declarations.d.ts +0 -26
  521. package/src/types/index.d.ts +0 -274
  522. package/src/types/index.ts +0 -244
  523. package/src/types/node-fix.d.ts +0 -19
  524. package/src/types/node-override.d.ts +0 -24
  525. package/src/types/opacity.d.ts +0 -16
  526. package/src/types/types.d.ts +0 -18
  527. package/src/types.ts +0 -298
  528. package/src/utils/Portal.tsx +0 -83
  529. package/src/utils/api.js +0 -112
  530. package/src/utils/auth.js +0 -104
  531. package/src/utils/crypto.js +0 -60
  532. package/src/utils/debugHelper.ts +0 -53
  533. package/src/utils/encryption.ts +0 -69
  534. package/src/utils/onairosApi.ts +0 -391
  535. package/src/utils/programmaticFlow.ts +0 -113
  536. package/src/utils/retryHelper.ts +0 -275
  537. package/src/utils/secureStorage.ts +0 -361
  538. package/types/index.d.ts +0 -218
  539. package/types/node-env.d.ts +0 -15
  540. /package/{src/assets/images → lib/commonjs/assets/icons}/farcaster.png +0 -0
  541. /package/{src/assets/images → lib/commonjs/assets/icons}/instagram.png +0 -0
  542. /package/{src/assets/images → lib/commonjs/assets/icons}/pinterest.png +0 -0
  543. /package/{src/assets/images → lib/commonjs/assets/icons}/swerv_logo.png +0 -0
  544. /package/{src/assets/images → lib/commonjs/assets/icons}/twitter.jpg +0 -0
@@ -1,984 +0,0 @@
1
- import type { OnairosConfig, ApiKeyValidationResult } from '../types';
2
- import AsyncStorage from '@react-native-async-storage/async-storage';
3
- import NetInfo from '@react-native-community/netinfo';
4
-
5
- // Admin key for backend validation
6
- export const ADMIN_API_KEY = 'OnairosIsAUnicorn2025';
7
-
8
- // API key types
9
- export enum ApiKeyType {
10
- DEVELOPER = 'developer',
11
- ADMIN = 'admin',
12
- INVALID = 'invalid'
13
- }
14
-
15
- // JWT token storage key
16
- const JWT_TOKEN_KEY = 'onairos_jwt_token';
17
-
18
- /**
19
- * Two-Tier Authentication Service for Onairos React Native SDK
20
- *
21
- * This service implements the two-tier authentication system:
22
- * 1. Developer API Keys: For app-level operations (email verification, app registration)
23
- * 2. JWT User Tokens: For user-level operations (PIN storage, user profile)
24
- *
25
- * How it works:
26
- * 1. Initialize with developer API key
27
- * 2. Use API key for email verification requests
28
- * 3. Store JWT token from email verification response
29
- * 4. Use JWT token for user-authenticated requests
30
- * 5. Handle token expiration gracefully
31
- *
32
- * Backend Integration:
33
- * - Developer routes: Authorization: Bearer ${API_KEY}
34
- * - User routes: Authorization: Bearer ${JWT_TOKEN}
35
- */
36
-
37
- // Global configuration state
38
- let globalConfig: OnairosConfig | null = null;
39
- let validationCache: Map<string, { result: ApiKeyValidationResult; timestamp: number }> = new Map();
40
- let isInitialized = false;
41
- let userToken: string | null = null;
42
-
43
- // Cache duration (5 minutes)
44
- const CACHE_DURATION = 5 * 60 * 1000;
45
-
46
- /**
47
- * Check network connectivity
48
- * @returns Promise<boolean> - true if connected, false otherwise
49
- */
50
- const checkNetworkConnectivity = async (): Promise<boolean> => {
51
- try {
52
- const netInfo = await NetInfo.fetch();
53
- return netInfo.isConnected === true && netInfo.isInternetReachable !== false;
54
- } catch (error) {
55
- console.warn('⚠️ Failed to check network connectivity:', error);
56
- // If we can't check connectivity, assume we're connected and let the request fail naturally
57
- return true;
58
- }
59
- };
60
-
61
- // API endpoints for different environments (updated to handle non-existent dev endpoint)
62
- const API_ENDPOINTS = {
63
- production: 'https://api2.onairos.uk',
64
- staging: 'https://api2.onairos.uk', // Fallback to production for staging
65
- development: 'https://api2.onairos.uk', // Fallback to production since dev-api2.onairos.uk doesn't exist
66
- };
67
-
68
- /**
69
- * Initialize the SDK with developer API key
70
- * @param config API configuration including developer API key
71
- */
72
- export const initializeApiKey = async (config: OnairosConfig): Promise<void> => {
73
- try {
74
- console.log('🔑 Initializing Onairos SDK with developer API key...');
75
-
76
- if (!config.apiKey) {
77
- throw new Error('Developer API key is required for SDK initialization');
78
- }
79
-
80
- // Check if it's admin key first (admin key is shorter than 32 chars)
81
- if (!isAdminKey(config.apiKey) && config.apiKey.length < 32) {
82
- throw new Error('Invalid API key format. Developer keys must be at least 32 characters long.');
83
- }
84
-
85
- // Set global configuration
86
- globalConfig = {
87
- apiKey: config.apiKey,
88
- environment: config.environment || 'production',
89
- enableLogging: config.enableLogging !== false, // Default to true
90
- timeout: config.timeout || 30000,
91
- retryAttempts: config.retryAttempts || 3,
92
- };
93
-
94
- if (globalConfig.enableLogging) {
95
- console.log('📝 SDK Configuration:', {
96
- environment: globalConfig.environment,
97
- timeout: globalConfig.timeout,
98
- retryAttempts: globalConfig.retryAttempts,
99
- apiKeyPrefix: config.apiKey.substring(0, 8) + '...',
100
- enableLogging: globalConfig.enableLogging,
101
- });
102
- }
103
-
104
- // Validate the API key (handles both admin and developer keys)
105
- const validation = await validateApiKey(config.apiKey);
106
-
107
- if (!validation.isValid) {
108
- // Use defensive coding to handle cases where validation.error might be undefined
109
- const errorMessage = validation.error || '';
110
-
111
- // Check if it's a network/connectivity issue (either from error message or the flag)
112
- const isNetworkError = validation.isNetworkError ||
113
- errorMessage.includes('Network request failed') ||
114
- errorMessage.includes('Network error') ||
115
- errorMessage.includes('JSON Parse error') ||
116
- errorMessage.includes('API validation endpoint returned') ||
117
- errorMessage.includes('timeout') ||
118
- errorMessage.includes('ENOTFOUND') ||
119
- errorMessage.includes('fetch') ||
120
- errorMessage.includes('No network connection');
121
-
122
- if (isNetworkError) {
123
- console.warn('⚠️ API key validation failed due to network/connectivity issues');
124
- console.warn('🔄 Continuing in offline mode with basic validation');
125
- console.warn('📝 SDK will function with limited validation. Network connectivity will be retried automatically.');
126
- console.warn('🌐 Error details:', validation.error);
127
-
128
- // Continue initialization in offline mode - don't throw error
129
- console.log('📱 SDK initialized in offline mode - will retry validation when network is available');
130
- } else {
131
- // Only throw for actual API key validation errors (not network issues)
132
- throw new Error(`API key validation failed: ${validation.error}`);
133
- }
134
- }
135
-
136
- // Try to load existing JWT token
137
- await loadJWT();
138
-
139
- isInitialized = true;
140
-
141
- if (globalConfig.enableLogging) {
142
- console.log('✅ Onairos SDK initialized successfully');
143
-
144
- if (isAdminKey(config.apiKey)) {
145
- console.log('🔑 Admin API key ready with full permissions');
146
- } else {
147
- console.log('🔑 Developer API key ready for app-level operations');
148
- }
149
-
150
- if (userToken) {
151
- console.log('🎫 User JWT token loaded from storage');
152
- }
153
- if (validation.permissions) {
154
- console.log('🔐 API Key Permissions:', validation.permissions);
155
- }
156
- if (validation.rateLimits) {
157
- console.log('⏱️ Rate Limits:', validation.rateLimits);
158
- }
159
- }
160
- } catch (error) {
161
- console.error('❌ Failed to initialize Onairos SDK:', error);
162
- isInitialized = false;
163
- throw error;
164
- }
165
- };
166
-
167
- /**
168
- * Determine API key type
169
- * @param apiKey The API key to check
170
- * @returns The type of API key
171
- */
172
- export const getApiKeyType = (apiKey: string): ApiKeyType => {
173
- if (apiKey === ADMIN_API_KEY) {
174
- return ApiKeyType.ADMIN;
175
- }
176
-
177
- // Developer keys should be at least 32 characters and start with specific prefix
178
- if (apiKey.length >= 32 && (apiKey.startsWith('dev_') || apiKey.startsWith('pk_') || apiKey.startsWith('ona_'))) {
179
- return ApiKeyType.DEVELOPER;
180
- }
181
-
182
- return ApiKeyType.INVALID;
183
- };
184
-
185
- /**
186
- * Check if API key is admin key
187
- * @param apiKey The API key to check
188
- * @returns True if admin key
189
- */
190
- export const isAdminKey = (apiKey: string): boolean => {
191
- return apiKey === ADMIN_API_KEY;
192
- };
193
-
194
- /**
195
- * Validate an API key with the Onairos backend
196
- * @param apiKey The API key to validate
197
- * @returns Validation result with permissions and rate limits
198
- */
199
- export const validateApiKey = async (apiKey: string): Promise<ApiKeyValidationResult> => {
200
- try {
201
- console.log('🔍 Validating API key...');
202
-
203
- // Check if it's an admin key
204
- if (isAdminKey(apiKey)) {
205
- console.log('🔑 Admin key detected - granting full permissions');
206
- return {
207
- isValid: true,
208
- permissions: ['*'], // Full permissions for admin
209
- rateLimits: {
210
- remaining: 999999,
211
- resetTime: Date.now() + 24 * 60 * 60 * 1000 // 24 hours
212
- },
213
- keyType: ApiKeyType.ADMIN
214
- };
215
- }
216
-
217
- // Check basic format for developer keys
218
- const keyType = getApiKeyType(apiKey);
219
- if (keyType === ApiKeyType.INVALID) {
220
- return {
221
- isValid: false,
222
- error: 'Invalid API key format. Developer keys must be at least 32 characters and start with "dev_", "pk_", or "ona_"',
223
- keyType: ApiKeyType.INVALID
224
- };
225
- }
226
-
227
- // Check cache first
228
- const cached = validationCache.get(apiKey);
229
- if (cached && Date.now() - cached.timestamp < CACHE_DURATION) {
230
- if (globalConfig?.enableLogging) {
231
- console.log('📋 Using cached API key validation result');
232
- }
233
- return cached.result;
234
- }
235
-
236
- // Check network connectivity before making API calls
237
- const isConnected = await checkNetworkConnectivity();
238
- if (!isConnected) {
239
- console.warn('⚠️ No network connectivity detected');
240
- return {
241
- isValid: false,
242
- error: 'No network connection available. Please check your internet connection and try again.',
243
- keyType: keyType,
244
- isNetworkError: true
245
- };
246
- }
247
-
248
- const environment = globalConfig?.environment || 'production';
249
- const baseUrl = API_ENDPOINTS[environment];
250
- const timeout = globalConfig?.timeout || 30000;
251
- const maxRetries = globalConfig?.retryAttempts || 3;
252
-
253
- // Retry logic for network failures
254
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
255
- // Create abort controller for timeout
256
- const controller = new AbortController();
257
- const timeoutId = setTimeout(() => controller.abort(), timeout);
258
-
259
- try {
260
- if (globalConfig?.enableLogging && attempt > 1) {
261
- console.log(`🔄 Retry attempt ${attempt}/${maxRetries} for API key validation`);
262
- }
263
-
264
- const response = await fetch(`${baseUrl}/dev/validate`, {
265
- method: 'POST',
266
- headers: {
267
- 'Content-Type': 'application/json',
268
- 'Authorization': `Bearer ${apiKey}`,
269
- 'User-Agent': 'OnairosReactNative/3.3.1',
270
- 'X-API-Key-Type': keyType,
271
- 'X-SDK-Platform': 'react-native',
272
- 'X-Retry-Attempt': attempt.toString(),
273
- },
274
- body: JSON.stringify({
275
- environment,
276
- sdk_version: '3.3.1',
277
- platform: 'react-native',
278
- keyType,
279
- timestamp: new Date().toISOString(),
280
- attempt,
281
- }),
282
- signal: controller.signal,
283
- });
284
-
285
- clearTimeout(timeoutId);
286
-
287
- // First check if we got a valid response
288
- if (!response) {
289
- throw new Error('No response received from server');
290
- }
291
-
292
- // Handle common HTTP errors that indicate server issues
293
- if (response.status === 502) {
294
- throw new Error('Onairos API is temporarily unavailable (502 Bad Gateway). Please try again later.');
295
- }
296
-
297
- if (response.status === 503) {
298
- throw new Error('Onairos API is under maintenance (503 Service Unavailable). Please try again later.');
299
- }
300
-
301
- if (response.status === 504) {
302
- throw new Error('Onairos API request timed out (504 Gateway Timeout). Please try again.');
303
- }
304
-
305
- // Check if response is actually JSON before trying to parse
306
- const contentType = response.headers.get('content-type');
307
- const isJsonResponse = contentType && contentType.includes('application/json');
308
-
309
- if (!isJsonResponse) {
310
- const textContent = await response.text();
311
- const previewText = textContent.substring(0, 200);
312
-
313
- console.error('❌ API endpoint returned non-JSON response:', {
314
- status: response.status,
315
- statusText: response.statusText,
316
- contentType: contentType || 'unknown',
317
- preview: previewText,
318
- url: `${baseUrl}/dev/validate`,
319
- attempt: attempt
320
- });
321
-
322
- // Handle specific error cases
323
- if (response.status === 404) {
324
- throw new Error(`API validation endpoint not found (404). The endpoint ${baseUrl}/dev/validate may not exist or be configured correctly.`);
325
- } else if (response.status === 500) {
326
- throw new Error(`Server error (500). The Onairos backend is experiencing issues.`);
327
- } else if (response.status === 502 || response.status === 503) {
328
- throw new Error(`Service unavailable (${response.status}). The Onairos backend may be temporarily down.`);
329
- } else if (textContent.includes('<html') || textContent.includes('<!DOCTYPE')) {
330
- throw new Error(`Server returned HTML page instead of JSON API response. This often indicates a routing issue or server misconfiguration.`);
331
- } else {
332
- throw new Error(`API validation endpoint returned ${response.status} - ${response.statusText}. Expected JSON but got ${contentType || 'unknown content type'}.`);
333
- }
334
- }
335
-
336
- // Parse JSON response
337
- let data;
338
- try {
339
- data = await response.json();
340
- } catch (jsonError) {
341
- console.error('❌ Failed to parse JSON response:', {
342
- error: jsonError.message,
343
- status: response.status,
344
- contentType,
345
- attempt: attempt
346
- });
347
- throw new Error(`Failed to parse server response as JSON: ${jsonError.message}`);
348
- }
349
-
350
- // Handle successful response
351
- // Backend returns either {success: true} or {valid: true}
352
- if (response.ok && (data.success || data.valid)) {
353
- const result: ApiKeyValidationResult = {
354
- isValid: true,
355
- permissions: data.permissions || [],
356
- rateLimits: data.rateLimits || null,
357
- keyType: keyType,
358
- };
359
-
360
- // Cache the successful result
361
- validationCache.set(apiKey, {
362
- result,
363
- timestamp: Date.now(),
364
- });
365
-
366
- if (globalConfig?.enableLogging) {
367
- console.log('✅ API key validation successful', {
368
- apiKeyId: data.apiKey?.id,
369
- appName: data.application?.name,
370
- usageCount: data.apiKey?.usageCount
371
- });
372
- }
373
-
374
- return result;
375
- } else {
376
- // Handle API errors (invalid key, etc.)
377
- const errorMessage = data.error || data.message || `HTTP ${response.status}: ${response.statusText}`;
378
-
379
- const result: ApiKeyValidationResult = {
380
- isValid: false,
381
- error: errorMessage,
382
- keyType: keyType,
383
- };
384
-
385
- // For client errors (4xx), don't retry
386
- if (response.status >= 400 && response.status < 500) {
387
- if (globalConfig?.enableLogging) {
388
- console.error('❌ API key validation failed (client error):', errorMessage);
389
- }
390
- return result;
391
- }
392
-
393
- // For server errors (5xx), retry
394
- throw new Error(errorMessage);
395
- }
396
-
397
- } catch (fetchError: any) {
398
- clearTimeout(timeoutId);
399
-
400
- if (fetchError.name === 'AbortError') {
401
- const errorMessage = `API key validation timeout (${timeout}ms)`;
402
- console.error('⏱️ API key validation timeout');
403
-
404
- if (attempt === maxRetries) {
405
- return { isValid: false, error: errorMessage, keyType: keyType };
406
- }
407
- continue; // Retry timeout errors
408
- }
409
-
410
- // Enhanced error message based on error type
411
- let errorMessage = `Network error during API key validation: ${fetchError.message}`;
412
-
413
- // Add specific guidance for common errors
414
- if (fetchError.message.includes('JSON Parse error') || fetchError.message.includes('Unexpected character')) {
415
- errorMessage = `Server returned invalid JSON response. This usually indicates the API endpoint returned HTML instead of JSON (often a 404 or server error page). ${fetchError.message}`;
416
- } else if (fetchError.message.includes('Network request failed') || fetchError.message.includes('fetch')) {
417
- errorMessage = `Network connectivity issue. Please check internet connection and verify the Onairos API is accessible. ${fetchError.message}`;
418
- } else if (fetchError.message.includes('DNS') || fetchError.message.includes('ENOTFOUND')) {
419
- errorMessage = `DNS resolution failed for ${baseUrl}. Please check network settings and domain accessibility. ${fetchError.message}`;
420
- }
421
-
422
- console.error('🌐 Network error during API key validation:', {
423
- error: fetchError,
424
- endpoint: `${baseUrl}/dev/validate`,
425
- attempt: attempt,
426
- maxRetries: maxRetries,
427
- retryable: attempt < maxRetries
428
- });
429
-
430
- // If this is the last attempt, return the error
431
- if (attempt === maxRetries) {
432
- return {
433
- isValid: false,
434
- error: errorMessage,
435
- keyType: keyType,
436
- isNetworkError: true // Flag to indicate this is a network issue, not an API key issue
437
- };
438
- }
439
-
440
- // Wait before retrying (exponential backoff)
441
- const backoffDelay = Math.min(1000 * Math.pow(2, attempt - 1), 5000);
442
- if (globalConfig?.enableLogging) {
443
- console.log(`⏳ Waiting ${backoffDelay}ms before retry...`);
444
- }
445
- await new Promise<void>(resolve => setTimeout(() => resolve(), backoffDelay));
446
- }
447
- }
448
-
449
- // This should never be reached, but just in case
450
- return {
451
- isValid: false,
452
- error: 'All retry attempts exhausted',
453
- keyType: keyType
454
- };
455
-
456
- } catch (error: any) {
457
- const errorMessage = `API key validation error: ${error.message}`;
458
- console.error('❌ API key validation error:', error);
459
- return { isValid: false, error: errorMessage, keyType: ApiKeyType.INVALID };
460
- }
461
- };
462
-
463
- /**
464
- * Get the current API configuration
465
- * @returns Current API configuration or null if not initialized
466
- */
467
- export const getApiConfig = (): OnairosConfig | null => {
468
- return globalConfig;
469
- };
470
-
471
- /**
472
- * Get the current API key
473
- * @returns Current API key or null if not initialized
474
- */
475
- export const getApiKey = (): string | null => {
476
- return globalConfig?.apiKey || null;
477
- };
478
-
479
- /**
480
- * Check if the SDK is properly initialized
481
- * @returns True if initialized with valid API key
482
- */
483
- export const isApiKeyInitialized = (): boolean => {
484
- return isInitialized && globalConfig !== null;
485
- };
486
-
487
- /**
488
- * Store JWT token securely after email verification
489
- * @param token JWT token from email verification response
490
- */
491
- export const storeJWT = async (token: string): Promise<void> => {
492
- try {
493
- await AsyncStorage.setItem(JWT_TOKEN_KEY, token);
494
- userToken = token;
495
-
496
- if (globalConfig?.enableLogging) {
497
- console.log('🎫 JWT token stored successfully');
498
- }
499
- } catch (error) {
500
- console.error('❌ Failed to store JWT token:', error);
501
- throw error;
502
- }
503
- };
504
-
505
- /**
506
- * Load JWT token from storage
507
- * @returns JWT token or null if not found
508
- */
509
- export const loadJWT = async (): Promise<string | null> => {
510
- try {
511
- const token = await AsyncStorage.getItem(JWT_TOKEN_KEY);
512
- userToken = token;
513
- return token;
514
- } catch (error) {
515
- console.error('❌ Failed to load JWT token:', error);
516
- return null;
517
- }
518
- };
519
-
520
- /**
521
- * Get current JWT token
522
- * @returns JWT token or null if not available
523
- */
524
- export const getJWT = (): string | null => {
525
- return userToken;
526
- };
527
-
528
- /**
529
- * Clear JWT token (on logout or token expiration)
530
- */
531
- export const clearJWT = async (): Promise<void> => {
532
- try {
533
- await AsyncStorage.removeItem(JWT_TOKEN_KEY);
534
- userToken = null;
535
-
536
- if (globalConfig?.enableLogging) {
537
- console.log('🗑️ JWT token cleared');
538
- }
539
- } catch (error) {
540
- console.error('❌ Failed to clear JWT token:', error);
541
- }
542
- };
543
-
544
- /**
545
- * React Native compatible base64 decoder
546
- * @param str Base64 encoded string
547
- * @returns Decoded string
548
- */
549
- const base64Decode = (str: string): string => {
550
- // Simple base64 decoding for React Native
551
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
552
- let result = '';
553
- let i = 0;
554
-
555
- str = str.replace(/[^A-Za-z0-9+/]/g, '');
556
-
557
- while (i < str.length) {
558
- const a = chars.indexOf(str.charAt(i++));
559
- const b = chars.indexOf(str.charAt(i++));
560
- const c = chars.indexOf(str.charAt(i++));
561
- const d = chars.indexOf(str.charAt(i++));
562
-
563
- const bitmap = (a << 18) | (b << 12) | (c << 6) | d;
564
-
565
- result += String.fromCharCode((bitmap >> 16) & 255);
566
- if (c !== 64) result += String.fromCharCode((bitmap >> 8) & 255);
567
- if (d !== 64) result += String.fromCharCode(bitmap & 255);
568
- }
569
-
570
- return result;
571
- };
572
-
573
- /**
574
- * Decode JWT token payload (React Native compatible)
575
- * @param token JWT token string
576
- * @returns Decoded payload or null if invalid
577
- */
578
- export const decodeJWTPayload = (token: string): any => {
579
- try {
580
- // Split JWT token (header.payload.signature)
581
- const parts = token.split('.');
582
- if (parts.length !== 3) {
583
- console.error('❌ Invalid JWT token format');
584
- return null;
585
- }
586
-
587
- // Decode payload (base64url to base64)
588
- const payload = parts[1];
589
- const base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
590
-
591
- // Add padding if needed
592
- const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, '=');
593
-
594
- // Decode base64 to JSON using React Native compatible decoder
595
- const decoded = base64Decode(padded);
596
- return JSON.parse(decoded);
597
- } catch (error) {
598
- console.error('❌ Failed to decode JWT token:', error);
599
- return null;
600
- }
601
- };
602
-
603
- /**
604
- * Extract username from JWT token
605
- * @param token JWT token (optional, uses stored token if not provided)
606
- * @returns Username or null if not found
607
- */
608
- export const extractUsernameFromJWT = (token?: string): string | null => {
609
- try {
610
- const jwtToken = token || userToken;
611
- if (!jwtToken) {
612
- console.warn('⚠️ No JWT token available for username extraction');
613
- return null;
614
- }
615
-
616
- const payload = decodeJWTPayload(jwtToken);
617
- if (!payload) {
618
- return null;
619
- }
620
-
621
- // Try different possible username fields in order of preference
622
- const username = payload.userName || payload.username || payload.userId || payload.email;
623
-
624
- if (globalConfig?.enableLogging) {
625
- console.log('👤 Extracted username from JWT:', username);
626
- }
627
-
628
- return username || null;
629
- } catch (error) {
630
- console.error('❌ Failed to extract username from JWT:', error);
631
- return null;
632
- }
633
- };
634
-
635
- /**
636
- * Extract user data from JWT token
637
- * @param token JWT token (optional, uses stored token if not provided)
638
- * @returns User data object or null if not found
639
- */
640
- export const extractUserDataFromJWT = (token?: string): any => {
641
- try {
642
- const jwtToken = token || userToken;
643
- if (!jwtToken) {
644
- console.warn('⚠️ No JWT token available for user data extraction');
645
- return null;
646
- }
647
-
648
- const payload = decodeJWTPayload(jwtToken);
649
- if (!payload) {
650
- return null;
651
- }
652
-
653
- const userData = {
654
- id: payload.id,
655
- email: payload.email,
656
- userId: payload.userId,
657
- userName: payload.userName || payload.username,
658
- verified: payload.verified,
659
- iat: payload.iat,
660
- exp: payload.exp
661
- };
662
-
663
- if (globalConfig?.enableLogging) {
664
- console.log('👤 Extracted user data from JWT:', userData);
665
- }
666
-
667
- return userData;
668
- } catch (error) {
669
- console.error('❌ Failed to extract user data from JWT:', error);
670
- return null;
671
- }
672
- };
673
-
674
- /**
675
- * Check if user is authenticated with JWT token
676
- * @returns True if user has valid JWT token
677
- */
678
- export const isUserAuthenticated = (): boolean => {
679
- return !!userToken;
680
- };
681
-
682
- /**
683
- * Get authenticated headers for API requests
684
- * @returns Headers object with Authorization and other required headers
685
- */
686
- export const getAuthHeaders = (): Record<string, string> => {
687
- if (!globalConfig?.apiKey) {
688
- throw new Error('SDK not initialized. Call initializeApiKey() first.');
689
- }
690
-
691
- const keyType = getApiKeyType(globalConfig.apiKey);
692
-
693
- return {
694
- 'Content-Type': 'application/json',
695
- 'Authorization': `Bearer ${globalConfig.apiKey}`,
696
- 'User-Agent': 'OnairosReactNative/3.0.72',
697
- 'X-SDK-Version': '3.0.72',
698
- 'X-SDK-Environment': globalConfig.environment || 'production',
699
- 'X-API-Key-Type': keyType,
700
- 'X-Timestamp': new Date().toISOString(),
701
- };
702
- };
703
-
704
- /**
705
- * Get authentication headers for developer API requests
706
- * @returns Headers with developer API key
707
- */
708
- export const getDeveloperAuthHeaders = (): Record<string, string> => {
709
- if (!globalConfig?.apiKey) {
710
- throw new Error('SDK not initialized. Call initializeApiKey() first.');
711
- }
712
-
713
- const keyType = getApiKeyType(globalConfig.apiKey);
714
-
715
- return {
716
- 'Content-Type': 'application/json',
717
- 'Authorization': `Bearer ${globalConfig.apiKey}`,
718
- 'User-Agent': 'OnairosSDK/1.0.0',
719
- 'X-SDK-Version': '3.0.72',
720
- 'X-SDK-Environment': globalConfig.environment || 'production',
721
- 'X-API-Key-Type': keyType,
722
- 'X-Timestamp': new Date().toISOString(),
723
- };
724
- };
725
-
726
- /**
727
- * Get authentication headers for user JWT requests
728
- * @returns Headers with user JWT token
729
- */
730
- export const getUserAuthHeaders = (): Record<string, string> => {
731
- if (!userToken) {
732
- throw new Error('User not authenticated. Please verify email first.');
733
- }
734
-
735
- return {
736
- 'Content-Type': 'application/json',
737
- 'Authorization': `Bearer ${userToken}`,
738
- 'User-Agent': 'OnairosSDK/1.0.0',
739
- 'X-SDK-Version': '3.0.72',
740
- 'X-SDK-Environment': globalConfig?.environment || 'production',
741
- };
742
- };
743
-
744
- /**
745
- * Make an authenticated API request
746
- * @param endpoint The API endpoint (relative to base URL)
747
- * @param options Fetch options
748
- * @returns Response promise
749
- */
750
- export const makeAuthenticatedRequest = async (
751
- endpoint: string,
752
- options: RequestInit = {}
753
- ): Promise<Response> => {
754
- if (!isApiKeyInitialized()) {
755
- throw new Error('SDK not initialized. Call initializeApiKey() first.');
756
- }
757
-
758
- const config = getApiConfig()!;
759
- const baseUrl = API_ENDPOINTS[config.environment || 'production'];
760
- const url = `${baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`;
761
-
762
- // Merge authentication headers
763
- const headers = {
764
- ...getAuthHeaders(),
765
- ...(options.headers || {}),
766
- };
767
-
768
- // Add timeout
769
- const controller = new AbortController();
770
- const timeoutId = setTimeout(() => controller.abort(), config.timeout || 30000);
771
-
772
- try {
773
- if (config.enableLogging) {
774
- console.log(`🌐 Making authenticated request to: ${endpoint}`);
775
- }
776
-
777
- const response = await fetch(url, {
778
- ...options,
779
- headers,
780
- signal: controller.signal,
781
- });
782
-
783
- clearTimeout(timeoutId);
784
-
785
- if (config.enableLogging) {
786
- console.log(`📡 Response status: ${response.status} for ${endpoint}`);
787
- }
788
-
789
- // Handle API key errors
790
- if (response.status === 401) {
791
- console.error('❌ API key authentication failed. Please check your API key.');
792
- throw new Error('Invalid or expired API key');
793
- }
794
-
795
- if (response.status === 403) {
796
- console.error('❌ API key permissions insufficient for this operation.');
797
- throw new Error('Insufficient API key permissions');
798
- }
799
-
800
- if (response.status === 429) {
801
- console.error('❌ API rate limit exceeded. Please try again later.');
802
- throw new Error('Rate limit exceeded');
803
- }
804
-
805
- return response;
806
- } catch (error) {
807
- clearTimeout(timeoutId);
808
-
809
- if (error.name === 'AbortError') {
810
- console.error('⏱️ Request timeout for:', endpoint);
811
- throw new Error('Request timeout');
812
- }
813
-
814
- throw error;
815
- }
816
- };
817
-
818
- /**
819
- * Make authenticated request with developer API key
820
- * @param endpoint The API endpoint
821
- * @param options Fetch options
822
- * @returns Response promise
823
- */
824
- export const makeDeveloperRequest = async (
825
- endpoint: string,
826
- options: RequestInit = {}
827
- ): Promise<Response> => {
828
- if (!isApiKeyInitialized()) {
829
- throw new Error('SDK not initialized. Call initializeApiKey() first.');
830
- }
831
-
832
- const config = getApiConfig()!;
833
- const baseUrl = API_ENDPOINTS[config.environment || 'production'];
834
- const url = `${baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`;
835
-
836
- // Merge developer authentication headers
837
- const headers = {
838
- ...getDeveloperAuthHeaders(),
839
- ...(options.headers || {}),
840
- };
841
-
842
- // Add timeout
843
- const controller = new AbortController();
844
- const timeoutId = setTimeout(() => controller.abort(), config.timeout || 30000);
845
-
846
- try {
847
- if (config.enableLogging) {
848
- console.log(`🌐 Making developer request to: ${endpoint}`);
849
- }
850
-
851
- const response = await fetch(url, {
852
- ...options,
853
- headers,
854
- signal: controller.signal,
855
- });
856
-
857
- clearTimeout(timeoutId);
858
-
859
- if (config.enableLogging) {
860
- console.log(`📡 Developer request response: ${response.status} for ${endpoint}`);
861
- }
862
-
863
- // Handle API key errors
864
- if (response.status === 401) {
865
- console.error('❌ Developer API key authentication failed');
866
- throw new Error('Invalid or expired API key');
867
- }
868
-
869
- if (response.status === 403) {
870
- console.error('❌ Developer API key permissions insufficient');
871
- throw new Error('Insufficient API key permissions');
872
- }
873
-
874
- if (response.status === 429) {
875
- console.error('❌ API rate limit exceeded');
876
- throw new Error('Rate limit exceeded');
877
- }
878
-
879
- return response;
880
- } catch (error) {
881
- clearTimeout(timeoutId);
882
-
883
- if (error.name === 'AbortError') {
884
- console.error('⏱️ Request timeout for:', endpoint);
885
- throw new Error('Request timeout');
886
- }
887
-
888
- throw error;
889
- }
890
- };
891
-
892
- /**
893
- * Make authenticated request with user JWT token
894
- * @param endpoint The API endpoint
895
- * @param options Fetch options
896
- * @returns Response promise
897
- */
898
- export const makeUserRequest = async (
899
- endpoint: string,
900
- options: RequestInit = {}
901
- ): Promise<Response> => {
902
- if (!isUserAuthenticated()) {
903
- await loadJWT(); // Try to load from storage
904
- }
905
-
906
- if (!isUserAuthenticated()) {
907
- throw new Error('User not authenticated. Please verify email first.');
908
- }
909
-
910
- const config = getApiConfig() || { environment: 'production', timeout: 30000, enableLogging: false };
911
- const baseUrl = API_ENDPOINTS[config.environment || 'production'];
912
- const url = `${baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`;
913
-
914
- // Merge user authentication headers
915
- const headers = {
916
- ...getUserAuthHeaders(),
917
- ...(options.headers || {}),
918
- };
919
-
920
- // Add timeout
921
- const controller = new AbortController();
922
- const timeoutId = setTimeout(() => controller.abort(), config.timeout || 30000);
923
-
924
- try {
925
- if (config.enableLogging) {
926
- console.log(`🌐 Making user request to: ${endpoint}`);
927
- }
928
-
929
- const response = await fetch(url, {
930
- ...options,
931
- headers,
932
- signal: controller.signal,
933
- });
934
-
935
- clearTimeout(timeoutId);
936
-
937
- if (config.enableLogging) {
938
- console.log(`📡 User request response: ${response.status} for ${endpoint}`);
939
- }
940
-
941
- // Handle JWT token errors
942
- if (response.status === 401) {
943
- console.error('❌ JWT token authentication failed - token may be expired');
944
- await clearJWT(); // Clear expired token
945
- throw new Error('Authentication expired. Please verify email again.');
946
- }
947
-
948
- if (response.status === 403) {
949
- console.error('❌ JWT token permissions insufficient');
950
- throw new Error('Insufficient permissions for this operation');
951
- }
952
-
953
- return response;
954
- } catch (error) {
955
- clearTimeout(timeoutId);
956
-
957
- if (error.name === 'AbortError') {
958
- console.error('⏱️ Request timeout for:', endpoint);
959
- throw new Error('Request timeout');
960
- }
961
-
962
- throw error;
963
- }
964
- };
965
-
966
- /**
967
- * Clear the API key validation cache
968
- */
969
- export const clearValidationCache = (): void => {
970
- validationCache.clear();
971
- if (globalConfig?.enableLogging) {
972
- console.log('🗑️ API key validation cache cleared');
973
- }
974
- };
975
-
976
- /**
977
- * Reset the SDK initialization state
978
- */
979
- export const resetApiKeyService = (): void => {
980
- globalConfig = null;
981
- isInitialized = false;
982
- clearValidationCache();
983
- console.log('🔄 API key service reset');
984
- };