@oxyhq/services 5.7.4 → 5.8.1

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 (252) hide show
  1. package/README.md +125 -268
  2. package/lib/commonjs/core/index.js +172 -0
  3. package/lib/commonjs/core/index.js.map +1 -1
  4. package/lib/commonjs/index.js +88 -29
  5. package/lib/commonjs/index.js.map +1 -1
  6. package/lib/commonjs/node/createAuth.js +585 -7
  7. package/lib/commonjs/node/createAuth.js.map +1 -1
  8. package/lib/commonjs/node/index.js +31 -41
  9. package/lib/commonjs/node/index.js.map +1 -1
  10. package/lib/commonjs/ui/components/Avatar.js +15 -6
  11. package/lib/commonjs/ui/components/Avatar.js.map +1 -1
  12. package/lib/commonjs/ui/components/GroupedItem.js +58 -13
  13. package/lib/commonjs/ui/components/GroupedItem.js.map +1 -1
  14. package/lib/commonjs/ui/components/GroupedSection.js +7 -1
  15. package/lib/commonjs/ui/components/GroupedSection.js.map +1 -1
  16. package/lib/commonjs/ui/components/Header.js +322 -0
  17. package/lib/commonjs/ui/components/Header.js.map +1 -0
  18. package/lib/commonjs/ui/components/OxyProvider.js +23 -7
  19. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  20. package/lib/commonjs/ui/components/index.js +7 -0
  21. package/lib/commonjs/ui/components/index.js.map +1 -1
  22. package/lib/commonjs/ui/components/internal/GroupedPillButtons.js +1 -1
  23. package/lib/commonjs/ui/components/internal/GroupedPillButtons.js.map +1 -1
  24. package/lib/commonjs/ui/components/internal/TextField.js +606 -546
  25. package/lib/commonjs/ui/components/internal/TextField.js.map +1 -1
  26. package/lib/commonjs/ui/components/internal/TextField.md +436 -0
  27. package/lib/commonjs/ui/context/OxyContext.js +122 -78
  28. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  29. package/lib/commonjs/ui/hooks/useSessionSocket.js +5 -2
  30. package/lib/commonjs/ui/hooks/useSessionSocket.js.map +1 -1
  31. package/lib/commonjs/ui/index.js +1 -16
  32. package/lib/commonjs/ui/index.js.map +1 -1
  33. package/lib/commonjs/ui/navigation/OxyRouter.js +1 -1
  34. package/lib/commonjs/ui/navigation/OxyRouter.js.map +1 -1
  35. package/lib/commonjs/ui/screens/AccountCenterScreen.js +6 -6
  36. package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
  37. package/lib/commonjs/ui/screens/AccountManagementDemo.js +3 -3
  38. package/lib/commonjs/ui/screens/AccountManagementDemo.js.map +1 -1
  39. package/lib/commonjs/ui/screens/AccountOverviewScreen.js +241 -598
  40. package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -1
  41. package/lib/commonjs/ui/screens/AccountSettingsScreen.js +1151 -406
  42. package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
  43. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +135 -237
  44. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
  45. package/lib/commonjs/ui/screens/AppInfoScreen.js +246 -463
  46. package/lib/commonjs/ui/screens/AppInfoScreen.js.map +1 -1
  47. package/lib/commonjs/ui/screens/FeedbackScreen.js +3 -3
  48. package/lib/commonjs/ui/screens/FeedbackScreen.js.map +1 -1
  49. package/lib/commonjs/ui/screens/PaymentGatewayScreen.js +808 -650
  50. package/lib/commonjs/ui/screens/PaymentGatewayScreen.js.map +1 -1
  51. package/lib/commonjs/ui/screens/RecoverAccountScreen.js +51 -72
  52. package/lib/commonjs/ui/screens/RecoverAccountScreen.js.map +1 -1
  53. package/lib/commonjs/ui/screens/SessionManagementScreen.js +11 -29
  54. package/lib/commonjs/ui/screens/SessionManagementScreen.js.map +1 -1
  55. package/lib/commonjs/ui/screens/SignInScreen.js +30 -303
  56. package/lib/commonjs/ui/screens/SignInScreen.js.map +1 -1
  57. package/lib/commonjs/ui/screens/SignUpScreen.js +4 -4
  58. package/lib/commonjs/ui/screens/SignUpScreen.js.map +1 -1
  59. package/lib/commonjs/ui/screens/internal/SignInPasswordStep.js +19 -31
  60. package/lib/commonjs/ui/screens/internal/SignInPasswordStep.js.map +1 -1
  61. package/lib/commonjs/ui/screens/internal/SignInUsernameStep.js +7 -10
  62. package/lib/commonjs/ui/screens/internal/SignInUsernameStep.js.map +1 -1
  63. package/lib/commonjs/ui/screens/internal/SignUpIdentityStep.js +11 -5
  64. package/lib/commonjs/ui/screens/internal/SignUpIdentityStep.js.map +1 -1
  65. package/lib/commonjs/ui/screens/internal/SignUpSecurityStep.js +11 -4
  66. package/lib/commonjs/ui/screens/internal/SignUpSecurityStep.js.map +1 -1
  67. package/lib/commonjs/ui/stores/authStore.js +12 -0
  68. package/lib/commonjs/ui/stores/authStore.js.map +1 -1
  69. package/lib/commonjs/ui/styles/authStyles.js +337 -0
  70. package/lib/commonjs/ui/styles/authStyles.js.map +1 -0
  71. package/lib/commonjs/ui/styles/index.js +11 -0
  72. package/lib/commonjs/ui/styles/index.js.map +1 -1
  73. package/lib/module/core/index.js +172 -0
  74. package/lib/module/core/index.js.map +1 -1
  75. package/lib/module/index.js +26 -4
  76. package/lib/module/index.js.map +1 -1
  77. package/lib/module/node/createAuth.js +584 -7
  78. package/lib/module/node/createAuth.js.map +1 -1
  79. package/lib/module/node/index.js +8 -12
  80. package/lib/module/node/index.js.map +1 -1
  81. package/lib/module/ui/components/Avatar.js +15 -6
  82. package/lib/module/ui/components/Avatar.js.map +1 -1
  83. package/lib/module/ui/components/GroupedItem.js +59 -14
  84. package/lib/module/ui/components/GroupedItem.js.map +1 -1
  85. package/lib/module/ui/components/GroupedSection.js +7 -1
  86. package/lib/module/ui/components/GroupedSection.js.map +1 -1
  87. package/lib/module/ui/components/Header.js +317 -0
  88. package/lib/module/ui/components/Header.js.map +1 -0
  89. package/lib/module/ui/components/OxyProvider.js +25 -9
  90. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  91. package/lib/module/ui/components/index.js +1 -0
  92. package/lib/module/ui/components/index.js.map +1 -1
  93. package/lib/module/ui/components/internal/GroupedPillButtons.js +1 -1
  94. package/lib/module/ui/components/internal/GroupedPillButtons.js.map +1 -1
  95. package/lib/module/ui/components/internal/TextField.js +607 -547
  96. package/lib/module/ui/components/internal/TextField.js.map +1 -1
  97. package/lib/module/ui/components/internal/TextField.md +436 -0
  98. package/lib/module/ui/context/OxyContext.js +121 -77
  99. package/lib/module/ui/context/OxyContext.js.map +1 -1
  100. package/lib/module/ui/hooks/useSessionSocket.js +5 -2
  101. package/lib/module/ui/hooks/useSessionSocket.js.map +1 -1
  102. package/lib/module/ui/index.js +1 -16
  103. package/lib/module/ui/index.js.map +1 -1
  104. package/lib/module/ui/navigation/OxyRouter.js +1 -1
  105. package/lib/module/ui/navigation/OxyRouter.js.map +1 -1
  106. package/lib/module/ui/screens/AccountCenterScreen.js +6 -6
  107. package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
  108. package/lib/module/ui/screens/AccountManagementDemo.js +3 -3
  109. package/lib/module/ui/screens/AccountManagementDemo.js.map +1 -1
  110. package/lib/module/ui/screens/AccountOverviewScreen.js +242 -597
  111. package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -1
  112. package/lib/module/ui/screens/AccountSettingsScreen.js +1152 -407
  113. package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
  114. package/lib/module/ui/screens/AccountSwitcherScreen.js +135 -237
  115. package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
  116. package/lib/module/ui/screens/AppInfoScreen.js +248 -465
  117. package/lib/module/ui/screens/AppInfoScreen.js.map +1 -1
  118. package/lib/module/ui/screens/FeedbackScreen.js +3 -3
  119. package/lib/module/ui/screens/FeedbackScreen.js.map +1 -1
  120. package/lib/module/ui/screens/PaymentGatewayScreen.js +809 -651
  121. package/lib/module/ui/screens/PaymentGatewayScreen.js.map +1 -1
  122. package/lib/module/ui/screens/RecoverAccountScreen.js +53 -74
  123. package/lib/module/ui/screens/RecoverAccountScreen.js.map +1 -1
  124. package/lib/module/ui/screens/SessionManagementScreen.js +11 -29
  125. package/lib/module/ui/screens/SessionManagementScreen.js.map +1 -1
  126. package/lib/module/ui/screens/SignInScreen.js +32 -305
  127. package/lib/module/ui/screens/SignInScreen.js.map +1 -1
  128. package/lib/module/ui/screens/SignUpScreen.js +5 -5
  129. package/lib/module/ui/screens/SignUpScreen.js.map +1 -1
  130. package/lib/module/ui/screens/internal/SignInPasswordStep.js +19 -31
  131. package/lib/module/ui/screens/internal/SignInPasswordStep.js.map +1 -1
  132. package/lib/module/ui/screens/internal/SignInUsernameStep.js +7 -10
  133. package/lib/module/ui/screens/internal/SignInUsernameStep.js.map +1 -1
  134. package/lib/module/ui/screens/internal/SignUpIdentityStep.js +11 -5
  135. package/lib/module/ui/screens/internal/SignUpIdentityStep.js.map +1 -1
  136. package/lib/module/ui/screens/internal/SignUpSecurityStep.js +11 -4
  137. package/lib/module/ui/screens/internal/SignUpSecurityStep.js.map +1 -1
  138. package/lib/module/ui/stores/authStore.js +12 -0
  139. package/lib/module/ui/stores/authStore.js.map +1 -1
  140. package/lib/module/ui/styles/authStyles.js +332 -0
  141. package/lib/module/ui/styles/authStyles.js.map +1 -0
  142. package/lib/module/ui/styles/index.js +1 -0
  143. package/lib/module/ui/styles/index.js.map +1 -1
  144. package/lib/typescript/core/index.d.ts +67 -0
  145. package/lib/typescript/core/index.d.ts.map +1 -1
  146. package/lib/typescript/index.d.ts +13 -3
  147. package/lib/typescript/index.d.ts.map +1 -1
  148. package/lib/typescript/node/createAuth.d.ts +112 -0
  149. package/lib/typescript/node/createAuth.d.ts.map +1 -1
  150. package/lib/typescript/node/index.d.ts +3 -7
  151. package/lib/typescript/node/index.d.ts.map +1 -1
  152. package/lib/typescript/ui/components/Avatar.d.ts.map +1 -1
  153. package/lib/typescript/ui/components/GroupedItem.d.ts +6 -0
  154. package/lib/typescript/ui/components/GroupedItem.d.ts.map +1 -1
  155. package/lib/typescript/ui/components/GroupedSection.d.ts +6 -0
  156. package/lib/typescript/ui/components/GroupedSection.d.ts.map +1 -1
  157. package/lib/typescript/ui/components/Header.d.ts +22 -0
  158. package/lib/typescript/ui/components/Header.d.ts.map +1 -0
  159. package/lib/typescript/ui/components/OxyProvider.d.ts.map +1 -1
  160. package/lib/typescript/ui/components/index.d.ts +1 -0
  161. package/lib/typescript/ui/components/index.d.ts.map +1 -1
  162. package/lib/typescript/ui/components/internal/TextField.d.ts +31 -16
  163. package/lib/typescript/ui/components/internal/TextField.d.ts.map +1 -1
  164. package/lib/typescript/ui/context/OxyContext.d.ts +5 -2
  165. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
  166. package/lib/typescript/ui/hooks/useSessionSocket.d.ts.map +1 -1
  167. package/lib/typescript/ui/index.d.ts +1 -2
  168. package/lib/typescript/ui/index.d.ts.map +1 -1
  169. package/lib/typescript/ui/navigation/types.d.ts +9 -2
  170. package/lib/typescript/ui/navigation/types.d.ts.map +1 -1
  171. package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts.map +1 -1
  172. package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +1 -1
  173. package/lib/typescript/ui/screens/AccountSwitcherScreen.d.ts.map +1 -1
  174. package/lib/typescript/ui/screens/AppInfoScreen.d.ts.map +1 -1
  175. package/lib/typescript/ui/screens/PaymentGatewayScreen.d.ts.map +1 -1
  176. package/lib/typescript/ui/screens/RecoverAccountScreen.d.ts +5 -1
  177. package/lib/typescript/ui/screens/RecoverAccountScreen.d.ts.map +1 -1
  178. package/lib/typescript/ui/screens/SessionManagementScreen.d.ts.map +1 -1
  179. package/lib/typescript/ui/screens/SignInScreen.d.ts.map +1 -1
  180. package/lib/typescript/ui/screens/internal/SignInPasswordStep.d.ts +1 -1
  181. package/lib/typescript/ui/screens/internal/SignInPasswordStep.d.ts.map +1 -1
  182. package/lib/typescript/ui/screens/internal/SignInUsernameStep.d.ts +0 -1
  183. package/lib/typescript/ui/screens/internal/SignInUsernameStep.d.ts.map +1 -1
  184. package/lib/typescript/ui/screens/internal/SignUpIdentityStep.d.ts.map +1 -1
  185. package/lib/typescript/ui/screens/internal/SignUpSecurityStep.d.ts.map +1 -1
  186. package/lib/typescript/ui/stores/authStore.d.ts.map +1 -1
  187. package/lib/typescript/ui/styles/authStyles.d.ts +326 -0
  188. package/lib/typescript/ui/styles/authStyles.d.ts.map +1 -0
  189. package/lib/typescript/ui/styles/index.d.ts +1 -0
  190. package/lib/typescript/ui/styles/index.d.ts.map +1 -1
  191. package/package.json +1 -6
  192. package/src/core/index.ts +189 -0
  193. package/src/index.ts +72 -4
  194. package/src/node/createAuth.ts +623 -7
  195. package/src/node/index.ts +20 -18
  196. package/src/ui/components/Avatar.tsx +11 -5
  197. package/src/ui/components/GroupedItem.tsx +57 -9
  198. package/src/ui/components/GroupedSection.tsx +12 -0
  199. package/src/ui/components/Header.tsx +364 -0
  200. package/src/ui/components/OxyProvider.tsx +31 -15
  201. package/src/ui/components/index.ts +1 -0
  202. package/src/ui/components/internal/GroupedPillButtons.tsx +1 -1
  203. package/src/ui/components/internal/TextField.md +436 -0
  204. package/src/ui/components/internal/TextField.tsx +720 -620
  205. package/src/ui/context/OxyContext.tsx +150 -63
  206. package/src/ui/hooks/useSessionSocket.ts +5 -2
  207. package/src/ui/index.ts +1 -19
  208. package/src/ui/navigation/OxyRouter.tsx +1 -1
  209. package/src/ui/navigation/types.ts +10 -2
  210. package/src/ui/screens/AccountCenterScreen.tsx +5 -5
  211. package/src/ui/screens/AccountManagementDemo.tsx +9 -9
  212. package/src/ui/screens/AccountOverviewScreen.tsx +265 -414
  213. package/src/ui/screens/AccountSettingsScreen.tsx +1165 -403
  214. package/src/ui/screens/AccountSwitcherScreen.tsx +158 -202
  215. package/src/ui/screens/AppInfoScreen.tsx +270 -497
  216. package/src/ui/screens/FeedbackScreen.tsx +3 -3
  217. package/src/ui/screens/PaymentGatewayScreen.tsx +668 -365
  218. package/src/ui/screens/ProfileScreen.tsx +5 -5
  219. package/src/ui/screens/RecoverAccountScreen.tsx +46 -74
  220. package/src/ui/screens/SessionManagementScreen.tsx +14 -22
  221. package/src/ui/screens/SignInScreen.tsx +27 -294
  222. package/src/ui/screens/SignUpScreen.tsx +5 -5
  223. package/src/ui/screens/internal/SignInPasswordStep.tsx +11 -22
  224. package/src/ui/screens/internal/SignInUsernameStep.tsx +3 -10
  225. package/src/ui/screens/internal/SignUpIdentityStep.tsx +2 -5
  226. package/src/ui/screens/internal/SignUpSecurityStep.tsx +3 -4
  227. package/src/ui/stores/authStore.ts +12 -0
  228. package/src/ui/styles/authStyles.ts +352 -0
  229. package/src/ui/styles/index.ts +1 -0
  230. package/lib/commonjs/node/middleware.js +0 -227
  231. package/lib/commonjs/node/middleware.js.map +0 -1
  232. package/lib/commonjs/ui/zero-config/index.js +0 -25
  233. package/lib/commonjs/ui/zero-config/index.js.map +0 -1
  234. package/lib/commonjs/ui/zero-config/provider.js +0 -278
  235. package/lib/commonjs/ui/zero-config/provider.js.map +0 -1
  236. package/lib/module/node/middleware.js +0 -199
  237. package/lib/module/node/middleware.js.map +0 -1
  238. package/lib/module/ui/zero-config/index.js +0 -8
  239. package/lib/module/ui/zero-config/index.js.map +0 -1
  240. package/lib/module/ui/zero-config/provider.js +0 -270
  241. package/lib/module/ui/zero-config/provider.js.map +0 -1
  242. package/lib/typescript/node/middleware.d.ts +0 -92
  243. package/lib/typescript/node/middleware.d.ts.map +0 -1
  244. package/lib/typescript/ui/zero-config/index.d.ts +0 -5
  245. package/lib/typescript/ui/zero-config/index.d.ts.map +0 -1
  246. package/lib/typescript/ui/zero-config/provider.d.ts +0 -84
  247. package/lib/typescript/ui/zero-config/provider.d.ts.map +0 -1
  248. package/src/__tests__/middleware.test.ts +0 -105
  249. package/src/__tests__/setup.ts +0 -10
  250. package/src/node/middleware.ts +0 -234
  251. package/src/ui/zero-config/index.ts +0 -11
  252. package/src/ui/zero-config/provider.tsx +0 -310
@@ -1,278 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useOxyZeroConfig = exports.useOxyApi = exports.OxyZeroConfigProvider = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _core = require("../../core");
9
- var _jsxRuntime = require("react/jsx-runtime");
10
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
- /**
12
- * Zero-config OxyHQ Provider and Hook for React/React Native
13
- *
14
- * This provides a simplified, one-line setup for frontend authentication
15
- * with automatic token management and API integration.
16
- */
17
-
18
- const OxyZeroConfigContext = /*#__PURE__*/(0, _react.createContext)(null);
19
- /**
20
- * Zero-config provider for OxyHQ Services
21
- *
22
- * @example
23
- * ```tsx
24
- * import { OxyZeroConfigProvider } from '@oxyhq/services/ui';
25
- *
26
- * function App() {
27
- * return (
28
- * <OxyZeroConfigProvider>
29
- * <MyApp />
30
- * </OxyZeroConfigProvider>
31
- * );
32
- * }
33
- * ```
34
- */
35
- const OxyZeroConfigProvider = ({
36
- children,
37
- apiUrl,
38
- onAuthChange,
39
- storagePrefix = 'oxy_zero'
40
- }) => {
41
- // Determine API URL with fallbacks
42
- const finalApiUrl = apiUrl || typeof process !== 'undefined' && process.env?.REACT_APP_OXY_API_URL || 'http://localhost:3001';
43
-
44
- // Initialize OxyServices
45
- const [api] = (0, _react.useState)(() => new _core.OxyServices({
46
- baseURL: finalApiUrl
47
- }));
48
-
49
- // State
50
- const [user, setUser] = (0, _react.useState)(null);
51
- const [isLoading, setIsLoading] = (0, _react.useState)(true);
52
- const [error, setError] = (0, _react.useState)(null);
53
- const isAuthenticated = user !== null;
54
-
55
- // Storage helpers
56
- const getStorageKey = key => `${storagePrefix}_${key}`;
57
- const saveToStorage = (0, _react.useCallback)((key, value) => {
58
- try {
59
- if (typeof localStorage !== 'undefined') {
60
- localStorage.setItem(getStorageKey(key), value);
61
- }
62
- } catch (error) {
63
- console.warn('Failed to save to storage:', error);
64
- }
65
- }, [storagePrefix]);
66
- const getFromStorage = (0, _react.useCallback)(key => {
67
- try {
68
- if (typeof localStorage !== 'undefined') {
69
- return localStorage.getItem(getStorageKey(key));
70
- }
71
- } catch (error) {
72
- console.warn('Failed to read from storage:', error);
73
- }
74
- return null;
75
- }, [storagePrefix]);
76
- const removeFromStorage = (0, _react.useCallback)(key => {
77
- try {
78
- if (typeof localStorage !== 'undefined') {
79
- localStorage.removeItem(getStorageKey(key));
80
- }
81
- } catch (error) {
82
- console.warn('Failed to remove from storage:', error);
83
- }
84
- }, [storagePrefix]);
85
-
86
- // Initialize authentication state
87
- (0, _react.useEffect)(() => {
88
- const initAuth = async () => {
89
- try {
90
- setIsLoading(true);
91
- setError(null);
92
-
93
- // Try to restore tokens from storage
94
- const savedAccessToken = getFromStorage('accessToken');
95
- const savedRefreshToken = getFromStorage('refreshToken');
96
- if (savedAccessToken && savedRefreshToken) {
97
- // Set tokens in the API client
98
- api.setTokens(savedAccessToken, savedRefreshToken);
99
-
100
- // Validate the token
101
- const isValid = await api.validate();
102
- if (isValid) {
103
- // Load user data
104
- const currentUser = await api.getCurrentUser();
105
- setUser(currentUser);
106
- if (onAuthChange) {
107
- onAuthChange(currentUser);
108
- }
109
- } else {
110
- // Invalid token, clear storage
111
- removeFromStorage('accessToken');
112
- removeFromStorage('refreshToken');
113
- api.clearTokens();
114
- }
115
- }
116
- } catch (error) {
117
- console.warn('Failed to restore authentication:', error);
118
- setError('Failed to restore authentication');
119
-
120
- // Clear invalid tokens
121
- removeFromStorage('accessToken');
122
- removeFromStorage('refreshToken');
123
- api.clearTokens();
124
- } finally {
125
- setIsLoading(false);
126
- }
127
- };
128
- initAuth();
129
- }, [api, getFromStorage, removeFromStorage, onAuthChange]);
130
-
131
- // Login method
132
- const login = (0, _react.useCallback)(async (username, password) => {
133
- try {
134
- setIsLoading(true);
135
- setError(null);
136
- const response = await api.login(username, password);
137
-
138
- // Save tokens to storage
139
- if (response.accessToken) {
140
- saveToStorage('accessToken', response.accessToken);
141
- }
142
- if (response.refreshToken) {
143
- saveToStorage('refreshToken', response.refreshToken);
144
- }
145
-
146
- // Update state
147
- setUser(response.user);
148
- if (onAuthChange) {
149
- onAuthChange(response.user);
150
- }
151
- return response.user;
152
- } catch (error) {
153
- const errorMessage = error.message || 'Login failed';
154
- setError(errorMessage);
155
- throw new Error(errorMessage);
156
- } finally {
157
- setIsLoading(false);
158
- }
159
- }, [api, saveToStorage, onAuthChange]);
160
-
161
- // Logout method
162
- const logout = (0, _react.useCallback)(async () => {
163
- try {
164
- setIsLoading(true);
165
- await api.logout();
166
- } catch (error) {
167
- console.warn('Logout API call failed:', error);
168
- } finally {
169
- // Always clean up local state and storage
170
- removeFromStorage('accessToken');
171
- removeFromStorage('refreshToken');
172
- api.clearTokens();
173
- setUser(null);
174
- setError(null);
175
- setIsLoading(false);
176
- if (onAuthChange) {
177
- onAuthChange(null);
178
- }
179
- }
180
- }, [api, removeFromStorage, onAuthChange]);
181
-
182
- // Register method
183
- const register = (0, _react.useCallback)(async (username, email, password) => {
184
- try {
185
- setIsLoading(true);
186
- setError(null);
187
- const response = await api.signUp(username, email, password);
188
-
189
- // Save token from registration
190
- if (response.token) {
191
- saveToStorage('accessToken', response.token);
192
- // Note: signUp doesn't return refreshToken in current API
193
- }
194
-
195
- // Update state
196
- setUser(response.user);
197
- if (onAuthChange) {
198
- onAuthChange(response.user);
199
- }
200
- return response.user;
201
- } catch (error) {
202
- const errorMessage = error.message || 'Registration failed';
203
- setError(errorMessage);
204
- throw new Error(errorMessage);
205
- } finally {
206
- setIsLoading(false);
207
- }
208
- }, [api, saveToStorage, onAuthChange]);
209
- const contextValue = {
210
- user,
211
- isAuthenticated,
212
- isLoading,
213
- error,
214
- login,
215
- logout,
216
- register,
217
- api
218
- };
219
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(OxyZeroConfigContext.Provider, {
220
- value: contextValue,
221
- children: children
222
- });
223
- };
224
-
225
- /**
226
- * Zero-config hook for OxyHQ Services
227
- *
228
- * @example
229
- * ```tsx
230
- * function MyComponent() {
231
- * const { user, login, logout, isAuthenticated } = useOxyZeroConfig();
232
- *
233
- * const handleLogin = () => {
234
- * login('username', 'password');
235
- * };
236
- *
237
- * if (isAuthenticated) {
238
- * return <div>Welcome, {user?.username}!</div>;
239
- * }
240
- *
241
- * return <button onClick={handleLogin}>Login</button>;
242
- * }
243
- * ```
244
- */
245
- exports.OxyZeroConfigProvider = OxyZeroConfigProvider;
246
- const useOxyZeroConfig = () => {
247
- const context = (0, _react.useContext)(OxyZeroConfigContext);
248
- if (!context) {
249
- throw new Error('useOxyZeroConfig must be used within an OxyZeroConfigProvider');
250
- }
251
- return context;
252
- };
253
-
254
- /**
255
- * Hook for automatic API client with authentication
256
- * This automatically includes the auth token in requests
257
- *
258
- * @example
259
- * ```tsx
260
- * function ProfileComponent() {
261
- * const api = useOxyApi();
262
- *
263
- * const updateProfile = async (data) => {
264
- * const user = await api.updateProfile(data);
265
- * // Token is automatically included
266
- * };
267
- * }
268
- * ```
269
- */
270
- exports.useOxyZeroConfig = useOxyZeroConfig;
271
- const useOxyApi = () => {
272
- const {
273
- api
274
- } = useOxyZeroConfig();
275
- return api;
276
- };
277
- exports.useOxyApi = useOxyApi;
278
- //# sourceMappingURL=provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_core","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","OxyZeroConfigContext","createContext","OxyZeroConfigProvider","children","apiUrl","onAuthChange","storagePrefix","finalApiUrl","process","env","REACT_APP_OXY_API_URL","api","useState","OxyServices","baseURL","user","setUser","isLoading","setIsLoading","error","setError","isAuthenticated","getStorageKey","key","saveToStorage","useCallback","value","localStorage","setItem","console","warn","getFromStorage","getItem","removeFromStorage","removeItem","useEffect","initAuth","savedAccessToken","savedRefreshToken","setTokens","isValid","validate","currentUser","getCurrentUser","clearTokens","login","username","password","response","accessToken","refreshToken","errorMessage","message","Error","logout","register","email","signUp","token","contextValue","jsx","Provider","exports","useOxyZeroConfig","context","useContext","useOxyApi"],"sourceRoot":"../../../../src","sources":["ui/zero-config/provider.tsx"],"mappings":";;;;;;AAOA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAAyC,IAAAE,WAAA,GAAAF,OAAA;AAAA,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,CAAAI,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,C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AACA;AACA;AACA;AACA;AACA;AAnBA2D,OAAA,CAAA5D,qBAAA,GAAAA,qBAAA;AAoBO,MAAM6D,gBAAgB,GAAGA,CAAA,KAA0B;EACxD,MAAMC,OAAO,GAAG,IAAAC,iBAAU,EAACjE,oBAAoB,CAAC;EAChD,IAAI,CAACgE,OAAO,EAAE;IACZ,MAAM,IAAIX,KAAK,CAAC,+DAA+D,CAAC;EAClF;EACA,OAAOW,OAAO;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAfAF,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAgBO,MAAMG,SAAS,GAAGA,CAAA,KAAmB;EAC1C,MAAM;IAAEvD;EAAI,CAAC,GAAGoD,gBAAgB,CAAC,CAAC;EAClC,OAAOpD,GAAG;AACZ,CAAC;AAACmD,OAAA,CAAAI,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -1,199 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Zero-config Express middleware for OxyHQ Services authentication
5
- *
6
- * This provides a simple, one-line solution for adding authentication to Express apps.
7
- * Simply import and use: app.use('/api', createOxyAuth())
8
- */
9
-
10
- import { OxyServices } from '../core';
11
- /**
12
- * Creates zero-config authentication middleware for Express.js
13
- *
14
- * @example
15
- * ```typescript
16
- * import express from 'express';
17
- * import { createOxyAuth } from '@oxyhq/services/node';
18
- *
19
- * const app = express();
20
- *
21
- * // Zero-config auth for all /api routes
22
- * app.use('/api', createOxyAuth());
23
- *
24
- * // Now all routes under /api automatically have req.user available
25
- * app.get('/api/profile', (req, res) => {
26
- * res.json({ user: req.user }); // req.user is automatically available
27
- * });
28
- * ```
29
- */
30
- export function createOxyAuth(config = {}) {
31
- const {
32
- baseURL = process.env.OXY_API_URL || 'http://localhost:3001',
33
- loadUser = true,
34
- publicPaths = [],
35
- onError
36
- } = config;
37
- const oxy = new OxyServices({
38
- baseURL
39
- });
40
- return async (req, res, next) => {
41
- // Check if this is a public path
42
- const isPublicPath = publicPaths.some(path => req.path === path || req.path.startsWith(path + '/'));
43
- if (isPublicPath) {
44
- return next();
45
- }
46
- try {
47
- const authHeader = req.headers['authorization'];
48
- const token = authHeader && authHeader.split(' ')[1]; // Bearer TOKEN
49
-
50
- if (!token) {
51
- const error = {
52
- message: 'Access token required',
53
- code: 'MISSING_TOKEN',
54
- status: 401
55
- };
56
- if (onError) {
57
- return onError(error, req, res);
58
- }
59
- return res.status(401).json({
60
- error: 'Access token required',
61
- code: 'MISSING_TOKEN'
62
- });
63
- }
64
-
65
- // Validate token using the OxyServices client
66
- const authResult = await oxy.authenticateToken(token);
67
- if (!authResult.valid) {
68
- const error = {
69
- message: authResult.error || 'Invalid token',
70
- code: 'INVALID_TOKEN',
71
- status: 403
72
- };
73
- if (onError) {
74
- return onError(error, req, res);
75
- }
76
- return res.status(403).json({
77
- error: authResult.error || 'Invalid token',
78
- code: 'INVALID_TOKEN'
79
- });
80
- }
81
-
82
- // Attach user data to request
83
- req.userId = authResult.userId;
84
- req.accessToken = token;
85
- if (loadUser && authResult.user) {
86
- req.user = authResult.user;
87
- } else {
88
- req.user = {
89
- id: authResult.userId
90
- };
91
- }
92
- next();
93
- } catch (error) {
94
- const apiError = {
95
- message: error.message || 'Authentication failed',
96
- code: error.code || 'AUTH_ERROR',
97
- status: error.status || 500
98
- };
99
- if (onError) {
100
- return onError(apiError, req, res);
101
- }
102
- res.status(apiError.status).json({
103
- error: apiError.message,
104
- code: apiError.code
105
- });
106
- }
107
- };
108
- }
109
-
110
- /**
111
- * Creates optional authentication middleware
112
- * This middleware will attach user data if a valid token is present, but won't fail if missing
113
- *
114
- * @example
115
- * ```typescript
116
- * import { createOptionalOxyAuth } from '@oxyhq/services/node';
117
- *
118
- * app.use('/api', createOptionalOxyAuth());
119
- *
120
- * app.get('/api/content', (req, res) => {
121
- * if (req.user) {
122
- * // User is authenticated, show personalized content
123
- * res.json({ content: 'personalized', user: req.user });
124
- * } else {
125
- * // Anonymous user, show public content
126
- * res.json({ content: 'public' });
127
- * }
128
- * });
129
- * ```
130
- */
131
- export function createOptionalOxyAuth(config = {}) {
132
- const {
133
- baseURL = process.env.OXY_API_URL || 'http://localhost:3001',
134
- loadUser = true
135
- } = config;
136
- const oxy = new OxyServices({
137
- baseURL
138
- });
139
- return async (req, res, next) => {
140
- try {
141
- const authHeader = req.headers['authorization'];
142
- const token = authHeader && authHeader.split(' ')[1]; // Bearer TOKEN
143
-
144
- if (!token) {
145
- // No token provided, continue without authentication
146
- return next();
147
- }
148
-
149
- // Validate token using the OxyServices client
150
- const authResult = await oxy.authenticateToken(token);
151
- if (authResult.valid) {
152
- // Attach user data to request if token is valid
153
- req.userId = authResult.userId;
154
- req.accessToken = token;
155
- if (loadUser && authResult.user) {
156
- req.user = authResult.user;
157
- } else {
158
- req.user = {
159
- id: authResult.userId
160
- };
161
- }
162
- }
163
- next();
164
- } catch (error) {
165
- // If there's an error, continue without authentication
166
- // This makes the middleware truly optional
167
- next();
168
- }
169
- };
170
- }
171
-
172
- /**
173
- * Utility function to quickly set up a complete Express app with authentication
174
- *
175
- * @example
176
- * ```typescript
177
- * import { createOxyExpressApp } from '@oxyhq/services/node';
178
- *
179
- * const app = createOxyExpressApp();
180
- *
181
- * // All routes automatically have authentication and req.user available
182
- * app.get('/api/profile', (req, res) => {
183
- * res.json({ user: req.user });
184
- * });
185
- *
186
- * app.listen(3000);
187
- * ```
188
- */
189
- export function createOxyExpressApp(config = {}) {
190
- // This is a lightweight helper - users should import express themselves
191
- // We'll provide the middleware setup instructions instead
192
-
193
- throw new Error('createOxyExpressApp is not implemented yet. Please use createOxyAuth() middleware with your existing Express app.');
194
- }
195
-
196
- // Re-export for convenience
197
- export { OxyServices } from '../core';
198
- export * from '../models/interfaces';
199
- //# sourceMappingURL=middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["OxyServices","createOxyAuth","config","baseURL","process","env","OXY_API_URL","loadUser","publicPaths","onError","oxy","req","res","next","isPublicPath","some","path","startsWith","authHeader","headers","token","split","error","message","code","status","json","authResult","authenticateToken","valid","userId","accessToken","user","id","apiError","createOptionalOxyAuth","createOxyExpressApp","Error"],"sourceRoot":"../../../src","sources":["node/middleware.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,QAAQ,SAAS;AAoBrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACC,MAAqB,GAAG,CAAC,CAAC,EAAE;EACxD,MAAM;IACJC,OAAO,GAAGC,OAAO,CAACC,GAAG,CAACC,WAAW,IAAI,uBAAuB;IAC5DC,QAAQ,GAAG,IAAI;IACfC,WAAW,GAAG,EAAE;IAChBC;EACF,CAAC,GAAGP,MAAM;EAEV,MAAMQ,GAAG,GAAG,IAAIV,WAAW,CAAC;IAAEG;EAAQ,CAAC,CAAC;EAExC,OAAO,OAAOQ,GAAQ,EAAEC,GAAQ,EAAEC,IAAS,KAAK;IAC9C;IACA,MAAMC,YAAY,GAAGN,WAAW,CAACO,IAAI,CAACC,IAAI,IACxCL,GAAG,CAACK,IAAI,KAAKA,IAAI,IAAIL,GAAG,CAACK,IAAI,CAACC,UAAU,CAACD,IAAI,GAAG,GAAG,CACrD,CAAC;IAED,IAAIF,YAAY,EAAE;MAChB,OAAOD,IAAI,CAAC,CAAC;IACf;IAEA,IAAI;MACF,MAAMK,UAAU,GAAGP,GAAG,CAACQ,OAAO,CAAC,eAAe,CAAC;MAC/C,MAAMC,KAAK,GAAGF,UAAU,IAAIA,UAAU,CAACG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;MAEtD,IAAI,CAACD,KAAK,EAAE;QACV,MAAME,KAAe,GAAG;UACtBC,OAAO,EAAE,uBAAuB;UAChCC,IAAI,EAAE,eAAe;UACrBC,MAAM,EAAE;QACV,CAAC;QAED,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WAAW,GAAGX,KAAK;QAEvB,IAAIb,QAAQ,IAAIoB,UAAU,CAACK,IAAI,EAAE;UAC/BrB,GAAG,CAACqB,IAAI,GAAGL,UAAU,CAACK,IAAI;QAC5B,CAAC,MAAM;UACLrB,GAAG,CAACqB,IAAI,GAAG;YAAEC,EAAE,EAAEN,UAAU,CAACG;UAAO,CAAC;QACtC;MACF;MAEAjB,IAAI,CAAC,CAAC;IACR,CAAC,CAAC,OAAOS,KAAK,EAAE;MACd;MACA;MACAT,IAAI,CAAC,CAAC;IACR;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASuB,mBAAmBA,CAAClC,MAOnC,GAAG,CAAC,CAAC,EAAE;EACN;EACA;;EAEA,MAAM,IAAImC,KAAK,CAAC,mHAAmH,CAAC;AACtI;;AAEA;AACA,SAASrC,WAAW,QAAQ,SAAS;AACrC,cAAc,sBAAsB","ignoreList":[]}
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Zero-config exports for OxyHQ Services
5
- */
6
-
7
- export { OxyZeroConfigProvider, useOxyZeroConfig, useOxyApi } from './provider';
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["OxyZeroConfigProvider","useOxyZeroConfig","useOxyApi"],"sourceRoot":"../../../../src","sources":["ui/zero-config/index.ts"],"mappings":";;AAAA;AACA;AACA;;AAEA,SACEA,qBAAqB,EACrBC,gBAAgB,EAChBC,SAAS,QAGJ,YAAY","ignoreList":[]}