@oxyhq/services 5.24.0 → 5.26.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 (444) hide show
  1. package/README.md +60 -8
  2. package/lib/commonjs/core/AuthManager.js +405 -0
  3. package/lib/commonjs/core/AuthManager.js.map +1 -0
  4. package/lib/commonjs/core/HttpService.js +39 -1
  5. package/lib/commonjs/core/HttpService.js.map +1 -1
  6. package/lib/commonjs/core/index.js +16 -0
  7. package/lib/commonjs/core/index.js.map +1 -1
  8. package/lib/commonjs/core/mixins/OxyServices.fedcm.js +38 -44
  9. package/lib/commonjs/core/mixins/OxyServices.fedcm.js.map +1 -1
  10. package/lib/commonjs/core/mixins/OxyServices.popup.js +9 -7
  11. package/lib/commonjs/core/mixins/OxyServices.popup.js.map +1 -1
  12. package/lib/commonjs/index.js +321 -18
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/shared/index.js +227 -0
  15. package/lib/commonjs/shared/index.js.map +1 -0
  16. package/lib/commonjs/shared/utils/colorUtils.js +161 -0
  17. package/lib/commonjs/shared/utils/colorUtils.js.map +1 -0
  18. package/lib/commonjs/shared/utils/debugUtils.js +84 -0
  19. package/lib/commonjs/shared/utils/debugUtils.js.map +1 -0
  20. package/lib/commonjs/shared/utils/errorUtils.js +190 -0
  21. package/lib/commonjs/shared/utils/errorUtils.js.map +1 -0
  22. package/lib/commonjs/shared/utils/index.js +196 -0
  23. package/lib/commonjs/shared/utils/index.js.map +1 -0
  24. package/lib/commonjs/shared/utils/networkUtils.js +213 -0
  25. package/lib/commonjs/shared/utils/networkUtils.js.map +1 -0
  26. package/lib/commonjs/shared/utils/themeUtils.js +118 -0
  27. package/lib/commonjs/shared/utils/themeUtils.js.map +1 -0
  28. package/lib/commonjs/ui/components/BottomSheetRouter.js +1 -1
  29. package/lib/commonjs/ui/components/FontLoader.js +1 -1
  30. package/lib/commonjs/ui/components/FontLoader.js.map +1 -1
  31. package/lib/commonjs/ui/components/GroupedItem.js +1 -1
  32. package/lib/commonjs/ui/components/Header.js +1 -1
  33. package/lib/commonjs/ui/components/OxyProvider.js +9 -1
  34. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  35. package/lib/commonjs/ui/components/OxySignInButton.js +19 -20
  36. package/lib/commonjs/ui/components/OxySignInButton.js.map +1 -1
  37. package/lib/commonjs/ui/components/ProfileCard.js +1 -1
  38. package/lib/commonjs/ui/components/ProfileCard.js.map +1 -1
  39. package/lib/commonjs/ui/components/QuickActions.js +1 -1
  40. package/lib/commonjs/ui/components/QuickActions.js.map +1 -1
  41. package/lib/commonjs/ui/components/Section.js +1 -1
  42. package/lib/commonjs/ui/components/SectionTitle.js +1 -1
  43. package/lib/commonjs/ui/components/SignInModal.js +546 -0
  44. package/lib/commonjs/ui/components/SignInModal.js.map +1 -0
  45. package/lib/commonjs/ui/context/OxyContext.js +2 -1
  46. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  47. package/lib/commonjs/ui/hooks/{use-color-scheme.js → useColorScheme.js} +1 -1
  48. package/lib/commonjs/ui/hooks/useColorScheme.js.map +1 -0
  49. package/lib/commonjs/ui/hooks/useSessionSocket.js +6 -12
  50. package/lib/commonjs/ui/hooks/useSessionSocket.js.map +1 -1
  51. package/lib/commonjs/ui/hooks/useThemeColors.js +1 -1
  52. package/lib/commonjs/ui/hooks/useThemeStyles.js +1 -1
  53. package/lib/commonjs/ui/navigation/bottomSheetManager.js +5 -2
  54. package/lib/commonjs/ui/navigation/bottomSheetManager.js.map +1 -1
  55. package/lib/commonjs/ui/navigation/routes.js +7 -8
  56. package/lib/commonjs/ui/navigation/routes.js.map +1 -1
  57. package/lib/commonjs/ui/screens/AccountCenterScreen.js +7 -7
  58. package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
  59. package/lib/commonjs/ui/screens/AccountOverviewScreen.js +6 -6
  60. package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -1
  61. package/lib/commonjs/ui/screens/AccountSettingsScreen.js +2 -2
  62. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +4 -4
  63. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
  64. package/lib/commonjs/ui/screens/AppInfoScreen.js +1 -1
  65. package/lib/commonjs/ui/screens/EditProfileFieldScreen.js +1 -1
  66. package/lib/commonjs/ui/screens/FileManagementScreen.js +1 -1
  67. package/lib/commonjs/ui/screens/FollowersListScreen.js +18 -0
  68. package/lib/commonjs/ui/screens/FollowersListScreen.js.map +1 -0
  69. package/lib/commonjs/ui/screens/FollowingListScreen.js +18 -0
  70. package/lib/commonjs/ui/screens/FollowingListScreen.js.map +1 -0
  71. package/lib/commonjs/ui/screens/HelpSupportScreen.js +1 -1
  72. package/lib/commonjs/ui/screens/HelpSupportScreen.js.map +1 -1
  73. package/lib/commonjs/ui/screens/HistoryViewScreen.js +1 -1
  74. package/lib/commonjs/ui/screens/LanguageSelectorScreen.js +1 -1
  75. package/lib/commonjs/ui/screens/LearnMoreUsernamesScreen.js +229 -0
  76. package/lib/commonjs/ui/screens/LearnMoreUsernamesScreen.js.map +1 -0
  77. package/lib/commonjs/ui/screens/LegalDocumentsScreen.js +1 -1
  78. package/lib/commonjs/ui/screens/LegalDocumentsScreen.js.map +1 -1
  79. package/lib/commonjs/ui/screens/OxyAuthScreen.js +9 -21
  80. package/lib/commonjs/ui/screens/OxyAuthScreen.js.map +1 -1
  81. package/lib/commonjs/ui/screens/PremiumSubscriptionScreen.js +1 -1
  82. package/lib/commonjs/ui/screens/ProfileScreen.js +1 -1
  83. package/lib/commonjs/ui/screens/ProfileScreen.js.map +1 -1
  84. package/lib/commonjs/ui/screens/SavesCollectionsScreen.js +1 -1
  85. package/lib/commonjs/ui/screens/UserListScreen.js +411 -0
  86. package/lib/commonjs/ui/screens/UserListScreen.js.map +1 -0
  87. package/lib/commonjs/ui/screens/karma/KarmaAboutScreen.js +1 -1
  88. package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js +1 -1
  89. package/lib/commonjs/ui/screens/karma/KarmaFAQScreen.js +1 -1
  90. package/lib/commonjs/ui/screens/karma/KarmaLeaderboardScreen.js +1 -1
  91. package/lib/commonjs/ui/screens/karma/KarmaRewardsScreen.js +1 -1
  92. package/lib/commonjs/ui/screens/karma/KarmaRulesScreen.js +1 -1
  93. package/lib/commonjs/ui/stores/authStore.js +4 -6
  94. package/lib/commonjs/ui/stores/authStore.js.map +1 -1
  95. package/lib/commonjs/ui/utils/colorUtils.js +43 -46
  96. package/lib/commonjs/ui/utils/colorUtils.js.map +1 -1
  97. package/lib/commonjs/ui/utils/themeUtils.js +29 -39
  98. package/lib/commonjs/ui/utils/themeUtils.js.map +1 -1
  99. package/lib/commonjs/ui/utils/{user-utils.js → userUtils.js} +1 -1
  100. package/lib/commonjs/ui/utils/userUtils.js.map +1 -0
  101. package/lib/commonjs/utils/errorUtils.js +0 -13
  102. package/lib/commonjs/utils/errorUtils.js.map +1 -1
  103. package/lib/commonjs/utils/hookUtils.js +8 -8
  104. package/lib/commonjs/utils/hookUtils.js.map +1 -1
  105. package/lib/commonjs/web/WebOxyContext.js +277 -72
  106. package/lib/commonjs/web/WebOxyContext.js.map +1 -1
  107. package/lib/commonjs/web/index.js +177 -4
  108. package/lib/commonjs/web/index.js.map +1 -1
  109. package/lib/commonjs/web.js +12 -12
  110. package/lib/commonjs/web.js.map +1 -1
  111. package/lib/module/core/AuthManager.js +399 -0
  112. package/lib/module/core/AuthManager.js.map +1 -0
  113. package/lib/module/core/HttpService.js +39 -1
  114. package/lib/module/core/HttpService.js.map +1 -1
  115. package/lib/module/core/index.js +2 -0
  116. package/lib/module/core/index.js.map +1 -1
  117. package/lib/module/core/mixins/OxyServices.fedcm.js +38 -44
  118. package/lib/module/core/mixins/OxyServices.fedcm.js.map +1 -1
  119. package/lib/module/core/mixins/OxyServices.popup.js +9 -7
  120. package/lib/module/core/mixins/OxyServices.popup.js.map +1 -1
  121. package/lib/module/index.js +27 -2
  122. package/lib/module/index.js.map +1 -1
  123. package/lib/module/shared/index.js +37 -0
  124. package/lib/module/shared/index.js.map +1 -0
  125. package/lib/module/shared/utils/colorUtils.js +150 -0
  126. package/lib/module/shared/utils/colorUtils.js.map +1 -0
  127. package/lib/module/shared/utils/debugUtils.js +75 -0
  128. package/lib/module/shared/utils/debugUtils.js.map +1 -0
  129. package/lib/module/shared/utils/errorUtils.js +176 -0
  130. package/lib/module/shared/utils/errorUtils.js.map +1 -0
  131. package/lib/module/shared/utils/index.js +21 -0
  132. package/lib/module/shared/utils/index.js.map +1 -0
  133. package/lib/module/shared/utils/networkUtils.js +202 -0
  134. package/lib/module/shared/utils/networkUtils.js.map +1 -0
  135. package/lib/module/shared/utils/themeUtils.js +109 -0
  136. package/lib/module/shared/utils/themeUtils.js.map +1 -0
  137. package/lib/module/ui/components/BottomSheetRouter.js +1 -1
  138. package/lib/module/ui/components/BottomSheetRouter.js.map +1 -1
  139. package/lib/module/ui/components/FontLoader.js +1 -1
  140. package/lib/module/ui/components/FontLoader.js.map +1 -1
  141. package/lib/module/ui/components/GroupedItem.js +1 -1
  142. package/lib/module/ui/components/GroupedItem.js.map +1 -1
  143. package/lib/module/ui/components/Header.js +1 -1
  144. package/lib/module/ui/components/Header.js.map +1 -1
  145. package/lib/module/ui/components/OxyProvider.js +9 -1
  146. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  147. package/lib/module/ui/components/OxySignInButton.js +20 -21
  148. package/lib/module/ui/components/OxySignInButton.js.map +1 -1
  149. package/lib/module/ui/components/ProfileCard.js +1 -1
  150. package/lib/module/ui/components/ProfileCard.js.map +1 -1
  151. package/lib/module/ui/components/QuickActions.js +1 -1
  152. package/lib/module/ui/components/QuickActions.js.map +1 -1
  153. package/lib/module/ui/components/Section.js +1 -1
  154. package/lib/module/ui/components/Section.js.map +1 -1
  155. package/lib/module/ui/components/SectionTitle.js +1 -1
  156. package/lib/module/ui/components/SectionTitle.js.map +1 -1
  157. package/lib/module/ui/components/SignInModal.js +536 -0
  158. package/lib/module/ui/components/SignInModal.js.map +1 -0
  159. package/lib/module/ui/context/OxyContext.js +1 -1
  160. package/lib/module/ui/context/OxyContext.js.map +1 -1
  161. package/lib/module/ui/hooks/{use-color-scheme.js → useColorScheme.js} +1 -1
  162. package/lib/module/ui/hooks/useColorScheme.js.map +1 -0
  163. package/lib/module/ui/hooks/useSessionSocket.js +6 -12
  164. package/lib/module/ui/hooks/useSessionSocket.js.map +1 -1
  165. package/lib/module/ui/hooks/useThemeColors.js +1 -1
  166. package/lib/module/ui/hooks/useThemeColors.js.map +1 -1
  167. package/lib/module/ui/hooks/useThemeStyles.js +1 -1
  168. package/lib/module/ui/hooks/useThemeStyles.js.map +1 -1
  169. package/lib/module/ui/navigation/bottomSheetManager.js +5 -2
  170. package/lib/module/ui/navigation/bottomSheetManager.js.map +1 -1
  171. package/lib/module/ui/navigation/routes.js +7 -8
  172. package/lib/module/ui/navigation/routes.js.map +1 -1
  173. package/lib/module/ui/screens/AccountCenterScreen.js +7 -7
  174. package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
  175. package/lib/module/ui/screens/AccountOverviewScreen.js +6 -6
  176. package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -1
  177. package/lib/module/ui/screens/AccountSettingsScreen.js +2 -2
  178. package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
  179. package/lib/module/ui/screens/AccountSwitcherScreen.js +4 -4
  180. package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
  181. package/lib/module/ui/screens/AppInfoScreen.js +1 -1
  182. package/lib/module/ui/screens/AppInfoScreen.js.map +1 -1
  183. package/lib/module/ui/screens/EditProfileFieldScreen.js +1 -1
  184. package/lib/module/ui/screens/EditProfileFieldScreen.js.map +1 -1
  185. package/lib/module/ui/screens/FileManagementScreen.js +1 -1
  186. package/lib/module/ui/screens/FileManagementScreen.js.map +1 -1
  187. package/lib/module/ui/screens/FollowersListScreen.js +13 -0
  188. package/lib/module/ui/screens/FollowersListScreen.js.map +1 -0
  189. package/lib/module/ui/screens/FollowingListScreen.js +13 -0
  190. package/lib/module/ui/screens/FollowingListScreen.js.map +1 -0
  191. package/lib/module/ui/screens/HelpSupportScreen.js +1 -1
  192. package/lib/module/ui/screens/HelpSupportScreen.js.map +1 -1
  193. package/lib/module/ui/screens/HistoryViewScreen.js +1 -1
  194. package/lib/module/ui/screens/HistoryViewScreen.js.map +1 -1
  195. package/lib/module/ui/screens/LanguageSelectorScreen.js +1 -1
  196. package/lib/module/ui/screens/LanguageSelectorScreen.js.map +1 -1
  197. package/lib/module/ui/screens/LearnMoreUsernamesScreen.js +224 -0
  198. package/lib/module/ui/screens/LearnMoreUsernamesScreen.js.map +1 -0
  199. package/lib/module/ui/screens/LegalDocumentsScreen.js +1 -1
  200. package/lib/module/ui/screens/LegalDocumentsScreen.js.map +1 -1
  201. package/lib/module/ui/screens/OxyAuthScreen.js +9 -21
  202. package/lib/module/ui/screens/OxyAuthScreen.js.map +1 -1
  203. package/lib/module/ui/screens/PremiumSubscriptionScreen.js +1 -1
  204. package/lib/module/ui/screens/PremiumSubscriptionScreen.js.map +1 -1
  205. package/lib/module/ui/screens/ProfileScreen.js +1 -1
  206. package/lib/module/ui/screens/ProfileScreen.js.map +1 -1
  207. package/lib/module/ui/screens/SavesCollectionsScreen.js +1 -1
  208. package/lib/module/ui/screens/SavesCollectionsScreen.js.map +1 -1
  209. package/lib/module/ui/screens/UserListScreen.js +405 -0
  210. package/lib/module/ui/screens/UserListScreen.js.map +1 -0
  211. package/lib/module/ui/screens/karma/KarmaAboutScreen.js +1 -1
  212. package/lib/module/ui/screens/karma/KarmaAboutScreen.js.map +1 -1
  213. package/lib/module/ui/screens/karma/KarmaCenterScreen.js +1 -1
  214. package/lib/module/ui/screens/karma/KarmaCenterScreen.js.map +1 -1
  215. package/lib/module/ui/screens/karma/KarmaFAQScreen.js +1 -1
  216. package/lib/module/ui/screens/karma/KarmaFAQScreen.js.map +1 -1
  217. package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js +1 -1
  218. package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js.map +1 -1
  219. package/lib/module/ui/screens/karma/KarmaRewardsScreen.js +1 -1
  220. package/lib/module/ui/screens/karma/KarmaRewardsScreen.js.map +1 -1
  221. package/lib/module/ui/screens/karma/KarmaRulesScreen.js +1 -1
  222. package/lib/module/ui/screens/karma/KarmaRulesScreen.js.map +1 -1
  223. package/lib/module/ui/stores/authStore.js +4 -6
  224. package/lib/module/ui/stores/authStore.js.map +1 -1
  225. package/lib/module/ui/utils/colorUtils.js +7 -40
  226. package/lib/module/ui/utils/colorUtils.js.map +1 -1
  227. package/lib/module/ui/utils/themeUtils.js +7 -35
  228. package/lib/module/ui/utils/themeUtils.js.map +1 -1
  229. package/lib/module/ui/utils/{user-utils.js → userUtils.js} +1 -1
  230. package/lib/module/ui/utils/userUtils.js.map +1 -0
  231. package/lib/module/utils/errorUtils.js +0 -7
  232. package/lib/module/utils/errorUtils.js.map +1 -1
  233. package/lib/module/utils/hookUtils.js +8 -8
  234. package/lib/module/utils/hookUtils.js.map +1 -1
  235. package/lib/module/web/WebOxyContext.js +276 -72
  236. package/lib/module/web/WebOxyContext.js.map +1 -1
  237. package/lib/module/web/index.js +26 -5
  238. package/lib/module/web/index.js.map +1 -1
  239. package/lib/module/web.js +2 -1
  240. package/lib/module/web.js.map +1 -1
  241. package/lib/typescript/commonjs/core/AuthManager.d.ts +144 -0
  242. package/lib/typescript/commonjs/core/AuthManager.d.ts.map +1 -0
  243. package/lib/typescript/commonjs/core/HttpService.d.ts.map +1 -1
  244. package/lib/typescript/commonjs/core/index.d.ts +2 -0
  245. package/lib/typescript/commonjs/core/index.d.ts.map +1 -1
  246. package/lib/typescript/commonjs/core/mixins/OxyServices.fedcm.d.ts.map +1 -1
  247. package/lib/typescript/commonjs/core/mixins/OxyServices.popup.d.ts.map +1 -1
  248. package/lib/typescript/commonjs/index.d.ts +16 -2
  249. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  250. package/lib/typescript/commonjs/models/session.d.ts +4 -0
  251. package/lib/typescript/commonjs/models/session.d.ts.map +1 -1
  252. package/lib/typescript/commonjs/shared/index.d.ts +29 -0
  253. package/lib/typescript/commonjs/shared/index.d.ts.map +1 -0
  254. package/lib/typescript/commonjs/shared/utils/colorUtils.d.ts +105 -0
  255. package/lib/typescript/commonjs/shared/utils/colorUtils.d.ts.map +1 -0
  256. package/lib/typescript/commonjs/shared/utils/debugUtils.d.ts +49 -0
  257. package/lib/typescript/commonjs/shared/utils/debugUtils.d.ts.map +1 -0
  258. package/lib/typescript/commonjs/shared/utils/errorUtils.d.ts +98 -0
  259. package/lib/typescript/commonjs/shared/utils/errorUtils.d.ts.map +1 -0
  260. package/lib/typescript/commonjs/shared/utils/index.d.ts +14 -0
  261. package/lib/typescript/commonjs/shared/utils/index.d.ts.map +1 -0
  262. package/lib/typescript/commonjs/shared/utils/networkUtils.d.ts +140 -0
  263. package/lib/typescript/commonjs/shared/utils/networkUtils.d.ts.map +1 -0
  264. package/lib/typescript/commonjs/shared/utils/themeUtils.d.ts +91 -0
  265. package/lib/typescript/commonjs/shared/utils/themeUtils.d.ts.map +1 -0
  266. package/lib/typescript/commonjs/ui/components/FontLoader.d.ts +1 -1
  267. package/lib/typescript/commonjs/ui/components/FontLoader.d.ts.map +1 -1
  268. package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
  269. package/lib/typescript/commonjs/ui/components/OxySignInButton.d.ts.map +1 -1
  270. package/lib/typescript/commonjs/ui/components/SignInModal.d.ts +18 -0
  271. package/lib/typescript/commonjs/ui/components/SignInModal.d.ts.map +1 -0
  272. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts +1 -2
  273. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
  274. package/lib/typescript/commonjs/ui/hooks/{use-color-scheme.d.ts → useColorScheme.d.ts} +1 -1
  275. package/lib/typescript/commonjs/ui/hooks/useColorScheme.d.ts.map +1 -0
  276. package/lib/typescript/commonjs/ui/hooks/useSessionSocket.d.ts.map +1 -1
  277. package/lib/typescript/commonjs/ui/navigation/bottomSheetManager.d.ts +2 -0
  278. package/lib/typescript/commonjs/ui/navigation/bottomSheetManager.d.ts.map +1 -1
  279. package/lib/typescript/commonjs/ui/navigation/routes.d.ts +1 -1
  280. package/lib/typescript/commonjs/ui/navigation/routes.d.ts.map +1 -1
  281. package/lib/typescript/commonjs/ui/screens/FollowersListScreen.d.ts +9 -0
  282. package/lib/typescript/commonjs/ui/screens/FollowersListScreen.d.ts.map +1 -0
  283. package/lib/typescript/commonjs/ui/screens/FollowingListScreen.d.ts +9 -0
  284. package/lib/typescript/commonjs/ui/screens/FollowingListScreen.d.ts.map +1 -0
  285. package/lib/typescript/commonjs/ui/screens/LearnMoreUsernamesScreen.d.ts +5 -0
  286. package/lib/typescript/commonjs/ui/screens/LearnMoreUsernamesScreen.d.ts.map +1 -0
  287. package/lib/typescript/commonjs/ui/screens/OxyAuthScreen.d.ts.map +1 -1
  288. package/lib/typescript/commonjs/ui/screens/UserListScreen.d.ts +11 -0
  289. package/lib/typescript/commonjs/ui/screens/UserListScreen.d.ts.map +1 -0
  290. package/lib/typescript/commonjs/ui/stores/authStore.d.ts.map +1 -1
  291. package/lib/typescript/commonjs/ui/utils/colorUtils.d.ts +7 -11
  292. package/lib/typescript/commonjs/ui/utils/colorUtils.d.ts.map +1 -1
  293. package/lib/typescript/commonjs/ui/utils/themeUtils.d.ts +6 -19
  294. package/lib/typescript/commonjs/ui/utils/themeUtils.d.ts.map +1 -1
  295. package/lib/typescript/commonjs/ui/utils/{user-utils.d.ts → userUtils.d.ts} +1 -1
  296. package/lib/typescript/commonjs/ui/utils/userUtils.d.ts.map +1 -0
  297. package/lib/typescript/commonjs/utils/errorUtils.d.ts +0 -6
  298. package/lib/typescript/commonjs/utils/errorUtils.d.ts.map +1 -1
  299. package/lib/typescript/commonjs/web/WebOxyContext.d.ts +113 -4
  300. package/lib/typescript/commonjs/web/WebOxyContext.d.ts.map +1 -1
  301. package/lib/typescript/commonjs/web/index.d.ts +20 -9
  302. package/lib/typescript/commonjs/web/index.d.ts.map +1 -1
  303. package/lib/typescript/commonjs/web.d.ts +2 -1
  304. package/lib/typescript/commonjs/web.d.ts.map +1 -1
  305. package/lib/typescript/module/core/AuthManager.d.ts +144 -0
  306. package/lib/typescript/module/core/AuthManager.d.ts.map +1 -0
  307. package/lib/typescript/module/core/HttpService.d.ts.map +1 -1
  308. package/lib/typescript/module/core/index.d.ts +2 -0
  309. package/lib/typescript/module/core/index.d.ts.map +1 -1
  310. package/lib/typescript/module/core/mixins/OxyServices.fedcm.d.ts.map +1 -1
  311. package/lib/typescript/module/core/mixins/OxyServices.popup.d.ts.map +1 -1
  312. package/lib/typescript/module/index.d.ts +16 -2
  313. package/lib/typescript/module/index.d.ts.map +1 -1
  314. package/lib/typescript/module/models/session.d.ts +4 -0
  315. package/lib/typescript/module/models/session.d.ts.map +1 -1
  316. package/lib/typescript/module/shared/index.d.ts +29 -0
  317. package/lib/typescript/module/shared/index.d.ts.map +1 -0
  318. package/lib/typescript/module/shared/utils/colorUtils.d.ts +105 -0
  319. package/lib/typescript/module/shared/utils/colorUtils.d.ts.map +1 -0
  320. package/lib/typescript/module/shared/utils/debugUtils.d.ts +49 -0
  321. package/lib/typescript/module/shared/utils/debugUtils.d.ts.map +1 -0
  322. package/lib/typescript/module/shared/utils/errorUtils.d.ts +98 -0
  323. package/lib/typescript/module/shared/utils/errorUtils.d.ts.map +1 -0
  324. package/lib/typescript/module/shared/utils/index.d.ts +14 -0
  325. package/lib/typescript/module/shared/utils/index.d.ts.map +1 -0
  326. package/lib/typescript/module/shared/utils/networkUtils.d.ts +140 -0
  327. package/lib/typescript/module/shared/utils/networkUtils.d.ts.map +1 -0
  328. package/lib/typescript/module/shared/utils/themeUtils.d.ts +91 -0
  329. package/lib/typescript/module/shared/utils/themeUtils.d.ts.map +1 -0
  330. package/lib/typescript/module/ui/components/FontLoader.d.ts +1 -1
  331. package/lib/typescript/module/ui/components/FontLoader.d.ts.map +1 -1
  332. package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
  333. package/lib/typescript/module/ui/components/OxySignInButton.d.ts.map +1 -1
  334. package/lib/typescript/module/ui/components/SignInModal.d.ts +18 -0
  335. package/lib/typescript/module/ui/components/SignInModal.d.ts.map +1 -0
  336. package/lib/typescript/module/ui/context/OxyContext.d.ts +1 -2
  337. package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
  338. package/lib/typescript/module/ui/hooks/{use-color-scheme.d.ts → useColorScheme.d.ts} +1 -1
  339. package/lib/typescript/module/ui/hooks/useColorScheme.d.ts.map +1 -0
  340. package/lib/typescript/module/ui/hooks/useSessionSocket.d.ts.map +1 -1
  341. package/lib/typescript/module/ui/navigation/bottomSheetManager.d.ts +2 -0
  342. package/lib/typescript/module/ui/navigation/bottomSheetManager.d.ts.map +1 -1
  343. package/lib/typescript/module/ui/navigation/routes.d.ts +1 -1
  344. package/lib/typescript/module/ui/navigation/routes.d.ts.map +1 -1
  345. package/lib/typescript/module/ui/screens/FollowersListScreen.d.ts +9 -0
  346. package/lib/typescript/module/ui/screens/FollowersListScreen.d.ts.map +1 -0
  347. package/lib/typescript/module/ui/screens/FollowingListScreen.d.ts +9 -0
  348. package/lib/typescript/module/ui/screens/FollowingListScreen.d.ts.map +1 -0
  349. package/lib/typescript/module/ui/screens/LearnMoreUsernamesScreen.d.ts +5 -0
  350. package/lib/typescript/module/ui/screens/LearnMoreUsernamesScreen.d.ts.map +1 -0
  351. package/lib/typescript/module/ui/screens/OxyAuthScreen.d.ts.map +1 -1
  352. package/lib/typescript/module/ui/screens/UserListScreen.d.ts +11 -0
  353. package/lib/typescript/module/ui/screens/UserListScreen.d.ts.map +1 -0
  354. package/lib/typescript/module/ui/stores/authStore.d.ts.map +1 -1
  355. package/lib/typescript/module/ui/utils/colorUtils.d.ts +7 -11
  356. package/lib/typescript/module/ui/utils/colorUtils.d.ts.map +1 -1
  357. package/lib/typescript/module/ui/utils/themeUtils.d.ts +6 -19
  358. package/lib/typescript/module/ui/utils/themeUtils.d.ts.map +1 -1
  359. package/lib/typescript/module/ui/utils/{user-utils.d.ts → userUtils.d.ts} +1 -1
  360. package/lib/typescript/module/ui/utils/userUtils.d.ts.map +1 -0
  361. package/lib/typescript/module/utils/errorUtils.d.ts +0 -6
  362. package/lib/typescript/module/utils/errorUtils.d.ts.map +1 -1
  363. package/lib/typescript/module/web/WebOxyContext.d.ts +113 -4
  364. package/lib/typescript/module/web/WebOxyContext.d.ts.map +1 -1
  365. package/lib/typescript/module/web/index.d.ts +20 -9
  366. package/lib/typescript/module/web/index.d.ts.map +1 -1
  367. package/lib/typescript/module/web.d.ts +2 -1
  368. package/lib/typescript/module/web.d.ts.map +1 -1
  369. package/package.json +8 -2
  370. package/src/core/AuthManager.ts +436 -0
  371. package/src/core/HttpService.ts +43 -1
  372. package/src/core/index.ts +4 -0
  373. package/src/core/mixins/OxyServices.fedcm.ts +37 -42
  374. package/src/core/mixins/OxyServices.popup.ts +10 -7
  375. package/src/index.ts +76 -11
  376. package/src/models/session.ts +4 -0
  377. package/src/shared/index.ts +82 -0
  378. package/src/shared/utils/colorUtils.ts +155 -0
  379. package/src/shared/utils/debugUtils.ts +73 -0
  380. package/src/shared/utils/errorUtils.ts +181 -0
  381. package/src/shared/utils/index.ts +59 -0
  382. package/src/shared/utils/networkUtils.ts +248 -0
  383. package/src/shared/utils/themeUtils.ts +115 -0
  384. package/src/ui/components/BottomSheetRouter.tsx +1 -1
  385. package/src/ui/components/FontLoader.tsx +1 -2
  386. package/src/ui/components/GroupedItem.tsx +1 -1
  387. package/src/ui/components/Header.tsx +1 -1
  388. package/src/ui/components/OxyProvider.tsx +10 -0
  389. package/src/ui/components/OxySignInButton.tsx +20 -22
  390. package/src/ui/components/ProfileCard.tsx +1 -1
  391. package/src/ui/components/QuickActions.tsx +1 -1
  392. package/src/ui/components/Section.tsx +1 -1
  393. package/src/ui/components/SectionTitle.tsx +1 -1
  394. package/src/ui/components/SignInModal.tsx +534 -0
  395. package/src/ui/context/OxyContext.tsx +1 -2
  396. package/src/ui/hooks/queries/queryKeys.ts +2 -2
  397. package/src/ui/hooks/useSessionSocket.ts +12 -17
  398. package/src/ui/hooks/useThemeColors.ts +1 -1
  399. package/src/ui/hooks/useThemeStyles.ts +1 -1
  400. package/src/ui/navigation/bottomSheetManager.ts +5 -1
  401. package/src/ui/navigation/routes.ts +8 -9
  402. package/src/ui/screens/AccountCenterScreen.tsx +7 -7
  403. package/src/ui/screens/AccountOverviewScreen.tsx +6 -6
  404. package/src/ui/screens/AccountSettingsScreen.tsx +2 -2
  405. package/src/ui/screens/AccountSwitcherScreen.tsx +4 -4
  406. package/src/ui/screens/AppInfoScreen.tsx +1 -1
  407. package/src/ui/screens/EditProfileFieldScreen.tsx +1 -1
  408. package/src/ui/screens/FileManagementScreen.tsx +1 -1
  409. package/src/ui/screens/FollowersListScreen.tsx +14 -0
  410. package/src/ui/screens/FollowingListScreen.tsx +14 -0
  411. package/src/ui/screens/HelpSupportScreen.tsx +1 -1
  412. package/src/ui/screens/HistoryViewScreen.tsx +1 -1
  413. package/src/ui/screens/LanguageSelectorScreen.tsx +1 -1
  414. package/src/ui/screens/LearnMoreUsernamesScreen.tsx +231 -0
  415. package/src/ui/screens/LegalDocumentsScreen.tsx +1 -1
  416. package/src/ui/screens/OxyAuthScreen.tsx +10 -21
  417. package/src/ui/screens/PremiumSubscriptionScreen.tsx +1 -1
  418. package/src/ui/screens/ProfileScreen.tsx +1 -1
  419. package/src/ui/screens/SavesCollectionsScreen.tsx +1 -1
  420. package/src/ui/screens/UserListScreen.tsx +416 -0
  421. package/src/ui/screens/karma/KarmaAboutScreen.tsx +1 -1
  422. package/src/ui/screens/karma/KarmaCenterScreen.tsx +1 -1
  423. package/src/ui/screens/karma/KarmaFAQScreen.tsx +1 -1
  424. package/src/ui/screens/karma/KarmaLeaderboardScreen.tsx +1 -1
  425. package/src/ui/screens/karma/KarmaRewardsScreen.tsx +1 -1
  426. package/src/ui/screens/karma/KarmaRulesScreen.tsx +1 -1
  427. package/src/ui/stores/authStore.ts +5 -6
  428. package/src/ui/utils/colorUtils.ts +15 -43
  429. package/src/ui/utils/themeUtils.ts +14 -39
  430. package/src/utils/errorUtils.ts +1 -6
  431. package/src/utils/hookUtils.ts +8 -8
  432. package/src/web/WebOxyContext.tsx +330 -72
  433. package/src/web/index.ts +77 -7
  434. package/src/web.ts +1 -1
  435. package/lib/commonjs/ui/hooks/use-color-scheme.js.map +0 -1
  436. package/lib/commonjs/ui/utils/user-utils.js.map +0 -1
  437. package/lib/module/ui/hooks/use-color-scheme.js.map +0 -1
  438. package/lib/module/ui/utils/user-utils.js.map +0 -1
  439. package/lib/typescript/commonjs/ui/hooks/use-color-scheme.d.ts.map +0 -1
  440. package/lib/typescript/commonjs/ui/utils/user-utils.d.ts.map +0 -1
  441. package/lib/typescript/module/ui/hooks/use-color-scheme.d.ts.map +0 -1
  442. package/lib/typescript/module/ui/utils/user-utils.d.ts.map +0 -1
  443. /package/src/ui/hooks/{use-color-scheme.ts → useColorScheme.ts} +0 -0
  444. /package/src/ui/utils/{user-utils.ts → userUtils.ts} +0 -0
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Color Utility Functions
3
+ *
4
+ * Consolidated color manipulation utilities used across the OxyServices ecosystem.
5
+ * These functions work in any JavaScript environment (browser, Node.js, React Native).
6
+ *
7
+ * @module shared/utils/colorUtils
8
+ */
9
+
10
+ /**
11
+ * Darkens a hex color by a specified factor.
12
+ *
13
+ * @param color - Hex color string (with or without #)
14
+ * @param factor - Amount to darken (0-1). Default: 0.6
15
+ * @returns Darkened hex color string with # prefix
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * darkenColor('#FF0000', 0.5); // Returns a darker red
20
+ * darkenColor('FF0000', 0.3); // Also works without #
21
+ * ```
22
+ */
23
+ export const darkenColor = (color: string, factor: number = 0.6): string => {
24
+ const hex = color.replace('#', '');
25
+
26
+ const r = parseInt(hex.substring(0, 2), 16);
27
+ const g = parseInt(hex.substring(2, 4), 16);
28
+ const b = parseInt(hex.substring(4, 6), 16);
29
+
30
+ const newR = Math.max(0, Math.round(r * (1 - factor)));
31
+ const newG = Math.max(0, Math.round(g * (1 - factor)));
32
+ const newB = Math.max(0, Math.round(b * (1 - factor)));
33
+
34
+ return `#${newR.toString(16).padStart(2, '0')}${newG.toString(16).padStart(2, '0')}${newB.toString(16).padStart(2, '0')}`;
35
+ };
36
+
37
+ /**
38
+ * Lightens a hex color by a specified factor.
39
+ *
40
+ * @param color - Hex color string (with or without #)
41
+ * @param factor - Amount to lighten (0-1). Default: 0.3
42
+ * @returns Lightened hex color string with # prefix
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * lightenColor('#0000FF', 0.5); // Returns a lighter blue
47
+ * ```
48
+ */
49
+ export const lightenColor = (color: string, factor: number = 0.3): string => {
50
+ const hex = color.replace('#', '');
51
+
52
+ const r = parseInt(hex.substring(0, 2), 16);
53
+ const g = parseInt(hex.substring(2, 4), 16);
54
+ const b = parseInt(hex.substring(4, 6), 16);
55
+
56
+ const newR = Math.min(255, Math.round(r + (255 - r) * factor));
57
+ const newG = Math.min(255, Math.round(g + (255 - g) * factor));
58
+ const newB = Math.min(255, Math.round(b + (255 - b) * factor));
59
+
60
+ return `#${newR.toString(16).padStart(2, '0')}${newG.toString(16).padStart(2, '0')}${newB.toString(16).padStart(2, '0')}`;
61
+ };
62
+
63
+ /**
64
+ * Converts a hex color to RGB values.
65
+ *
66
+ * @param hex - Hex color string (with or without #)
67
+ * @returns Object with r, g, b values (0-255)
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * hexToRgb('#FF5733'); // { r: 255, g: 87, b: 51 }
72
+ * ```
73
+ */
74
+ export const hexToRgb = (hex: string): { r: number; g: number; b: number } | null => {
75
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
76
+ return result
77
+ ? {
78
+ r: parseInt(result[1], 16),
79
+ g: parseInt(result[2], 16),
80
+ b: parseInt(result[3], 16),
81
+ }
82
+ : null;
83
+ };
84
+
85
+ /**
86
+ * Converts RGB values to a hex color string.
87
+ *
88
+ * @param r - Red value (0-255)
89
+ * @param g - Green value (0-255)
90
+ * @param b - Blue value (0-255)
91
+ * @returns Hex color string with # prefix
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * rgbToHex(255, 87, 51); // '#ff5733'
96
+ * ```
97
+ */
98
+ export const rgbToHex = (r: number, g: number, b: number): string => {
99
+ return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
100
+ };
101
+
102
+ /**
103
+ * Adjusts the opacity of a hex color, returning an rgba string.
104
+ *
105
+ * @param hex - Hex color string
106
+ * @param opacity - Opacity value (0-1)
107
+ * @returns RGBA color string
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * withOpacity('#FF0000', 0.5); // 'rgba(255, 0, 0, 0.5)'
112
+ * ```
113
+ */
114
+ export const withOpacity = (hex: string, opacity: number): string => {
115
+ const rgb = hexToRgb(hex);
116
+ if (!rgb) return hex;
117
+ return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${opacity})`;
118
+ };
119
+
120
+ /**
121
+ * Checks if a color is considered "light" (for determining text contrast).
122
+ *
123
+ * @param hex - Hex color string
124
+ * @returns true if the color is light, false if dark
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * isLightColor('#FFFFFF'); // true
129
+ * isLightColor('#000000'); // false
130
+ * ```
131
+ */
132
+ export const isLightColor = (hex: string): boolean => {
133
+ const rgb = hexToRgb(hex);
134
+ if (!rgb) return true;
135
+
136
+ // Using relative luminance formula
137
+ const luminance = (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255;
138
+ return luminance > 0.5;
139
+ };
140
+
141
+ /**
142
+ * Gets a contrasting text color (black or white) for a given background color.
143
+ *
144
+ * @param backgroundColor - Hex color string of the background
145
+ * @returns '#000000' for light backgrounds, '#ffffff' for dark backgrounds
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * getContrastTextColor('#FFFF00'); // '#000000' (black text on yellow)
150
+ * getContrastTextColor('#000080'); // '#ffffff' (white text on navy)
151
+ * ```
152
+ */
153
+ export const getContrastTextColor = (backgroundColor: string): string => {
154
+ return isLightColor(backgroundColor) ? '#000000' : '#ffffff';
155
+ };
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Debug Utilities
3
+ *
4
+ * Provides safe logging functions that only output in development mode.
5
+ * All logs are stripped in production builds.
6
+ *
7
+ * @module shared/utils/debugUtils
8
+ */
9
+
10
+ /* global __DEV__ */
11
+ declare const __DEV__: boolean | undefined;
12
+
13
+ /**
14
+ * Check if running in development mode
15
+ */
16
+ export const isDev = (): boolean => {
17
+ return typeof __DEV__ !== 'undefined' && __DEV__;
18
+ };
19
+
20
+ /**
21
+ * Log a debug message (only in development)
22
+ * @param prefix - Log prefix (e.g., '[FedCM]')
23
+ * @param args - Arguments to log
24
+ */
25
+ export const debugLog = (prefix: string, ...args: unknown[]): void => {
26
+ if (isDev()) {
27
+ console.log(prefix, ...args);
28
+ }
29
+ };
30
+
31
+ /**
32
+ * Log a debug warning (only in development)
33
+ * @param prefix - Log prefix
34
+ * @param args - Arguments to log
35
+ */
36
+ export const debugWarn = (prefix: string, ...args: unknown[]): void => {
37
+ if (isDev()) {
38
+ console.warn(prefix, ...args);
39
+ }
40
+ };
41
+
42
+ /**
43
+ * Log a debug error (only in development)
44
+ * @param prefix - Log prefix
45
+ * @param args - Arguments to log
46
+ */
47
+ export const debugError = (prefix: string, ...args: unknown[]): void => {
48
+ if (isDev()) {
49
+ console.error(prefix, ...args);
50
+ }
51
+ };
52
+
53
+ /**
54
+ * Create a namespaced debug logger
55
+ * @param namespace - Logger namespace (e.g., 'FedCM', 'PopupAuth')
56
+ * @returns Object with log, warn, error methods
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const debug = createDebugLogger('FedCM');
61
+ * debug.log('Starting authentication');
62
+ * debug.warn('Token expires soon');
63
+ * debug.error('Authentication failed', error);
64
+ * ```
65
+ */
66
+ export const createDebugLogger = (namespace: string) => {
67
+ const prefix = `[${namespace}]`;
68
+ return {
69
+ log: (...args: unknown[]) => debugLog(prefix, ...args),
70
+ warn: (...args: unknown[]) => debugWarn(prefix, ...args),
71
+ error: (...args: unknown[]) => debugError(prefix, ...args),
72
+ };
73
+ };
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Error Utility Functions
3
+ *
4
+ * Consolidated error handling utilities for the OxyServices ecosystem.
5
+ * These functions help with common error patterns like checking HTTP status codes.
6
+ *
7
+ * @module shared/utils/errorUtils
8
+ */
9
+
10
+ /**
11
+ * Common HTTP status codes used in error checking.
12
+ */
13
+ export const HttpStatus = {
14
+ BAD_REQUEST: 400,
15
+ UNAUTHORIZED: 401,
16
+ FORBIDDEN: 403,
17
+ NOT_FOUND: 404,
18
+ CONFLICT: 409,
19
+ UNPROCESSABLE_ENTITY: 422,
20
+ TOO_MANY_REQUESTS: 429,
21
+ INTERNAL_SERVER_ERROR: 500,
22
+ BAD_GATEWAY: 502,
23
+ SERVICE_UNAVAILABLE: 503,
24
+ GATEWAY_TIMEOUT: 504,
25
+ } as const;
26
+
27
+ /**
28
+ * Extracts the HTTP status code from an error object.
29
+ *
30
+ * @param error - Any error object
31
+ * @returns The status code if found, undefined otherwise
32
+ */
33
+ export const getErrorStatus = (error: unknown): number | undefined => {
34
+ if (!error || typeof error !== 'object') return undefined;
35
+
36
+ const err = error as Record<string, unknown>;
37
+
38
+ // Direct status property
39
+ if (typeof err.status === 'number') return err.status;
40
+
41
+ // Axios-style response.status
42
+ if (err.response && typeof err.response === 'object') {
43
+ const response = err.response as Record<string, unknown>;
44
+ if (typeof response.status === 'number') return response.status;
45
+ }
46
+
47
+ // statusCode property (some libraries use this)
48
+ if (typeof err.statusCode === 'number') return err.statusCode;
49
+
50
+ return undefined;
51
+ };
52
+
53
+ /**
54
+ * Extracts the error message from an error object.
55
+ *
56
+ * @param error - Any error object
57
+ * @param fallback - Fallback message if none found
58
+ * @returns The error message
59
+ */
60
+ export const getErrorMessage = (error: unknown, fallback: string = 'An unknown error occurred'): string => {
61
+ if (!error) return fallback;
62
+
63
+ if (typeof error === 'string') return error;
64
+
65
+ if (error instanceof Error) return error.message;
66
+
67
+ if (typeof error === 'object') {
68
+ const err = error as Record<string, unknown>;
69
+
70
+ if (typeof err.message === 'string') return err.message;
71
+ if (typeof err.error === 'string') return err.error;
72
+
73
+ // Axios-style response.data.message
74
+ if (err.response && typeof err.response === 'object') {
75
+ const response = err.response as Record<string, unknown>;
76
+ if (response.data && typeof response.data === 'object') {
77
+ const data = response.data as Record<string, unknown>;
78
+ if (typeof data.message === 'string') return data.message;
79
+ if (typeof data.error === 'string') return data.error;
80
+ }
81
+ }
82
+ }
83
+
84
+ return fallback;
85
+ };
86
+
87
+ /**
88
+ * Check if an error indicates the user is already registered (HTTP 409 Conflict).
89
+ *
90
+ * The backend should always return HTTP 409 for duplicate registrations.
91
+ *
92
+ * @param error - Any error object
93
+ * @returns true if the error is a 409 Conflict
94
+ */
95
+ export const isAlreadyRegisteredError = (error: unknown): boolean => {
96
+ return getErrorStatus(error) === HttpStatus.CONFLICT;
97
+ };
98
+
99
+ /**
100
+ * Check if an error is an authentication error (HTTP 401).
101
+ *
102
+ * @param error - Any error object
103
+ * @returns true if the error is a 401 Unauthorized
104
+ */
105
+ export const isUnauthorizedError = (error: unknown): boolean => {
106
+ return getErrorStatus(error) === HttpStatus.UNAUTHORIZED;
107
+ };
108
+
109
+ /**
110
+ * Check if an error is a forbidden error (HTTP 403).
111
+ *
112
+ * @param error - Any error object
113
+ * @returns true if the error is a 403 Forbidden
114
+ */
115
+ export const isForbiddenError = (error: unknown): boolean => {
116
+ return getErrorStatus(error) === HttpStatus.FORBIDDEN;
117
+ };
118
+
119
+ /**
120
+ * Check if an error is a not found error (HTTP 404).
121
+ *
122
+ * @param error - Any error object
123
+ * @returns true if the error is a 404 Not Found
124
+ */
125
+ export const isNotFoundError = (error: unknown): boolean => {
126
+ return getErrorStatus(error) === HttpStatus.NOT_FOUND;
127
+ };
128
+
129
+ /**
130
+ * Check if an error is a rate limit error (HTTP 429).
131
+ *
132
+ * @param error - Any error object
133
+ * @returns true if the error is a 429 Too Many Requests
134
+ */
135
+ export const isRateLimitError = (error: unknown): boolean => {
136
+ return getErrorStatus(error) === HttpStatus.TOO_MANY_REQUESTS;
137
+ };
138
+
139
+ /**
140
+ * Check if an error is a server error (HTTP 5xx).
141
+ *
142
+ * @param error - Any error object
143
+ * @returns true if the error is a 5xx server error
144
+ */
145
+ export const isServerError = (error: unknown): boolean => {
146
+ const status = getErrorStatus(error);
147
+ return status !== undefined && status >= 500 && status < 600;
148
+ };
149
+
150
+ /**
151
+ * Check if an error is a network error (no response received).
152
+ *
153
+ * @param error - Any error object
154
+ * @returns true if the error appears to be a network error
155
+ */
156
+ export const isNetworkError = (error: unknown): boolean => {
157
+ if (!error || typeof error !== 'object') return false;
158
+
159
+ const err = error as Record<string, unknown>;
160
+
161
+ // Check for common network error indicators
162
+ if (err.name === 'NetworkError') return true;
163
+ if (err.code === 'ENOTFOUND' || err.code === 'ECONNREFUSED' || err.code === 'ETIMEDOUT') return true;
164
+
165
+ // Axios-style: has request but no response
166
+ if (err.request && !err.response) return true;
167
+
168
+ // Message-based detection
169
+ const message = getErrorMessage(error, '').toLowerCase();
170
+ return message.includes('network') || message.includes('connection') || message.includes('timeout');
171
+ };
172
+
173
+ /**
174
+ * Check if an error is retryable (network errors or 5xx server errors).
175
+ *
176
+ * @param error - Any error object
177
+ * @returns true if the request should be retried
178
+ */
179
+ export const isRetryableError = (error: unknown): boolean => {
180
+ return isNetworkError(error) || isServerError(error) || isRateLimitError(error);
181
+ };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Shared Utility Functions
3
+ *
4
+ * Re-exports all shared utilities for convenient importing.
5
+ *
6
+ * @module shared/utils
7
+ */
8
+
9
+ // Color utilities
10
+ export {
11
+ darkenColor,
12
+ lightenColor,
13
+ hexToRgb,
14
+ rgbToHex,
15
+ withOpacity,
16
+ isLightColor,
17
+ getContrastTextColor,
18
+ } from './colorUtils';
19
+
20
+ // Theme utilities
21
+ export {
22
+ normalizeTheme,
23
+ normalizeColorScheme,
24
+ getOppositeTheme,
25
+ systemPrefersDarkMode,
26
+ getSystemColorScheme,
27
+ } from './themeUtils';
28
+ export type { ThemeValue } from './themeUtils';
29
+
30
+ // Error utilities
31
+ export {
32
+ HttpStatus,
33
+ getErrorStatus,
34
+ getErrorMessage,
35
+ isAlreadyRegisteredError,
36
+ isUnauthorizedError,
37
+ isForbiddenError,
38
+ isNotFoundError,
39
+ isRateLimitError,
40
+ isServerError,
41
+ isNetworkError,
42
+ isRetryableError,
43
+ } from './errorUtils';
44
+
45
+ // Network utilities
46
+ export {
47
+ DEFAULT_CIRCUIT_BREAKER_CONFIG,
48
+ createCircuitBreakerState,
49
+ calculateBackoffInterval,
50
+ recordFailure,
51
+ recordSuccess,
52
+ shouldAllowRequest,
53
+ delay,
54
+ withRetry,
55
+ } from './networkUtils';
56
+ export type {
57
+ CircuitBreakerState,
58
+ CircuitBreakerConfig,
59
+ } from './networkUtils';
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Network Utility Functions
3
+ *
4
+ * Consolidated network utilities including circuit breaker pattern
5
+ * and exponential backoff for resilient API calls.
6
+ *
7
+ * @module shared/utils/networkUtils
8
+ */
9
+
10
+ /**
11
+ * State for circuit breaker pattern.
12
+ */
13
+ export interface CircuitBreakerState {
14
+ /** Number of consecutive failures */
15
+ consecutiveFailures: number;
16
+ /** Current interval between retries (ms) */
17
+ currentInterval: number;
18
+ /** Base interval for retries (ms) */
19
+ baseInterval: number;
20
+ /** Maximum interval cap (ms) */
21
+ maxInterval: number;
22
+ /** Number of failures before circuit opens */
23
+ maxFailures: number;
24
+ /** Whether the circuit is currently open (blocking requests) */
25
+ isOpen?: boolean;
26
+ /** Timestamp when circuit was opened */
27
+ openedAt?: number;
28
+ }
29
+
30
+ /**
31
+ * Configuration for circuit breaker.
32
+ */
33
+ export interface CircuitBreakerConfig {
34
+ /** Base interval between retries in milliseconds. Default: 10000 (10s) */
35
+ baseInterval?: number;
36
+ /** Maximum interval cap in milliseconds. Default: 60000 (60s) */
37
+ maxInterval?: number;
38
+ /** Number of consecutive failures before opening circuit. Default: 5 */
39
+ maxFailures?: number;
40
+ /** Time to wait before attempting recovery in milliseconds. Default: 30000 (30s) */
41
+ recoveryTimeout?: number;
42
+ }
43
+
44
+ /**
45
+ * Default circuit breaker configuration.
46
+ */
47
+ export const DEFAULT_CIRCUIT_BREAKER_CONFIG: Required<CircuitBreakerConfig> = {
48
+ baseInterval: 10000,
49
+ maxInterval: 60000,
50
+ maxFailures: 5,
51
+ recoveryTimeout: 30000,
52
+ };
53
+
54
+ /**
55
+ * Creates initial circuit breaker state.
56
+ *
57
+ * @param config - Optional custom configuration
58
+ * @returns Initial circuit breaker state
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const state = createCircuitBreakerState({ maxFailures: 3 });
63
+ * ```
64
+ */
65
+ export const createCircuitBreakerState = (
66
+ config: CircuitBreakerConfig = {}
67
+ ): CircuitBreakerState => {
68
+ const { baseInterval, maxInterval, maxFailures } = {
69
+ ...DEFAULT_CIRCUIT_BREAKER_CONFIG,
70
+ ...config,
71
+ };
72
+
73
+ return {
74
+ consecutiveFailures: 0,
75
+ currentInterval: baseInterval,
76
+ baseInterval,
77
+ maxInterval,
78
+ maxFailures,
79
+ isOpen: false,
80
+ };
81
+ };
82
+
83
+ /**
84
+ * Calculates next interval using exponential backoff.
85
+ *
86
+ * @param state - Current circuit breaker state
87
+ * @returns Next interval in milliseconds
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const nextInterval = calculateBackoffInterval(state);
92
+ * await delay(nextInterval);
93
+ * ```
94
+ */
95
+ export const calculateBackoffInterval = (state: CircuitBreakerState): number => {
96
+ const { consecutiveFailures, baseInterval, maxInterval } = state;
97
+
98
+ if (consecutiveFailures === 0) return baseInterval;
99
+
100
+ const backoffMultiplier = Math.min(
101
+ Math.pow(2, consecutiveFailures - 1),
102
+ maxInterval / baseInterval
103
+ );
104
+
105
+ return Math.min(baseInterval * backoffMultiplier, maxInterval);
106
+ };
107
+
108
+ /**
109
+ * Records a failure and updates circuit breaker state.
110
+ *
111
+ * @param state - Current circuit breaker state
112
+ * @returns Updated state after recording failure
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * try {
117
+ * await apiCall();
118
+ * state = recordSuccess(state);
119
+ * } catch (error) {
120
+ * state = recordFailure(state);
121
+ * }
122
+ * ```
123
+ */
124
+ export const recordFailure = (state: CircuitBreakerState): CircuitBreakerState => {
125
+ const newFailures = state.consecutiveFailures + 1;
126
+ const newInterval = calculateBackoffInterval({
127
+ ...state,
128
+ consecutiveFailures: newFailures,
129
+ });
130
+
131
+ const shouldOpenCircuit = newFailures >= state.maxFailures;
132
+ const finalInterval = shouldOpenCircuit ? state.maxInterval : newInterval;
133
+
134
+ return {
135
+ ...state,
136
+ consecutiveFailures: newFailures,
137
+ currentInterval: finalInterval,
138
+ isOpen: shouldOpenCircuit,
139
+ openedAt: shouldOpenCircuit ? Date.now() : state.openedAt,
140
+ };
141
+ };
142
+
143
+ /**
144
+ * Records a success and resets circuit breaker state.
145
+ *
146
+ * @param state - Current circuit breaker state
147
+ * @returns Reset state after successful request
148
+ */
149
+ export const recordSuccess = (state: CircuitBreakerState): CircuitBreakerState => {
150
+ return {
151
+ ...state,
152
+ consecutiveFailures: 0,
153
+ currentInterval: state.baseInterval,
154
+ isOpen: false,
155
+ openedAt: undefined,
156
+ };
157
+ };
158
+
159
+ /**
160
+ * Checks if the circuit breaker should allow a request.
161
+ *
162
+ * When the circuit is open, it will only allow requests after
163
+ * the recovery timeout has passed (half-open state).
164
+ *
165
+ * @param state - Current circuit breaker state
166
+ * @param recoveryTimeout - Time to wait before allowing recovery attempts
167
+ * @returns true if request should be allowed
168
+ */
169
+ export const shouldAllowRequest = (
170
+ state: CircuitBreakerState,
171
+ recoveryTimeout: number = DEFAULT_CIRCUIT_BREAKER_CONFIG.recoveryTimeout
172
+ ): boolean => {
173
+ if (!state.isOpen) return true;
174
+
175
+ if (!state.openedAt) return true;
176
+
177
+ const timeSinceOpen = Date.now() - state.openedAt;
178
+ return timeSinceOpen >= recoveryTimeout;
179
+ };
180
+
181
+ /**
182
+ * Delays execution for a specified duration.
183
+ *
184
+ * @param ms - Milliseconds to delay
185
+ * @returns Promise that resolves after the delay
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * await delay(1000); // Wait 1 second
190
+ * ```
191
+ */
192
+ export const delay = (ms: number): Promise<void> =>
193
+ new Promise(resolve => setTimeout(resolve, ms));
194
+
195
+ /**
196
+ * Executes a function with exponential backoff retry.
197
+ *
198
+ * @param fn - Async function to execute
199
+ * @param options - Retry options
200
+ * @returns Result of the function
201
+ * @throws Last error if all retries fail
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * const result = await withRetry(
206
+ * () => fetchData(),
207
+ * { maxRetries: 3, baseDelay: 1000 }
208
+ * );
209
+ * ```
210
+ */
211
+ export const withRetry = async <T>(
212
+ fn: () => Promise<T>,
213
+ options: {
214
+ maxRetries?: number;
215
+ baseDelay?: number;
216
+ maxDelay?: number;
217
+ shouldRetry?: (error: unknown) => boolean;
218
+ onRetry?: (error: unknown, attempt: number) => void;
219
+ } = {}
220
+ ): Promise<T> => {
221
+ const {
222
+ maxRetries = 3,
223
+ baseDelay = 1000,
224
+ maxDelay = 30000,
225
+ shouldRetry = () => true,
226
+ onRetry,
227
+ } = options;
228
+
229
+ let lastError: unknown;
230
+
231
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
232
+ try {
233
+ return await fn();
234
+ } catch (error) {
235
+ lastError = error;
236
+
237
+ if (attempt === maxRetries || !shouldRetry(error)) {
238
+ throw error;
239
+ }
240
+
241
+ const delayMs = Math.min(baseDelay * Math.pow(2, attempt), maxDelay);
242
+ onRetry?.(error, attempt + 1);
243
+ await delay(delayMs);
244
+ }
245
+ }
246
+
247
+ throw lastError;
248
+ };