@onairos/react-native 3.1.17 → 3.2.0

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