@oxyhq/services 5.4.0 → 5.4.2

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 (395) hide show
  1. package/package.json +3 -2
  2. package/src/__tests__/ui/screens/AccountSettingsScreen.test.tsx +8 -8
  3. package/src/core/index.ts +103 -0
  4. package/src/lib/sonner.ts +9 -4
  5. package/src/ui/components/OxyProvider.tsx +5 -5
  6. package/src/ui/context/OxyContext.tsx +61 -41
  7. package/src/ui/screens/AccountManagementDemo.tsx +1 -1
  8. package/src/ui/screens/AccountOverviewScreen.tsx +44 -26
  9. package/src/ui/screens/AccountSettingsScreen.tsx +25 -19
  10. package/src/ui/screens/AppInfoScreen.tsx +5 -5
  11. package/src/ui/screens/FileManagementScreen.tsx +246 -211
  12. package/src/ui/screens/SignInScreen.tsx +382 -326
  13. package/src/ui/screens/SignUpScreen.tsx +443 -273
  14. package/src/ui/screens/karma/KarmaFAQScreen.tsx +50 -29
  15. package/lib/commonjs/assets/OxyLogo.svg +0 -1
  16. package/lib/commonjs/assets/assets/OxyLogo.svg +0 -1
  17. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
  18. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
  19. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
  20. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
  21. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
  22. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
  23. package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
  24. package/lib/commonjs/assets/assets/icons/OxyServices.tsx +0 -67
  25. package/lib/commonjs/assets/assets/icons/logo_OxyServices.svg +0 -1
  26. package/lib/commonjs/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
  27. package/lib/commonjs/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
  28. package/lib/commonjs/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
  29. package/lib/commonjs/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
  30. package/lib/commonjs/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
  31. package/lib/commonjs/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
  32. package/lib/commonjs/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
  33. package/lib/commonjs/assets/icons/OxyServices.js +0 -53
  34. package/lib/commonjs/assets/icons/OxyServices.js.map +0 -1
  35. package/lib/commonjs/assets/icons/logo_OxyServices.svg +0 -1
  36. package/lib/commonjs/constants/version.js +0 -28
  37. package/lib/commonjs/constants/version.js.map +0 -1
  38. package/lib/commonjs/core/index.js +0 -1543
  39. package/lib/commonjs/core/index.js.map +0 -1
  40. package/lib/commonjs/index.js +0 -160
  41. package/lib/commonjs/index.js.map +0 -1
  42. package/lib/commonjs/lib/react-native-polyfills.js +0 -181
  43. package/lib/commonjs/lib/react-native-polyfills.js.map +0 -1
  44. package/lib/commonjs/lib/sonner-safe.js +0 -41
  45. package/lib/commonjs/lib/sonner-safe.js.map +0 -1
  46. package/lib/commonjs/lib/sonner.js +0 -18
  47. package/lib/commonjs/lib/sonner.js.map +0 -1
  48. package/lib/commonjs/lib/sonner.web.js +0 -17
  49. package/lib/commonjs/lib/sonner.web.js.map +0 -1
  50. package/lib/commonjs/models/interfaces.js +0 -2
  51. package/lib/commonjs/models/interfaces.js.map +0 -1
  52. package/lib/commonjs/models/secureSession.js +0 -2
  53. package/lib/commonjs/models/secureSession.js.map +0 -1
  54. package/lib/commonjs/node/index.js +0 -54
  55. package/lib/commonjs/node/index.js.map +0 -1
  56. package/lib/commonjs/package.json +0 -1
  57. package/lib/commonjs/ui/components/Avatar.js +0 -98
  58. package/lib/commonjs/ui/components/Avatar.js.map +0 -1
  59. package/lib/commonjs/ui/components/FollowButton.js +0 -246
  60. package/lib/commonjs/ui/components/FollowButton.js.map +0 -1
  61. package/lib/commonjs/ui/components/FontLoader.js +0 -181
  62. package/lib/commonjs/ui/components/FontLoader.js.map +0 -1
  63. package/lib/commonjs/ui/components/GroupedItem.js +0 -109
  64. package/lib/commonjs/ui/components/GroupedItem.js.map +0 -1
  65. package/lib/commonjs/ui/components/GroupedSection.js +0 -33
  66. package/lib/commonjs/ui/components/GroupedSection.js.map +0 -1
  67. package/lib/commonjs/ui/components/OxyLogo.js +0 -56
  68. package/lib/commonjs/ui/components/OxyLogo.js.map +0 -1
  69. package/lib/commonjs/ui/components/OxyProvider.js +0 -517
  70. package/lib/commonjs/ui/components/OxyProvider.js.map +0 -1
  71. package/lib/commonjs/ui/components/OxySignInButton.js +0 -178
  72. package/lib/commonjs/ui/components/OxySignInButton.js.map +0 -1
  73. package/lib/commonjs/ui/components/ProfileCard.js +0 -124
  74. package/lib/commonjs/ui/components/ProfileCard.js.map +0 -1
  75. package/lib/commonjs/ui/components/QuickActions.js +0 -87
  76. package/lib/commonjs/ui/components/QuickActions.js.map +0 -1
  77. package/lib/commonjs/ui/components/Section.js +0 -36
  78. package/lib/commonjs/ui/components/Section.js.map +0 -1
  79. package/lib/commonjs/ui/components/SectionTitle.js +0 -35
  80. package/lib/commonjs/ui/components/SectionTitle.js.map +0 -1
  81. package/lib/commonjs/ui/components/bottomSheet/index.js +0 -37
  82. package/lib/commonjs/ui/components/bottomSheet/index.js.map +0 -1
  83. package/lib/commonjs/ui/components/icon/OxyIcon.js +0 -27
  84. package/lib/commonjs/ui/components/icon/OxyIcon.js.map +0 -1
  85. package/lib/commonjs/ui/components/icon/index.js +0 -14
  86. package/lib/commonjs/ui/components/icon/index.js.map +0 -1
  87. package/lib/commonjs/ui/components/index.js +0 -97
  88. package/lib/commonjs/ui/components/index.js.map +0 -1
  89. package/lib/commonjs/ui/context/OxyContext.js +0 -568
  90. package/lib/commonjs/ui/context/OxyContext.js.map +0 -1
  91. package/lib/commonjs/ui/index.js +0 -128
  92. package/lib/commonjs/ui/index.js.map +0 -1
  93. package/lib/commonjs/ui/navigation/OxyRouter.js +0 -264
  94. package/lib/commonjs/ui/navigation/OxyRouter.js.map +0 -1
  95. package/lib/commonjs/ui/navigation/types.js +0 -6
  96. package/lib/commonjs/ui/navigation/types.js.map +0 -1
  97. package/lib/commonjs/ui/screens/AccountCenterScreen.js +0 -313
  98. package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +0 -1
  99. package/lib/commonjs/ui/screens/AccountManagementDemo.js +0 -299
  100. package/lib/commonjs/ui/screens/AccountManagementDemo.js.map +0 -1
  101. package/lib/commonjs/ui/screens/AccountOverviewScreen.js +0 -837
  102. package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +0 -1
  103. package/lib/commonjs/ui/screens/AccountSettingsScreen.js +0 -836
  104. package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +0 -1
  105. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +0 -788
  106. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +0 -1
  107. package/lib/commonjs/ui/screens/AppInfoScreen.js +0 -664
  108. package/lib/commonjs/ui/screens/AppInfoScreen.js.map +0 -1
  109. package/lib/commonjs/ui/screens/BillingManagementScreen.js +0 -636
  110. package/lib/commonjs/ui/screens/BillingManagementScreen.js.map +0 -1
  111. package/lib/commonjs/ui/screens/FileManagementScreen.js +0 -2497
  112. package/lib/commonjs/ui/screens/FileManagementScreen.js.map +0 -1
  113. package/lib/commonjs/ui/screens/PremiumSubscriptionScreen.js +0 -1620
  114. package/lib/commonjs/ui/screens/PremiumSubscriptionScreen.js.map +0 -1
  115. package/lib/commonjs/ui/screens/ProfileScreen.js +0 -450
  116. package/lib/commonjs/ui/screens/ProfileScreen.js.map +0 -1
  117. package/lib/commonjs/ui/screens/SessionManagementScreen.js +0 -449
  118. package/lib/commonjs/ui/screens/SessionManagementScreen.js.map +0 -1
  119. package/lib/commonjs/ui/screens/SignInScreen.js +0 -956
  120. package/lib/commonjs/ui/screens/SignInScreen.js.map +0 -1
  121. package/lib/commonjs/ui/screens/SignUpScreen.js +0 -762
  122. package/lib/commonjs/ui/screens/SignUpScreen.js.map +0 -1
  123. package/lib/commonjs/ui/screens/karma/KarmaAboutScreen.js +0 -88
  124. package/lib/commonjs/ui/screens/karma/KarmaAboutScreen.js.map +0 -1
  125. package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js +0 -364
  126. package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js.map +0 -1
  127. package/lib/commonjs/ui/screens/karma/KarmaFAQScreen.js +0 -202
  128. package/lib/commonjs/ui/screens/karma/KarmaFAQScreen.js.map +0 -1
  129. package/lib/commonjs/ui/screens/karma/KarmaLeaderboardScreen.js +0 -148
  130. package/lib/commonjs/ui/screens/karma/KarmaLeaderboardScreen.js.map +0 -1
  131. package/lib/commonjs/ui/screens/karma/KarmaRewardsScreen.js +0 -127
  132. package/lib/commonjs/ui/screens/karma/KarmaRewardsScreen.js.map +0 -1
  133. package/lib/commonjs/ui/screens/karma/KarmaRulesScreen.js +0 -105
  134. package/lib/commonjs/ui/screens/karma/KarmaRulesScreen.js.map +0 -1
  135. package/lib/commonjs/ui/styles/FONTS.md +0 -126
  136. package/lib/commonjs/ui/styles/fonts.js +0 -84
  137. package/lib/commonjs/ui/styles/fonts.js.map +0 -1
  138. package/lib/commonjs/ui/styles/index.js +0 -28
  139. package/lib/commonjs/ui/styles/index.js.map +0 -1
  140. package/lib/commonjs/ui/styles/theme.js +0 -121
  141. package/lib/commonjs/ui/styles/theme.js.map +0 -1
  142. package/lib/commonjs/utils/deviceManager.js +0 -173
  143. package/lib/commonjs/utils/deviceManager.js.map +0 -1
  144. package/lib/commonjs/utils/index.js +0 -13
  145. package/lib/commonjs/utils/index.js.map +0 -1
  146. package/lib/commonjs/utils/polyfills.js +0 -42
  147. package/lib/commonjs/utils/polyfills.js.map +0 -1
  148. package/lib/module/assets/OxyLogo.svg +0 -1
  149. package/lib/module/assets/assets/OxyLogo.svg +0 -1
  150. package/lib/module/assets/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
  151. package/lib/module/assets/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
  152. package/lib/module/assets/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
  153. package/lib/module/assets/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
  154. package/lib/module/assets/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
  155. package/lib/module/assets/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
  156. package/lib/module/assets/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
  157. package/lib/module/assets/assets/icons/OxyServices.tsx +0 -67
  158. package/lib/module/assets/assets/icons/logo_OxyServices.svg +0 -1
  159. package/lib/module/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
  160. package/lib/module/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
  161. package/lib/module/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
  162. package/lib/module/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
  163. package/lib/module/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
  164. package/lib/module/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
  165. package/lib/module/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
  166. package/lib/module/assets/icons/OxyServices.js +0 -46
  167. package/lib/module/assets/icons/OxyServices.js.map +0 -1
  168. package/lib/module/assets/icons/logo_OxyServices.svg +0 -1
  169. package/lib/module/constants/version.js +0 -21
  170. package/lib/module/constants/version.js.map +0 -1
  171. package/lib/module/core/index.js +0 -1517
  172. package/lib/module/core/index.js.map +0 -1
  173. package/lib/module/index.js +0 -48
  174. package/lib/module/index.js.map +0 -1
  175. package/lib/module/lib/react-native-polyfills.js +0 -179
  176. package/lib/module/lib/react-native-polyfills.js.map +0 -1
  177. package/lib/module/lib/sonner-safe.js +0 -37
  178. package/lib/module/lib/sonner-safe.js.map +0 -1
  179. package/lib/module/lib/sonner.js +0 -8
  180. package/lib/module/lib/sonner.js.map +0 -1
  181. package/lib/module/lib/sonner.web.js +0 -4
  182. package/lib/module/lib/sonner.web.js.map +0 -1
  183. package/lib/module/models/interfaces.js +0 -2
  184. package/lib/module/models/interfaces.js.map +0 -1
  185. package/lib/module/models/secureSession.js +0 -2
  186. package/lib/module/models/secureSession.js.map +0 -1
  187. package/lib/module/node/index.js +0 -23
  188. package/lib/module/node/index.js.map +0 -1
  189. package/lib/module/package.json +0 -1
  190. package/lib/module/ui/components/Avatar.js +0 -93
  191. package/lib/module/ui/components/Avatar.js.map +0 -1
  192. package/lib/module/ui/components/FollowButton.js +0 -241
  193. package/lib/module/ui/components/FollowButton.js.map +0 -1
  194. package/lib/module/ui/components/FontLoader.js +0 -176
  195. package/lib/module/ui/components/FontLoader.js.map +0 -1
  196. package/lib/module/ui/components/GroupedItem.js +0 -104
  197. package/lib/module/ui/components/GroupedItem.js.map +0 -1
  198. package/lib/module/ui/components/GroupedSection.js +0 -28
  199. package/lib/module/ui/components/GroupedSection.js.map +0 -1
  200. package/lib/module/ui/components/OxyLogo.js +0 -49
  201. package/lib/module/ui/components/OxyLogo.js.map +0 -1
  202. package/lib/module/ui/components/OxyProvider.js +0 -511
  203. package/lib/module/ui/components/OxyProvider.js.map +0 -1
  204. package/lib/module/ui/components/OxySignInButton.js +0 -172
  205. package/lib/module/ui/components/OxySignInButton.js.map +0 -1
  206. package/lib/module/ui/components/ProfileCard.js +0 -119
  207. package/lib/module/ui/components/ProfileCard.js.map +0 -1
  208. package/lib/module/ui/components/QuickActions.js +0 -82
  209. package/lib/module/ui/components/QuickActions.js.map +0 -1
  210. package/lib/module/ui/components/Section.js +0 -31
  211. package/lib/module/ui/components/Section.js.map +0 -1
  212. package/lib/module/ui/components/SectionTitle.js +0 -30
  213. package/lib/module/ui/components/SectionTitle.js.map +0 -1
  214. package/lib/module/ui/components/bottomSheet/index.js +0 -5
  215. package/lib/module/ui/components/bottomSheet/index.js.map +0 -1
  216. package/lib/module/ui/components/icon/OxyIcon.js +0 -22
  217. package/lib/module/ui/components/icon/OxyIcon.js.map +0 -1
  218. package/lib/module/ui/components/icon/index.js +0 -4
  219. package/lib/module/ui/components/icon/index.js.map +0 -1
  220. package/lib/module/ui/components/index.js +0 -18
  221. package/lib/module/ui/components/index.js.map +0 -1
  222. package/lib/module/ui/context/OxyContext.js +0 -563
  223. package/lib/module/ui/context/OxyContext.js.map +0 -1
  224. package/lib/module/ui/index.js +0 -24
  225. package/lib/module/ui/index.js.map +0 -1
  226. package/lib/module/ui/navigation/OxyRouter.js +0 -257
  227. package/lib/module/ui/navigation/OxyRouter.js.map +0 -1
  228. package/lib/module/ui/navigation/types.js +0 -4
  229. package/lib/module/ui/navigation/types.js.map +0 -1
  230. package/lib/module/ui/screens/AccountCenterScreen.js +0 -308
  231. package/lib/module/ui/screens/AccountCenterScreen.js.map +0 -1
  232. package/lib/module/ui/screens/AccountManagementDemo.js +0 -296
  233. package/lib/module/ui/screens/AccountManagementDemo.js.map +0 -1
  234. package/lib/module/ui/screens/AccountOverviewScreen.js +0 -831
  235. package/lib/module/ui/screens/AccountOverviewScreen.js.map +0 -1
  236. package/lib/module/ui/screens/AccountSettingsScreen.js +0 -830
  237. package/lib/module/ui/screens/AccountSettingsScreen.js.map +0 -1
  238. package/lib/module/ui/screens/AccountSwitcherScreen.js +0 -782
  239. package/lib/module/ui/screens/AccountSwitcherScreen.js.map +0 -1
  240. package/lib/module/ui/screens/AppInfoScreen.js +0 -658
  241. package/lib/module/ui/screens/AppInfoScreen.js.map +0 -1
  242. package/lib/module/ui/screens/BillingManagementScreen.js +0 -631
  243. package/lib/module/ui/screens/BillingManagementScreen.js.map +0 -1
  244. package/lib/module/ui/screens/FileManagementScreen.js +0 -2492
  245. package/lib/module/ui/screens/FileManagementScreen.js.map +0 -1
  246. package/lib/module/ui/screens/PremiumSubscriptionScreen.js +0 -1615
  247. package/lib/module/ui/screens/PremiumSubscriptionScreen.js.map +0 -1
  248. package/lib/module/ui/screens/ProfileScreen.js +0 -444
  249. package/lib/module/ui/screens/ProfileScreen.js.map +0 -1
  250. package/lib/module/ui/screens/SessionManagementScreen.js +0 -444
  251. package/lib/module/ui/screens/SessionManagementScreen.js.map +0 -1
  252. package/lib/module/ui/screens/SignInScreen.js +0 -950
  253. package/lib/module/ui/screens/SignInScreen.js.map +0 -1
  254. package/lib/module/ui/screens/SignUpScreen.js +0 -755
  255. package/lib/module/ui/screens/SignUpScreen.js.map +0 -1
  256. package/lib/module/ui/screens/karma/KarmaAboutScreen.js +0 -83
  257. package/lib/module/ui/screens/karma/KarmaAboutScreen.js.map +0 -1
  258. package/lib/module/ui/screens/karma/KarmaCenterScreen.js +0 -358
  259. package/lib/module/ui/screens/karma/KarmaCenterScreen.js.map +0 -1
  260. package/lib/module/ui/screens/karma/KarmaFAQScreen.js +0 -197
  261. package/lib/module/ui/screens/karma/KarmaFAQScreen.js.map +0 -1
  262. package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js +0 -142
  263. package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js.map +0 -1
  264. package/lib/module/ui/screens/karma/KarmaRewardsScreen.js +0 -122
  265. package/lib/module/ui/screens/karma/KarmaRewardsScreen.js.map +0 -1
  266. package/lib/module/ui/screens/karma/KarmaRulesScreen.js +0 -100
  267. package/lib/module/ui/screens/karma/KarmaRulesScreen.js.map +0 -1
  268. package/lib/module/ui/styles/FONTS.md +0 -126
  269. package/lib/module/ui/styles/fonts.js +0 -81
  270. package/lib/module/ui/styles/fonts.js.map +0 -1
  271. package/lib/module/ui/styles/index.js +0 -5
  272. package/lib/module/ui/styles/index.js.map +0 -1
  273. package/lib/module/ui/styles/theme.js +0 -114
  274. package/lib/module/ui/styles/theme.js.map +0 -1
  275. package/lib/module/utils/deviceManager.js +0 -167
  276. package/lib/module/utils/deviceManager.js.map +0 -1
  277. package/lib/module/utils/index.js +0 -4
  278. package/lib/module/utils/index.js.map +0 -1
  279. package/lib/module/utils/polyfills.js +0 -36
  280. package/lib/module/utils/polyfills.js.map +0 -1
  281. package/lib/typescript/assets/icons/OxyServices.d.ts +0 -29
  282. package/lib/typescript/assets/icons/OxyServices.d.ts.map +0 -1
  283. package/lib/typescript/constants/version.d.ts +0 -14
  284. package/lib/typescript/constants/version.d.ts.map +0 -1
  285. package/lib/typescript/core/index.d.ts +0 -563
  286. package/lib/typescript/core/index.d.ts.map +0 -1
  287. package/lib/typescript/index.d.ts +0 -20
  288. package/lib/typescript/index.d.ts.map +0 -1
  289. package/lib/typescript/lib/react-native-polyfills.d.ts +0 -8
  290. package/lib/typescript/lib/react-native-polyfills.d.ts.map +0 -1
  291. package/lib/typescript/lib/sonner-safe.d.ts +0 -11
  292. package/lib/typescript/lib/sonner-safe.d.ts.map +0 -1
  293. package/lib/typescript/lib/sonner.d.ts +0 -3
  294. package/lib/typescript/lib/sonner.d.ts.map +0 -1
  295. package/lib/typescript/lib/sonner.web.d.ts +0 -2
  296. package/lib/typescript/lib/sonner.web.d.ts.map +0 -1
  297. package/lib/typescript/models/interfaces.d.ts +0 -179
  298. package/lib/typescript/models/interfaces.d.ts.map +0 -1
  299. package/lib/typescript/models/secureSession.d.ts +0 -27
  300. package/lib/typescript/models/secureSession.d.ts.map +0 -1
  301. package/lib/typescript/node/index.d.ts +0 -11
  302. package/lib/typescript/node/index.d.ts.map +0 -1
  303. package/lib/typescript/ui/components/Avatar.d.ts +0 -62
  304. package/lib/typescript/ui/components/Avatar.d.ts.map +0 -1
  305. package/lib/typescript/ui/components/FollowButton.d.ts +0 -92
  306. package/lib/typescript/ui/components/FollowButton.d.ts.map +0 -1
  307. package/lib/typescript/ui/components/FontLoader.d.ts +0 -15
  308. package/lib/typescript/ui/components/FontLoader.d.ts.map +0 -1
  309. package/lib/typescript/ui/components/GroupedItem.d.ts +0 -17
  310. package/lib/typescript/ui/components/GroupedItem.d.ts.map +0 -1
  311. package/lib/typescript/ui/components/GroupedSection.d.ts +0 -19
  312. package/lib/typescript/ui/components/GroupedSection.d.ts.map +0 -1
  313. package/lib/typescript/ui/components/OxyLogo.d.ts +0 -29
  314. package/lib/typescript/ui/components/OxyLogo.d.ts.map +0 -1
  315. package/lib/typescript/ui/components/OxyProvider.d.ts +0 -12
  316. package/lib/typescript/ui/components/OxyProvider.d.ts.map +0 -1
  317. package/lib/typescript/ui/components/OxySignInButton.d.ts +0 -70
  318. package/lib/typescript/ui/components/OxySignInButton.d.ts.map +0 -1
  319. package/lib/typescript/ui/components/ProfileCard.d.ts +0 -20
  320. package/lib/typescript/ui/components/ProfileCard.d.ts.map +0 -1
  321. package/lib/typescript/ui/components/QuickActions.d.ts +0 -15
  322. package/lib/typescript/ui/components/QuickActions.d.ts.map +0 -1
  323. package/lib/typescript/ui/components/Section.d.ts +0 -11
  324. package/lib/typescript/ui/components/Section.d.ts.map +0 -1
  325. package/lib/typescript/ui/components/SectionTitle.d.ts +0 -9
  326. package/lib/typescript/ui/components/SectionTitle.d.ts.map +0 -1
  327. package/lib/typescript/ui/components/bottomSheet/index.d.ts +0 -4
  328. package/lib/typescript/ui/components/bottomSheet/index.d.ts.map +0 -1
  329. package/lib/typescript/ui/components/icon/OxyIcon.d.ts +0 -10
  330. package/lib/typescript/ui/components/icon/OxyIcon.d.ts.map +0 -1
  331. package/lib/typescript/ui/components/icon/index.d.ts +0 -3
  332. package/lib/typescript/ui/components/icon/index.d.ts.map +0 -1
  333. package/lib/typescript/ui/components/index.d.ts +0 -13
  334. package/lib/typescript/ui/components/index.d.ts.map +0 -1
  335. package/lib/typescript/ui/context/OxyContext.d.ts +0 -42
  336. package/lib/typescript/ui/context/OxyContext.d.ts.map +0 -1
  337. package/lib/typescript/ui/index.d.ts +0 -15
  338. package/lib/typescript/ui/index.d.ts.map +0 -1
  339. package/lib/typescript/ui/navigation/OxyRouter.d.ts +0 -5
  340. package/lib/typescript/ui/navigation/OxyRouter.d.ts.map +0 -1
  341. package/lib/typescript/ui/navigation/types.d.ts +0 -116
  342. package/lib/typescript/ui/navigation/types.d.ts.map +0 -1
  343. package/lib/typescript/ui/screens/AccountCenterScreen.d.ts +0 -5
  344. package/lib/typescript/ui/screens/AccountCenterScreen.d.ts.map +0 -1
  345. package/lib/typescript/ui/screens/AccountManagementDemo.d.ts +0 -8
  346. package/lib/typescript/ui/screens/AccountManagementDemo.d.ts.map +0 -1
  347. package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts +0 -5
  348. package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts.map +0 -1
  349. package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts +0 -5
  350. package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +0 -1
  351. package/lib/typescript/ui/screens/AccountSwitcherScreen.d.ts +0 -5
  352. package/lib/typescript/ui/screens/AccountSwitcherScreen.d.ts.map +0 -1
  353. package/lib/typescript/ui/screens/AppInfoScreen.d.ts +0 -5
  354. package/lib/typescript/ui/screens/AppInfoScreen.d.ts.map +0 -1
  355. package/lib/typescript/ui/screens/BillingManagementScreen.d.ts +0 -5
  356. package/lib/typescript/ui/screens/BillingManagementScreen.d.ts.map +0 -1
  357. package/lib/typescript/ui/screens/FileManagementScreen.d.ts +0 -8
  358. package/lib/typescript/ui/screens/FileManagementScreen.d.ts.map +0 -1
  359. package/lib/typescript/ui/screens/PremiumSubscriptionScreen.d.ts +0 -5
  360. package/lib/typescript/ui/screens/PremiumSubscriptionScreen.d.ts.map +0 -1
  361. package/lib/typescript/ui/screens/ProfileScreen.d.ts +0 -9
  362. package/lib/typescript/ui/screens/ProfileScreen.d.ts.map +0 -1
  363. package/lib/typescript/ui/screens/SessionManagementScreen.d.ts +0 -5
  364. package/lib/typescript/ui/screens/SessionManagementScreen.d.ts.map +0 -1
  365. package/lib/typescript/ui/screens/SignInScreen.d.ts +0 -5
  366. package/lib/typescript/ui/screens/SignInScreen.d.ts.map +0 -1
  367. package/lib/typescript/ui/screens/SignUpScreen.d.ts +0 -5
  368. package/lib/typescript/ui/screens/SignUpScreen.d.ts.map +0 -1
  369. package/lib/typescript/ui/screens/karma/KarmaAboutScreen.d.ts +0 -5
  370. package/lib/typescript/ui/screens/karma/KarmaAboutScreen.d.ts.map +0 -1
  371. package/lib/typescript/ui/screens/karma/KarmaCenterScreen.d.ts +0 -5
  372. package/lib/typescript/ui/screens/karma/KarmaCenterScreen.d.ts.map +0 -1
  373. package/lib/typescript/ui/screens/karma/KarmaFAQScreen.d.ts +0 -5
  374. package/lib/typescript/ui/screens/karma/KarmaFAQScreen.d.ts.map +0 -1
  375. package/lib/typescript/ui/screens/karma/KarmaLeaderboardScreen.d.ts +0 -5
  376. package/lib/typescript/ui/screens/karma/KarmaLeaderboardScreen.d.ts.map +0 -1
  377. package/lib/typescript/ui/screens/karma/KarmaRewardsScreen.d.ts +0 -5
  378. package/lib/typescript/ui/screens/karma/KarmaRewardsScreen.d.ts.map +0 -1
  379. package/lib/typescript/ui/screens/karma/KarmaRulesScreen.d.ts +0 -5
  380. package/lib/typescript/ui/screens/karma/KarmaRulesScreen.d.ts.map +0 -1
  381. package/lib/typescript/ui/styles/fonts.d.ts +0 -21
  382. package/lib/typescript/ui/styles/fonts.d.ts.map +0 -1
  383. package/lib/typescript/ui/styles/index.d.ts +0 -3
  384. package/lib/typescript/ui/styles/index.d.ts.map +0 -1
  385. package/lib/typescript/ui/styles/theme.d.ts +0 -68
  386. package/lib/typescript/ui/styles/theme.d.ts.map +0 -1
  387. package/lib/typescript/utils/deviceManager.d.ts +0 -66
  388. package/lib/typescript/utils/deviceManager.d.ts.map +0 -1
  389. package/lib/typescript/utils/index.d.ts +0 -3
  390. package/lib/typescript/utils/index.d.ts.map +0 -1
  391. package/lib/typescript/utils/polyfills.d.ts +0 -6
  392. package/lib/typescript/utils/polyfills.d.ts.map +0 -1
  393. package/src/lib/react-native-polyfills.ts +0 -219
  394. package/src/lib/sonner-safe.ts +0 -37
  395. package/src/lib/sonner.web.ts +0 -1
@@ -1,1517 +0,0 @@
1
- "use strict";
2
-
3
- import axios from 'axios';
4
- import { jwtDecode } from 'jwt-decode';
5
- import { getFormDataConstructor } from '../utils/polyfills';
6
- let NodeFormData = null;
7
-
8
- // Check if we're in Node.js environment
9
- if (typeof window === 'undefined') {
10
- try {
11
- NodeFormData = require('form-data');
12
- } catch (e) {
13
- console.warn('form-data module not found, file uploads from Buffer may fail in Node.js');
14
- }
15
- }
16
-
17
- // Import secure session types
18
-
19
- /**
20
- * Default cloud URL for Oxy services, cloud is where the user files are. (e.g. images, videos, etc.). Not the API.
21
- */
22
- export const OXY_CLOUD_URL = 'https://cloud.oxy.so';
23
-
24
- // Export device management utilities
25
- export { DeviceManager, DeviceFingerprint, StoredDeviceInfo } from '../utils/deviceManager';
26
- /**
27
- * OxyServices - Client library for interacting with the Oxy API
28
- */
29
- export class OxyServices {
30
- accessToken = null;
31
- refreshToken = null;
32
- refreshPromise = null;
33
-
34
- /**
35
- * Creates a new instance of the OxyServices client
36
- * @param config - Configuration for the client
37
- */
38
- constructor(config) {
39
- this.client = axios.create({
40
- baseURL: config.baseURL,
41
- timeout: 10000 // 10 second timeout
42
- });
43
-
44
- // Interceptor for adding auth header and handling token refresh
45
- this.client.interceptors.request.use(async req => {
46
- if (!this.accessToken) {
47
- return req;
48
- } // Check if token is expired and refresh if needed
49
- try {
50
- const decoded = jwtDecode(this.accessToken);
51
- const currentTime = Math.floor(Date.now() / 1000);
52
-
53
- // If token expires in less than 60 seconds, refresh it
54
- if (decoded.exp - currentTime < 60) {
55
- await this.refreshTokens();
56
- }
57
- } catch (error) {
58
- // If token can't be decoded, continue with request and let server handle it
59
- console.warn('Error decoding JWT token', error);
60
- }
61
- req.headers = req.headers || {};
62
- req.headers.Authorization = `Bearer ${this.accessToken}`;
63
- return req;
64
- });
65
-
66
- // Response interceptor for handling errors
67
- this.client.interceptors.response.use(response => response, async error => {
68
- const originalRequest = error.config;
69
- // If the error is due to an expired token and we haven't tried refreshing yet
70
- if (error.response?.status === 401 && this.refreshToken && originalRequest && !originalRequest.headers?.['X-Retry-After-Refresh']) {
71
- try {
72
- await this.refreshTokens();
73
- // Retry the original request with new token
74
- const newRequest = {
75
- ...originalRequest
76
- };
77
- if (newRequest.headers) {
78
- newRequest.headers.Authorization = `Bearer ${this.accessToken}`;
79
- newRequest.headers['X-Retry-After-Refresh'] = 'true';
80
- }
81
- return this.client(newRequest);
82
- } catch (refreshError) {
83
- // If refresh fails, force user to login again
84
- this.clearTokens();
85
- return Promise.reject(refreshError);
86
- }
87
- }
88
-
89
- // Format error response
90
- const apiError = {
91
- message: error.response?.data?.error || error.response?.data?.message || 'An unknown error occurred',
92
- code: error.response?.data?.code || 'UNKNOWN_ERROR',
93
- status: error.response?.status || 500,
94
- details: error.response?.data
95
- };
96
-
97
- // If the error is an invalid session, clear tokens
98
- if (apiError.code === 'INVALID_SESSION' || apiError.message === 'Invalid session') {
99
- this.clearTokens();
100
- }
101
- return Promise.reject(apiError);
102
- });
103
- }
104
-
105
- /**
106
- * Gets the currently authenticated user ID from the token
107
- * @returns The user ID or null if not authenticated
108
- */
109
- getCurrentUserId() {
110
- if (!this.accessToken) return null;
111
- try {
112
- const decoded = jwtDecode(this.accessToken);
113
-
114
- // Check for both userId (preferred) and id (fallback) for compatibility
115
- return decoded.userId || decoded.id || null;
116
- } catch (error) {
117
- return null;
118
- }
119
- }
120
-
121
- /**
122
- * Checks if the user is currently authenticated
123
- * @returns Boolean indicating authentication status
124
- */
125
- isAuthenticated() {
126
- return this.accessToken !== null;
127
- }
128
-
129
- /**
130
- * Sets authentication tokens directly (useful for initializing from storage)
131
- * @param accessToken - JWT access token
132
- * @param refreshToken - Refresh token for getting new access tokens
133
- */
134
- setTokens(accessToken, refreshToken) {
135
- this.accessToken = accessToken;
136
- this.refreshToken = refreshToken;
137
- }
138
-
139
- /**
140
- * Clears all authentication tokens
141
- */
142
- clearTokens() {
143
- this.accessToken = null;
144
- this.refreshToken = null;
145
- }
146
-
147
- /**
148
- * Sign up a new user
149
- * @param username - Desired username
150
- * @param email - User's email address
151
- * @param password - User's password
152
- * @returns Object containing the message, token and user data
153
- */
154
- async signUp(username, email, password) {
155
- try {
156
- const res = await this.client.post('/auth/signup', {
157
- username,
158
- email,
159
- password
160
- });
161
- const {
162
- message,
163
- token,
164
- user
165
- } = res.data;
166
- this.accessToken = token;
167
- return {
168
- message,
169
- token,
170
- user
171
- };
172
- } catch (error) {
173
- throw this.handleError(error);
174
- }
175
- }
176
-
177
- /**
178
- * Log in and store tokens
179
- * @param username - User's username or email
180
- * @param password - User's password
181
- * @returns Login response containing tokens and user data
182
- */
183
- async login(username, password) {
184
- try {
185
- const res = await this.client.post('/auth/login', {
186
- username,
187
- password
188
- });
189
- const {
190
- accessToken,
191
- refreshToken,
192
- user
193
- } = res.data;
194
- this.accessToken = accessToken;
195
- this.refreshToken = refreshToken;
196
- return {
197
- accessToken,
198
- refreshToken,
199
- user
200
- };
201
- } catch (error) {
202
- throw this.handleError(error);
203
- }
204
- }
205
-
206
- /**
207
- * Log out user
208
- */
209
- async logout() {
210
- if (!this.refreshToken) return;
211
- try {
212
- await this.client.post('/auth/logout', {
213
- refreshToken: this.refreshToken
214
- });
215
- } catch (error) {
216
- console.warn('Error during logout', error);
217
- } finally {
218
- this.accessToken = null;
219
- this.refreshToken = null;
220
- }
221
- }
222
-
223
- /**
224
- * Refresh access and refresh tokens
225
- * @returns New tokens
226
- */
227
- async refreshTokens() {
228
- if (!this.refreshToken) {
229
- throw new Error('No refresh token available');
230
- }
231
-
232
- // If a refresh is already in progress, return that promise
233
- if (this.refreshPromise) {
234
- return this.refreshPromise;
235
- }
236
-
237
- // Create a new refresh promise
238
- this.refreshPromise = (async () => {
239
- try {
240
- const res = await this.client.post('/auth/refresh', {
241
- refreshToken: this.refreshToken
242
- });
243
- const {
244
- accessToken,
245
- refreshToken
246
- } = res.data;
247
- this.accessToken = accessToken;
248
- this.refreshToken = refreshToken;
249
- return {
250
- accessToken,
251
- refreshToken
252
- };
253
- } catch (error) {
254
- this.accessToken = null;
255
- this.refreshToken = null;
256
- throw this.handleError(error);
257
- } finally {
258
- this.refreshPromise = null;
259
- }
260
- })();
261
- return this.refreshPromise;
262
- }
263
-
264
- /**
265
- * Validate current access token
266
- * @returns Boolean indicating if the token is valid
267
- */
268
- async validate() {
269
- try {
270
- const res = await this.client.get('/auth/validate');
271
- return res.data.valid;
272
- } catch (error) {
273
- return false;
274
- }
275
- }
276
-
277
- /* Session Management Methods */
278
-
279
- /**
280
- * Get active sessions for the authenticated user
281
- * @returns Array of active session objects
282
- */
283
- async getUserSessions() {
284
- try {
285
- const res = await this.client.get('/sessions');
286
- return res.data;
287
- } catch (error) {
288
- throw this.handleError(error);
289
- }
290
- }
291
-
292
- /**
293
- * Logout from a specific session
294
- * @param sessionId - The session ID to logout from
295
- * @returns Success status
296
- */
297
- async logoutSession(sessionId) {
298
- try {
299
- const res = await this.client.delete(`/sessions/${sessionId}`);
300
- return res.data;
301
- } catch (error) {
302
- throw this.handleError(error);
303
- }
304
- }
305
-
306
- /**
307
- * Logout from all other sessions (keep current session active)
308
- * @returns Success status
309
- */
310
- async logoutOtherSessions() {
311
- try {
312
- const res = await this.client.post('/sessions/logout-others');
313
- return res.data;
314
- } catch (error) {
315
- throw this.handleError(error);
316
- }
317
- }
318
-
319
- /**
320
- * Logout from all sessions
321
- * @returns Success status
322
- */
323
- async logoutAllSessions() {
324
- try {
325
- const res = await this.client.post('/sessions/logout-all');
326
- return res.data;
327
- } catch (error) {
328
- throw this.handleError(error);
329
- }
330
- }
331
-
332
- /**
333
- * Get device sessions for a specific session ID
334
- * @param sessionId - The session ID to get device sessions for
335
- * @param deviceId - Optional device ID filter
336
- * @returns Array of device sessions
337
- */
338
- async getDeviceSessions(sessionId, deviceId) {
339
- try {
340
- const params = deviceId ? {
341
- deviceId
342
- } : {};
343
- const res = await this.client.get(`/secure-session/device/sessions/${sessionId}`, {
344
- params
345
- });
346
-
347
- // Map backend response to frontend interface
348
- return (res.data.sessions || []).map(session => ({
349
- sessionId: session.sessionId,
350
- deviceId: res.data.deviceId || '',
351
- deviceName: session.deviceInfo?.deviceName || 'Unknown Device',
352
- isActive: true,
353
- // All returned sessions are active
354
- lastActive: session.lastActive,
355
- expiresAt: session.expiresAt || new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(),
356
- isCurrent: session.sessionId === sessionId,
357
- user: session.user,
358
- createdAt: session.createdAt
359
- }));
360
- } catch (error) {
361
- throw this.handleError(error);
362
- }
363
- }
364
-
365
- /**
366
- * Logout all device sessions for a specific device
367
- * @param sessionId - The session ID
368
- * @param deviceId - Optional device ID (uses current session's device if not provided)
369
- * @param excludeCurrent - Whether to exclude the current session from logout
370
- * @returns Logout response
371
- */
372
- async logoutAllDeviceSessions(sessionId, deviceId, excludeCurrent) {
373
- try {
374
- const data = {};
375
- if (deviceId) data.deviceId = deviceId;
376
- if (excludeCurrent !== undefined) data.excludeCurrent = excludeCurrent;
377
- const res = await this.client.post(`/secure-session/device/logout-all/${sessionId}`, data);
378
- return res.data;
379
- } catch (error) {
380
- throw this.handleError(error);
381
- }
382
- }
383
-
384
- /**
385
- * Update device name for a session
386
- * @param sessionId - The session ID
387
- * @param deviceName - The new device name
388
- * @returns Update response
389
- */
390
- async updateDeviceName(sessionId, deviceName) {
391
- try {
392
- const res = await this.client.put(`/secure-session/device/name/${sessionId}`, {
393
- deviceName
394
- });
395
- return res.data;
396
- } catch (error) {
397
- throw this.handleError(error);
398
- }
399
- }
400
-
401
- /* Profile Methods */
402
-
403
- /**
404
- * Fetch profile by username
405
- * @param username - The username to look up
406
- * @returns User profile data
407
- */
408
- async getProfileByUsername(username) {
409
- try {
410
- const res = await this.client.get(`/profiles/username/${username}`);
411
- return res.data;
412
- } catch (error) {
413
- throw this.handleError(error);
414
- }
415
- }
416
-
417
- /**
418
- * Search profiles
419
- * @param query - Search query string
420
- * @param limit - Maximum number of results to return
421
- * @param offset - Number of results to skip for pagination
422
- * @returns Array of matching user profiles
423
- */
424
- async searchProfiles(query, limit, offset) {
425
- try {
426
- const params = {
427
- query
428
- };
429
- if (limit !== undefined) params.limit = limit;
430
- if (offset !== undefined) params.offset = offset;
431
- const res = await this.client.get('/profiles/search', {
432
- params
433
- });
434
- return res.data;
435
- } catch (error) {
436
- throw this.handleError(error);
437
- }
438
- }
439
-
440
- /**
441
- * Get recommended profiles for the authenticated user
442
- * @returns Array of recommended profiles
443
- */
444
- async getProfileRecommendations() {
445
- try {
446
- const res = await this.client.get('/profiles/recommendations');
447
- return res.data;
448
- } catch (error) {
449
- throw this.handleError(error);
450
- }
451
- }
452
-
453
- /* User Methods */
454
-
455
- /**
456
- * Get general user by ID
457
- * @param userId - The user ID to look up
458
- * @returns User data
459
- */
460
- async getUserById(userId) {
461
- try {
462
- const res = await this.client.get(`/users/${userId}`);
463
- return res.data;
464
- } catch (error) {
465
- throw this.handleError(error);
466
- }
467
- }
468
-
469
- /**
470
- * Update user profile (requires auth)
471
- * @param userId - User ID to update (must match authenticated user or have admin rights)
472
- * @param updates - Object containing fields to update
473
- * @returns Updated user data
474
- */
475
- async updateUser(userId, updates) {
476
- try {
477
- const res = await this.client.put(`/users/${userId}`, updates);
478
- return res.data;
479
- } catch (error) {
480
- throw this.handleError(error);
481
- }
482
- }
483
-
484
- /**
485
- * Follow a user
486
- * @param userId - User ID to follow
487
- * @returns Status of the follow operation
488
- */
489
- async followUser(userId) {
490
- try {
491
- const res = await this.client.post(`/users/${userId}/follow`);
492
- return res.data;
493
- } catch (error) {
494
- throw this.handleError(error);
495
- }
496
- }
497
-
498
- /**
499
- * Unfollow a user
500
- * @param userId - User ID to unfollow
501
- * @returns Status of the unfollow operation
502
- */
503
- async unfollowUser(userId) {
504
- try {
505
- const res = await this.client.delete(`/users/${userId}/follow`);
506
- return res.data;
507
- } catch (error) {
508
- throw this.handleError(error);
509
- }
510
- }
511
-
512
- /**
513
- * Get all followers of a user
514
- * @param userId - User ID to get followers for
515
- * @param limit - Maximum number of followers to return
516
- * @param offset - Number of followers to skip for pagination
517
- * @returns Array of users who follow the specified user and pagination info
518
- */
519
- async getUserFollowers(userId, limit, offset) {
520
- try {
521
- const params = {};
522
- if (limit !== undefined) params.limit = limit;
523
- if (offset !== undefined) params.offset = offset;
524
- const res = await this.client.get(`/users/${userId}/followers`, {
525
- params
526
- });
527
- return res.data;
528
- } catch (error) {
529
- throw this.handleError(error);
530
- }
531
- }
532
-
533
- /**
534
- * Get all users that a user is following
535
- * @param userId - User ID to get following list for
536
- * @param limit - Maximum number of users to return
537
- * @param offset - Number of users to skip for pagination
538
- * @returns Array of users the specified user follows and pagination info
539
- */
540
- async getUserFollowing(userId, limit, offset) {
541
- try {
542
- const params = {};
543
- if (limit !== undefined) params.limit = limit;
544
- if (offset !== undefined) params.offset = offset;
545
- const res = await this.client.get(`/users/${userId}/following`, {
546
- params
547
- });
548
- return res.data;
549
- } catch (error) {
550
- throw this.handleError(error);
551
- }
552
- }
553
-
554
- /* Notification Methods */
555
-
556
- /**
557
- * Fetch all notifications for the authenticated user
558
- * @returns Array of notifications
559
- */
560
- async getNotifications() {
561
- try {
562
- const res = await this.client.get('/notifications');
563
- return res.data;
564
- } catch (error) {
565
- throw this.handleError(error);
566
- }
567
- }
568
-
569
- /**
570
- * Get count of unread notifications
571
- * @returns Number of unread notifications
572
- */
573
- async getUnreadCount() {
574
- try {
575
- const res = await this.client.get('/notifications/unread-count');
576
- return res.data;
577
- } catch (error) {
578
- throw this.handleError(error);
579
- }
580
- }
581
-
582
- /**
583
- * Create a new notification (admin use)
584
- * @param data - Notification data
585
- * @returns Created notification
586
- */
587
- async createNotification(data) {
588
- try {
589
- const res = await this.client.post('/notifications', data);
590
- return res.data;
591
- } catch (error) {
592
- throw this.handleError(error);
593
- }
594
- }
595
-
596
- /**
597
- * Mark a single notification as read
598
- * @param notificationId - ID of notification to mark as read
599
- */
600
- async markNotificationAsRead(notificationId) {
601
- try {
602
- await this.client.put(`/notifications/${notificationId}/read`);
603
- } catch (error) {
604
- throw this.handleError(error);
605
- }
606
- }
607
-
608
- /**
609
- * Mark all notifications as read
610
- */
611
- async markAllNotificationsAsRead() {
612
- try {
613
- await this.client.put('/notifications/read-all');
614
- } catch (error) {
615
- throw this.handleError(error);
616
- }
617
- }
618
-
619
- /**
620
- * Delete a notification
621
- * @param notificationId - ID of notification to delete
622
- */
623
- async deleteNotification(notificationId) {
624
- try {
625
- await this.client.delete(`/notifications/${notificationId}`);
626
- } catch (error) {
627
- throw this.handleError(error);
628
- }
629
- }
630
-
631
- /* Payment Methods */
632
-
633
- /**
634
- * Process a payment
635
- * @param data - Payment data including user ID, plan, and payment method
636
- * @returns Payment result with transaction ID
637
- */
638
- async processPayment(data) {
639
- try {
640
- const res = await this.client.post('/payments/process', data);
641
- return res.data;
642
- } catch (error) {
643
- throw this.handleError(error);
644
- }
645
- }
646
-
647
- /**
648
- * Validate a payment method
649
- * @param paymentMethod - Payment method to validate
650
- * @returns Object indicating if the payment method is valid
651
- */
652
- async validatePaymentMethod(paymentMethod) {
653
- try {
654
- const res = await this.client.post('/payments/validate', {
655
- paymentMethod
656
- });
657
- return res.data;
658
- } catch (error) {
659
- throw this.handleError(error);
660
- }
661
- }
662
-
663
- /**
664
- * Get saved payment methods for a user
665
- * @param userId - User ID to get payment methods for
666
- * @returns Array of payment methods
667
- */
668
- async getPaymentMethods(userId) {
669
- try {
670
- const res = await this.client.get(`/payments/methods/${userId}`);
671
- return res.data;
672
- } catch (error) {
673
- throw this.handleError(error);
674
- }
675
- }
676
-
677
- /* Analytics Methods */
678
-
679
- /**
680
- * Get analytics data
681
- * @param userId - User ID to get analytics for
682
- * @param period - Time period for analytics (e.g., "day", "week", "month")
683
- * @returns Analytics data
684
- */
685
- async getAnalytics(userId, period) {
686
- try {
687
- const params = {
688
- userID: userId
689
- };
690
- if (period) params.period = period;
691
- const res = await this.client.get('/analytics', {
692
- params
693
- });
694
- return res.data;
695
- } catch (error) {
696
- throw this.handleError(error);
697
- }
698
- }
699
-
700
- /**
701
- * Update analytics (internal use)
702
- * @param userId - User ID to update analytics for
703
- * @param type - Type of analytics to update
704
- * @param data - Analytics data to update
705
- * @returns Message indicating success
706
- */
707
- async updateAnalytics(userId, type, data) {
708
- try {
709
- const res = await this.client.post('/analytics/update', {
710
- userID: userId,
711
- type,
712
- data
713
- });
714
- return res.data;
715
- } catch (error) {
716
- throw this.handleError(error);
717
- }
718
- }
719
-
720
- /**
721
- * Get content viewers analytics
722
- * @param userId - User ID to get viewer data for
723
- * @param period - Time period for analytics
724
- * @returns Array of content viewer data
725
- */
726
- async getContentViewers(userId, period) {
727
- try {
728
- const params = {
729
- userID: userId
730
- };
731
- if (period) params.period = period;
732
- const res = await this.client.get('/analytics/viewers', {
733
- params
734
- });
735
- return res.data;
736
- } catch (error) {
737
- throw this.handleError(error);
738
- }
739
- }
740
-
741
- /**
742
- * Get follower analytics details
743
- * @param userId - User ID to get follower data for
744
- * @param period - Time period for follower data
745
- * @returns Follower details
746
- */
747
- async getFollowerDetails(userId, period) {
748
- try {
749
- const params = {
750
- userID: userId
751
- };
752
- if (period) params.period = period;
753
- const res = await this.client.get('/analytics/followers', {
754
- params
755
- });
756
- return res.data;
757
- } catch (error) {
758
- throw this.handleError(error);
759
- }
760
- }
761
-
762
- /* Wallet Methods */
763
-
764
- /**
765
- * Get wallet info
766
- * @param userId - User ID to get wallet for
767
- * @returns Wallet data
768
- */
769
- async getWallet(userId) {
770
- try {
771
- const res = await this.client.get(`/wallet/${userId}`);
772
- return res.data;
773
- } catch (error) {
774
- throw this.handleError(error);
775
- }
776
- }
777
-
778
- /**
779
- * Get transaction history
780
- * @param userId - User ID to get transactions for
781
- * @param limit - Maximum number of transactions to return
782
- * @param offset - Number of transactions to skip for pagination
783
- * @returns Array of transactions and pagination info
784
- */
785
- async getTransactionHistory(userId, limit, offset) {
786
- try {
787
- const params = {};
788
- if (limit !== undefined) params.limit = limit;
789
- if (offset !== undefined) params.offset = offset;
790
- const res = await this.client.get(`/wallet/transactions/${userId}`, {
791
- params
792
- });
793
- return res.data;
794
- } catch (error) {
795
- throw this.handleError(error);
796
- }
797
- }
798
-
799
- /**
800
- * Get a specific transaction
801
- * @param transactionId - ID of transaction to retrieve
802
- * @returns Transaction data
803
- */
804
- async getTransaction(transactionId) {
805
- try {
806
- const res = await this.client.get(`/wallet/transaction/${transactionId}`);
807
- return res.data;
808
- } catch (error) {
809
- throw this.handleError(error);
810
- }
811
- }
812
-
813
- /**
814
- * Transfer funds between users
815
- * @param data - Transfer details including source, destination, and amount
816
- * @returns Transaction response
817
- */
818
- async transferFunds(data) {
819
- try {
820
- const res = await this.client.post('/wallet/transfer', data);
821
- return res.data;
822
- } catch (error) {
823
- throw this.handleError(error);
824
- }
825
- }
826
-
827
- /**
828
- * Process a purchase
829
- * @param data - Purchase details including user, item, and amount
830
- * @returns Transaction response
831
- */
832
- async processPurchase(data) {
833
- try {
834
- const res = await this.client.post('/wallet/purchase', data);
835
- return res.data;
836
- } catch (error) {
837
- throw this.handleError(error);
838
- }
839
- }
840
-
841
- /**
842
- * Request a withdrawal
843
- * @param data - Withdrawal details including user, amount, and address
844
- * @returns Transaction response
845
- */
846
- async requestWithdrawal(data) {
847
- try {
848
- const res = await this.client.post('/wallet/withdraw', data);
849
- return res.data;
850
- } catch (error) {
851
- throw this.handleError(error);
852
- }
853
- }
854
-
855
- /* Karma Methods */
856
-
857
- /**
858
- * Get karma leaderboard
859
- * @returns Array of karma leaderboard entries
860
- */
861
- async getKarmaLeaderboard() {
862
- try {
863
- const res = await this.client.get('/karma/leaderboard');
864
- return res.data;
865
- } catch (error) {
866
- throw this.handleError(error);
867
- }
868
- }
869
-
870
- /**
871
- * Get karma rules
872
- * @returns Array of karma rules
873
- */
874
- async getKarmaRules() {
875
- try {
876
- const res = await this.client.get('/karma/rules');
877
- return res.data;
878
- } catch (error) {
879
- throw this.handleError(error);
880
- }
881
- }
882
-
883
- /**
884
- * Get total karma for a user
885
- * @param userId - User ID to get karma for
886
- * @returns Object with total karma points
887
- */
888
- async getUserKarmaTotal(userId) {
889
- try {
890
- const res = await this.client.get(`/karma/${userId}/total`);
891
- return res.data;
892
- } catch (error) {
893
- throw this.handleError(error);
894
- }
895
- }
896
-
897
- /**
898
- * Get karma history for a user
899
- * @param userId - User ID to get karma history for
900
- * @param limit - Maximum number of history entries to return
901
- * @param offset - Number of entries to skip for pagination
902
- * @returns Karma history entries and pagination info
903
- */
904
- async getUserKarmaHistory(userId, limit, offset) {
905
- try {
906
- const params = {};
907
- if (limit !== undefined) params.limit = limit;
908
- if (offset !== undefined) params.offset = offset;
909
- const res = await this.client.get(`/karma/${userId}/history`, {
910
- params
911
- });
912
- return res.data;
913
- } catch (error) {
914
- throw this.handleError(error);
915
- }
916
- }
917
-
918
- /**
919
- * Award karma points to a user
920
- * @param data - Karma award details
921
- * @returns Karma award response
922
- */
923
- async awardKarma(data) {
924
- try {
925
- const res = await this.client.post('/karma/award', data);
926
- return res.data;
927
- } catch (error) {
928
- throw this.handleError(error);
929
- }
930
- }
931
-
932
- /**
933
- * Deduct karma points from a user
934
- * @param data - Karma deduction details
935
- * @returns Karma deduction response
936
- */
937
- async deductKarma(data) {
938
- try {
939
- const res = await this.client.post('/karma/deduct', data);
940
- return res.data;
941
- } catch (error) {
942
- throw this.handleError(error);
943
- }
944
- }
945
-
946
- /**
947
- * Create or update karma rule (admin)
948
- * @param data - Karma rule data
949
- * @returns Created or updated karma rule
950
- */
951
- async createOrUpdateKarmaRule(data) {
952
- try {
953
- const res = await this.client.post('/karma/rules', data);
954
- return res.data;
955
- } catch (error) {
956
- throw this.handleError(error);
957
- }
958
- }
959
-
960
- /* File Management Methods */
961
-
962
- /**
963
- * Upload a file using GridFS
964
- * @param file - The file to upload (File or Blob in browser, Buffer in Node.js)
965
- * @param filename - The name of the file
966
- * @param metadata - Optional metadata to associate with the file
967
- * @returns File metadata including ID and download URL
968
- */
969
- async uploadFile(file,
970
- // Use 'any' to handle Buffer type in cross-platform scenarios
971
- filename, metadata) {
972
- const response = await this.uploadFiles([file], [filename], metadata);
973
- return response.files[0];
974
- }
975
-
976
- /**
977
- * Upload multiple files using GridFS
978
- * @param files - Array of files to upload
979
- * @param filenames - Array of filenames (must match files array length)
980
- * @param metadata - Optional metadata to associate with all files
981
- * @returns Array of file metadata
982
- */
983
- async uploadFiles(files, filenames, metadata) {
984
- try {
985
- if (files.length !== filenames.length) {
986
- throw new Error('Files and filenames arrays must have the same length');
987
- }
988
-
989
- // Create form data to handle the file upload
990
- let formData;
991
- if (typeof window === 'undefined' && NodeFormData) {
992
- // Node.js environment - prefer node-specific form-data
993
- formData = new NodeFormData();
994
- } else {
995
- // Browser/React Native environment - use polyfilled or native FormData
996
- const FormDataConstructor = getFormDataConstructor();
997
- formData = new FormDataConstructor();
998
- }
999
-
1000
- // Add all files to the form data
1001
- files.forEach((file, index) => {
1002
- const filename = filenames[index];
1003
-
1004
- // Handle different file types (Browser vs Node.js vs React Native)
1005
- const isNodeBuffer = typeof window === 'undefined' && file && typeof file.constructor === 'function' && file.constructor.name === 'Buffer';
1006
- if (isNodeBuffer) {
1007
- // Node.js environment with Buffer
1008
- if (!NodeFormData) {
1009
- throw new Error('form-data module is required for file uploads from Buffer but not found.');
1010
- }
1011
- // form-data handles Buffers directly.
1012
- formData.append('files', file, {
1013
- filename
1014
- }); // Pass filename in options for form-data
1015
- } else {
1016
- // Browser/React Native environment with File or Blob
1017
- formData.append('files', file, filename);
1018
- }
1019
- });
1020
-
1021
- // Add metadata as JSON string if provided
1022
- if (metadata) {
1023
- formData.append('metadata', JSON.stringify(metadata));
1024
- }
1025
- const res = await this.client.post('/files/upload', formData, {
1026
- headers: {
1027
- 'Content-Type': 'multipart/form-data'
1028
- }
1029
- });
1030
- return res.data;
1031
- } catch (error) {
1032
- throw this.handleError(error);
1033
- }
1034
- }
1035
-
1036
- /**
1037
- * Get file metadata by ID
1038
- * @param fileId - ID of the file to retrieve metadata for
1039
- * @returns File metadata
1040
- */
1041
- async getFileMetadata(fileId) {
1042
- try {
1043
- const res = await this.client.get(`/files/${fileId}/metadata`);
1044
- return res.data;
1045
- } catch (error) {
1046
- throw this.handleError(error);
1047
- }
1048
- }
1049
-
1050
- /**
1051
- * Update file metadata
1052
- * @param fileId - ID of the file to update
1053
- * @param updates - Metadata updates to apply
1054
- * @returns Updated file metadata
1055
- */
1056
- async updateFileMetadata(fileId, updates) {
1057
- try {
1058
- const res = await this.client.put(`/files/${fileId}/metadata`, updates);
1059
- return res.data;
1060
- } catch (error) {
1061
- throw this.handleError(error);
1062
- }
1063
- }
1064
-
1065
- /**
1066
- * Delete a file by ID
1067
- * @param fileId - ID of the file to delete
1068
- * @returns Status of the delete operation
1069
- */
1070
- async deleteFile(fileId) {
1071
- try {
1072
- console.log('Deleting file with ID:', fileId);
1073
- const res = await this.client.delete(`/files/${fileId}`);
1074
- console.log('Delete response:', res.data);
1075
- return res.data;
1076
- } catch (error) {
1077
- console.error('Delete file error:', error);
1078
- console.error('Error response:', error.response?.data);
1079
- console.error('Error status:', error.response?.status);
1080
-
1081
- // Provide more specific error messages based on status code
1082
- if (error.response?.status === 404) {
1083
- throw new Error('File not found or already deleted');
1084
- } else if (error.response?.status === 403) {
1085
- throw new Error('You do not have permission to delete this file');
1086
- } else if (error.response?.status === 400) {
1087
- throw new Error('Invalid file ID format');
1088
- }
1089
- throw this.handleError(error);
1090
- }
1091
- }
1092
-
1093
- /**
1094
- * Get download URL for a file
1095
- * @param fileId - ID of the file to get download URL for
1096
- * @returns Full URL to download the file
1097
- */
1098
- getFileDownloadUrl(fileId) {
1099
- return `${this.client.defaults.baseURL}/files/${fileId}`;
1100
- }
1101
-
1102
- /**
1103
- * Stream a file (useful for playing audio/video without full download)
1104
- * @param fileId - ID of the file to stream
1105
- * @returns Full URL to stream the file
1106
- */
1107
- getFileStreamUrl(fileId) {
1108
- return `${this.client.defaults.baseURL}/files/${fileId}`;
1109
- }
1110
-
1111
- /**
1112
- * List files for a specific user
1113
- * @param userId - User ID to list files for
1114
- * @param limit - Maximum number of files to return
1115
- * @param offset - Number of files to skip for pagination
1116
- * @param filters - Optional filters for the file list (e.g., contentType)
1117
- * @returns Array of file metadata and pagination info
1118
- */
1119
- async listUserFiles(userId, limit, offset, filters) {
1120
- try {
1121
- const params = {};
1122
- if (limit !== undefined) params.limit = limit;
1123
- if (offset !== undefined) params.offset = offset;
1124
- if (filters) Object.assign(params, filters);
1125
- const res = await this.client.get(`/files/list/${userId}`, {
1126
- params
1127
- });
1128
-
1129
- // Handle backend response format: backend returns FileMetadata[] directly
1130
- // but interface expects { files: FileMetadata[], total: number, hasMore: boolean }
1131
- const rawFiles = Array.isArray(res.data) ? res.data : res.data.files || [];
1132
-
1133
- // Transform GridFS files to match FileMetadata interface (map _id to id)
1134
- const filesArray = rawFiles.map(file => ({
1135
- ...file,
1136
- id: file._id?.toString() || file.id,
1137
- uploadDate: file.uploadDate?.toISOString ? file.uploadDate.toISOString() : file.uploadDate
1138
- }));
1139
- return {
1140
- files: filesArray,
1141
- total: filesArray.length,
1142
- hasMore: false // No pagination in current backend implementation
1143
- };
1144
- } catch (error) {
1145
- throw this.handleError(error);
1146
- }
1147
- }
1148
-
1149
- /**
1150
- * Secure login that returns only session data (no tokens stored locally)
1151
- * @param username - User's username or email
1152
- * @param password - User's password
1153
- * @param deviceName - Optional device name for session tracking
1154
- * @param deviceFingerprint - Device fingerprint for enhanced security
1155
- * @returns Secure login response with session data
1156
- */
1157
- async secureLogin(username, password, deviceName, deviceFingerprint) {
1158
- try {
1159
- const payload = {
1160
- username,
1161
- password,
1162
- deviceName
1163
- };
1164
- if (deviceFingerprint) {
1165
- payload.deviceFingerprint = deviceFingerprint;
1166
- }
1167
- const res = await this.client.post('/secure-session/login', payload);
1168
- return res.data;
1169
- } catch (error) {
1170
- throw this.handleError(error);
1171
- }
1172
- }
1173
-
1174
- /**
1175
- * Get full user data by session ID
1176
- * @param sessionId - The session ID
1177
- * @returns Full user data
1178
- */
1179
- async getUserBySession(sessionId) {
1180
- try {
1181
- const res = await this.client.get(`/secure-session/user/${sessionId}`);
1182
- return res.data.user;
1183
- } catch (error) {
1184
- throw this.handleError(error);
1185
- }
1186
- }
1187
-
1188
- /**
1189
- * Get access token by session ID (for API calls)
1190
- * @param sessionId - The session ID
1191
- * @returns Access token and expiry info
1192
- */
1193
- async getTokenBySession(sessionId) {
1194
- try {
1195
- const res = await this.client.get(`/secure-session/token/${sessionId}`);
1196
- // Set the token for subsequent API calls
1197
- this.accessToken = res.data.accessToken;
1198
- return res.data;
1199
- } catch (error) {
1200
- throw this.handleError(error);
1201
- }
1202
- }
1203
-
1204
- /**
1205
- * Get all active sessions for current user
1206
- * @param sessionId - Current session ID
1207
- * @returns Array of user sessions
1208
- */
1209
- async getSessionsBySessionId(sessionId) {
1210
- try {
1211
- const res = await this.client.get(`/secure-session/sessions/${sessionId}`);
1212
- return res.data.sessions;
1213
- } catch (error) {
1214
- throw this.handleError(error);
1215
- }
1216
- }
1217
-
1218
- /**
1219
- * Logout specific session
1220
- * @param sessionId - Current session ID
1221
- * @param targetSessionId - Optional target session to logout (defaults to current)
1222
- */
1223
- async logoutSecureSession(sessionId, targetSessionId) {
1224
- try {
1225
- await this.client.post(`/secure-session/logout/${sessionId}`, {
1226
- targetSessionId
1227
- });
1228
-
1229
- // If we're logging out the current session, clear the access token
1230
- if (!targetSessionId || targetSessionId === sessionId) {
1231
- this.accessToken = null;
1232
- this.refreshToken = null;
1233
- }
1234
- } catch (error) {
1235
- throw this.handleError(error);
1236
- }
1237
- }
1238
-
1239
- /**
1240
- * Logout all sessions for current user
1241
- * @param sessionId - Current session ID
1242
- */
1243
- async logoutAllSecureSessions(sessionId) {
1244
- console.log('logoutAllSecureSessions called with sessionId:', sessionId);
1245
- console.log('API client defaults:', this.client.defaults);
1246
- try {
1247
- const response = await this.client.post(`/secure-session/logout-all/${sessionId}`);
1248
- console.log('logoutAllSecureSessions response:', response.status, response.data);
1249
-
1250
- // Clear tokens since all sessions are logged out
1251
- this.accessToken = null;
1252
- this.refreshToken = null;
1253
- console.log('Tokens cleared successfully');
1254
- } catch (error) {
1255
- console.error('logoutAllSecureSessions error:', error);
1256
- if (error && typeof error === 'object' && 'response' in error) {
1257
- const axiosError = error;
1258
- console.error('Error response data:', axiosError.response?.data);
1259
- console.error('Error response status:', axiosError.response?.status);
1260
- }
1261
- throw this.handleError(error);
1262
- }
1263
- }
1264
-
1265
- /**
1266
- * Validate session
1267
- * @param sessionId - The session ID to validate
1268
- * @returns Session validation status with user data
1269
- */
1270
- async validateSession(sessionId) {
1271
- try {
1272
- const res = await this.client.get(`/secure-session/validate/${sessionId}`);
1273
- return res.data;
1274
- } catch (error) {
1275
- throw this.handleError(error);
1276
- }
1277
- }
1278
-
1279
- /**
1280
- * Validate session using x-session-id header
1281
- * @param sessionId - The session ID to validate (sent as header)
1282
- * @param deviceFingerprint - Optional device fingerprint for enhanced security
1283
- * @returns Session validation status with user data
1284
- */
1285
- async validateSessionFromHeader(sessionId, deviceFingerprint) {
1286
- try {
1287
- const headers = {
1288
- 'x-session-id': sessionId
1289
- };
1290
- if (deviceFingerprint) {
1291
- headers['x-device-fingerprint'] = deviceFingerprint;
1292
- }
1293
- const res = await this.client.get('/secure-session/validate-header', {
1294
- headers
1295
- });
1296
- return res.data;
1297
- } catch (error) {
1298
- throw this.handleError(error);
1299
- }
1300
- }
1301
-
1302
- /**
1303
- * Validate session using automatic header detection
1304
- * The validateSession endpoint will automatically read from x-session-id header
1305
- * @param sessionId - The session ID to validate (sent as header)
1306
- * @param deviceFingerprint - Optional device fingerprint for enhanced security
1307
- * @returns Session validation status with user data
1308
- */
1309
- async validateSessionAuto(sessionId, deviceFingerprint) {
1310
- try {
1311
- const headers = {
1312
- 'x-session-id': sessionId
1313
- };
1314
- if (deviceFingerprint) {
1315
- headers['x-device-fingerprint'] = deviceFingerprint;
1316
- }
1317
-
1318
- // Call the regular validateSession endpoint which now auto-reads from headers
1319
- // Use 'auto' as placeholder since the controller reads from header
1320
- const res = await this.client.get('/secure-session/validate/auto', {
1321
- headers
1322
- });
1323
- return res.data;
1324
- } catch (error) {
1325
- throw this.handleError(error);
1326
- }
1327
- }
1328
-
1329
- /**
1330
- * Utility method to help implement authentication middleware in Express.js applications
1331
- * This creates a function that can be used as Express middleware to validate tokens
1332
- * @param options - Configuration options for the middleware
1333
- * @returns Express middleware function
1334
- */
1335
- createAuthenticateTokenMiddleware(options = {}) {
1336
- const {
1337
- loadFullUser = true,
1338
- onError
1339
- } = options;
1340
- return async (req, res, next) => {
1341
- try {
1342
- const authHeader = req.headers['authorization'];
1343
- const token = authHeader && authHeader.split(' ')[1]; // Bearer TOKEN
1344
-
1345
- if (!token) {
1346
- const error = {
1347
- message: 'Access token required',
1348
- code: 'MISSING_TOKEN',
1349
- status: 401
1350
- };
1351
- if (onError) {
1352
- return onError(error);
1353
- }
1354
- return res.status(401).json({
1355
- message: 'Access token required',
1356
- code: 'MISSING_TOKEN'
1357
- });
1358
- }
1359
-
1360
- // Create a temporary OxyServices instance with the token to validate it
1361
- const tempOxyServices = new OxyServices({
1362
- baseURL: this.client.defaults.baseURL || ''
1363
- });
1364
- tempOxyServices.setTokens(token, ''); // Set access token
1365
-
1366
- // Validate token using the validate method
1367
- const isValid = await tempOxyServices.validate();
1368
- if (!isValid) {
1369
- const error = {
1370
- message: 'Invalid or expired token',
1371
- code: 'INVALID_TOKEN',
1372
- status: 403
1373
- };
1374
- if (onError) {
1375
- return onError(error);
1376
- }
1377
- return res.status(403).json({
1378
- message: 'Invalid or expired token',
1379
- code: 'INVALID_TOKEN'
1380
- });
1381
- }
1382
-
1383
- // Get user ID from token
1384
- const userId = tempOxyServices.getCurrentUserId();
1385
- if (!userId) {
1386
- const error = {
1387
- message: 'Invalid token payload',
1388
- code: 'INVALID_PAYLOAD',
1389
- status: 403
1390
- };
1391
- if (onError) {
1392
- return onError(error);
1393
- }
1394
- return res.status(403).json({
1395
- message: 'Invalid token payload',
1396
- code: 'INVALID_PAYLOAD'
1397
- });
1398
- }
1399
-
1400
- // Set user information on request object
1401
- req.userId = userId;
1402
- req.accessToken = token;
1403
-
1404
- // Optionally load full user data
1405
- if (loadFullUser) {
1406
- try {
1407
- const userProfile = await tempOxyServices.getUserById(userId);
1408
- req.user = userProfile;
1409
- } catch (userError) {
1410
- // If we can't load user, continue with just ID
1411
- req.user = {
1412
- id: userId
1413
- };
1414
- }
1415
- } else {
1416
- req.user = {
1417
- id: userId
1418
- };
1419
- }
1420
- next();
1421
- } catch (error) {
1422
- const apiError = this.handleError(error);
1423
- if (onError) {
1424
- return onError(apiError);
1425
- }
1426
- return res.status(apiError.status || 500).json({
1427
- message: apiError.message,
1428
- code: apiError.code
1429
- });
1430
- }
1431
- };
1432
- }
1433
-
1434
- /**
1435
- * Helper method for validating tokens without Express middleware
1436
- * Useful for standalone token validation in various contexts
1437
- * @param token - The access token to validate
1438
- * @returns Object with validation result and user information
1439
- */
1440
- async authenticateToken(token) {
1441
- try {
1442
- if (!token) {
1443
- return {
1444
- valid: false,
1445
- error: 'Token is required'
1446
- };
1447
- }
1448
-
1449
- // Create a temporary OxyServices instance with the token
1450
- const tempOxyServices = new OxyServices({
1451
- baseURL: this.client.defaults.baseURL || ''
1452
- });
1453
- tempOxyServices.setTokens(token, '');
1454
-
1455
- // Validate token
1456
- const isValid = await tempOxyServices.validate();
1457
- if (!isValid) {
1458
- return {
1459
- valid: false,
1460
- error: 'Invalid or expired token'
1461
- };
1462
- }
1463
-
1464
- // Get user ID from token
1465
- const userId = tempOxyServices.getCurrentUserId();
1466
- if (!userId) {
1467
- return {
1468
- valid: false,
1469
- error: 'Invalid token payload'
1470
- };
1471
- }
1472
-
1473
- // Try to get user profile
1474
- let user;
1475
- try {
1476
- user = await tempOxyServices.getUserById(userId);
1477
- } catch (error) {
1478
- // Continue without full user data
1479
- user = {
1480
- id: userId
1481
- };
1482
- }
1483
- return {
1484
- valid: true,
1485
- userId,
1486
- user
1487
- };
1488
- } catch (error) {
1489
- return {
1490
- valid: false,
1491
- error: error instanceof Error ? error.message : 'Token validation failed'
1492
- };
1493
- }
1494
- }
1495
-
1496
- /**
1497
- * Centralized error handling
1498
- * @private
1499
- * @param error - Error object from API call
1500
- * @returns Formatted API error
1501
- */
1502
- handleError(error) {
1503
- if (error && error.code && error.status) {
1504
- // Already formatted as ApiError
1505
- return error;
1506
- }
1507
- const apiError = {
1508
- message: error?.message || error?.response?.data?.message || 'Unknown error occurred',
1509
- code: error?.response?.data?.code || 'UNKNOWN_ERROR',
1510
- status: error?.response?.status || 500,
1511
- details: error?.response?.data
1512
- };
1513
- return apiError;
1514
- }
1515
- }
1516
- export default OxyServices;
1517
- //# sourceMappingURL=index.js.map