@oxyhq/services 5.22.0 → 5.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WebOxyProvider = WebOxyProvider;
7
+ exports.useAuth = useAuth;
8
+ exports.useWebOxy = useWebOxy;
9
+ var _react = require("react");
10
+ var _index = require("../core/index.js");
11
+ var _reactQuery = require("@tanstack/react-query");
12
+ var _queryClient = require("../ui/hooks/queryClient.js");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ /**
15
+ * Web-Only Oxy Context
16
+ * Clean implementation with ZERO React Native dependencies
17
+ */
18
+
19
+ const WebOxyContext = /*#__PURE__*/(0, _react.createContext)(null);
20
+ /**
21
+ * Web-only Oxy Provider
22
+ * Minimal, clean implementation for web apps
23
+ */
24
+ function WebOxyProvider({
25
+ children,
26
+ baseURL,
27
+ authWebUrl,
28
+ onAuthStateChange
29
+ }) {
30
+ const [oxyServices] = (0, _react.useState)(() => new _index.OxyServices({
31
+ baseURL,
32
+ authWebUrl
33
+ }));
34
+ const [user, setUser] = (0, _react.useState)(null);
35
+ const [isLoading, setIsLoading] = (0, _react.useState)(true);
36
+ const [error, setError] = (0, _react.useState)(null);
37
+ const [queryClient] = (0, _react.useState)(() => (0, _queryClient.createQueryClient)());
38
+ const isAuthenticated = !!user;
39
+
40
+ // Initialize - check for existing session
41
+ (0, _react.useEffect)(() => {
42
+ let mounted = true;
43
+ const initAuth = async () => {
44
+ try {
45
+ // Try to get sessions from storage (localStorage)
46
+ const sessions = await oxyServices.getAllSessions();
47
+ if (sessions && sessions.length > 0) {
48
+ const activeSession = sessions.find(s => s.isCurrent) || sessions[0];
49
+
50
+ // Try to get user info from the active session's userId
51
+ if (activeSession && activeSession.userId) {
52
+ try {
53
+ const userProfile = await oxyServices.getProfile(activeSession.userId);
54
+ if (mounted && userProfile) {
55
+ setUser(userProfile);
56
+ setIsLoading(false);
57
+ return;
58
+ }
59
+ } catch (err) {
60
+ console.log('[WebOxy] Could not fetch user profile:', err);
61
+ }
62
+ }
63
+ }
64
+
65
+ // No active session - check for cross-domain SSO via FedCM
66
+ if (typeof window !== 'undefined' && 'IdentityCredential' in window) {
67
+ try {
68
+ const credential = await navigator.credentials.get({
69
+ // @ts-expect-error - FedCM identity property is not in standard types
70
+ identity: {
71
+ providers: [{
72
+ configURL: `${authWebUrl || 'https://auth.oxy.so'}/fedcm.json`,
73
+ clientId: window.location.origin
74
+ }]
75
+ }
76
+ });
77
+ if (credential && 'token' in credential) {
78
+ // Use the token to authenticate
79
+ const session = await oxyServices.authenticateWithToken(credential.token);
80
+ if (mounted && session.user) {
81
+ setUser(session.user);
82
+ }
83
+ }
84
+ } catch (fedcmError) {
85
+ // FedCM not available or user cancelled - this is fine
86
+ console.log('[WebOxy] FedCM SSO not available:', fedcmError);
87
+ }
88
+ }
89
+ } catch (err) {
90
+ console.error('[WebOxy] Init error:', err);
91
+ if (mounted) {
92
+ setError(err instanceof Error ? err.message : 'Failed to initialize auth');
93
+ }
94
+ } finally {
95
+ if (mounted) {
96
+ setIsLoading(false);
97
+ }
98
+ }
99
+ };
100
+ initAuth();
101
+ return () => {
102
+ mounted = false;
103
+ };
104
+ }, [oxyServices, authWebUrl]);
105
+
106
+ // Notify parent of auth state changes
107
+ (0, _react.useEffect)(() => {
108
+ onAuthStateChange?.(user);
109
+ }, [user, onAuthStateChange]);
110
+ const signIn = (0, _react.useCallback)(async () => {
111
+ setError(null);
112
+ setIsLoading(true);
113
+ try {
114
+ // Open popup to auth.oxy.so
115
+ const popup = window.open(`${authWebUrl || 'https://auth.oxy.so'}/login?origin=${encodeURIComponent(window.location.origin)}`, 'oxy-auth', 'width=500,height=700,popup=yes');
116
+ if (!popup) {
117
+ throw new Error('Popup blocked. Please allow popups for this site.');
118
+ }
119
+
120
+ // Listen for message from popup
121
+ const handleMessage = async event => {
122
+ if (event.origin !== (authWebUrl || 'https://auth.oxy.so')) {
123
+ return;
124
+ }
125
+ if (event.data.type === 'oxy-auth-success') {
126
+ const {
127
+ sessionId,
128
+ accessToken,
129
+ user: authUser
130
+ } = event.data;
131
+
132
+ // Store session (note: user property doesn't exist in ClientSession type)
133
+ const session = {
134
+ sessionId,
135
+ deviceId: event.data.deviceId || '',
136
+ expiresAt: event.data.expiresAt || '',
137
+ lastActive: new Date().toISOString(),
138
+ userId: authUser.id,
139
+ isCurrent: true
140
+ };
141
+ await oxyServices.storeSession(session);
142
+ setUser(authUser);
143
+ setIsLoading(false);
144
+ window.removeEventListener('message', handleMessage);
145
+ popup.close();
146
+ } else if (event.data.type === 'oxy-auth-error') {
147
+ setError(event.data.error || 'Authentication failed');
148
+ setIsLoading(false);
149
+ window.removeEventListener('message', handleMessage);
150
+ popup.close();
151
+ }
152
+ };
153
+ window.addEventListener('message', handleMessage);
154
+
155
+ // Check if popup was closed
156
+ const checkClosed = setInterval(() => {
157
+ if (popup.closed) {
158
+ clearInterval(checkClosed);
159
+ window.removeEventListener('message', handleMessage);
160
+ setIsLoading(false);
161
+ }
162
+ }, 500);
163
+ } catch (err) {
164
+ console.error('[WebOxy] Sign in error:', err);
165
+ setError(err instanceof Error ? err.message : 'Sign in failed');
166
+ setIsLoading(false);
167
+ }
168
+ }, [oxyServices, authWebUrl]);
169
+ const signOut = (0, _react.useCallback)(async () => {
170
+ setError(null);
171
+ try {
172
+ await oxyServices.logout();
173
+ setUser(null);
174
+ } catch (err) {
175
+ console.error('[WebOxy] Sign out error:', err);
176
+ setError(err instanceof Error ? err.message : 'Sign out failed');
177
+ }
178
+ }, [oxyServices]);
179
+ const contextValue = {
180
+ user,
181
+ isAuthenticated,
182
+ isLoading,
183
+ error,
184
+ signIn,
185
+ signOut,
186
+ oxyServices
187
+ };
188
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
189
+ client: queryClient,
190
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(WebOxyContext.Provider, {
191
+ value: contextValue,
192
+ children: children
193
+ })
194
+ });
195
+ }
196
+ function useWebOxy() {
197
+ const context = (0, _react.useContext)(WebOxyContext);
198
+ if (!context) {
199
+ throw new Error('useWebOxy must be used within WebOxyProvider');
200
+ }
201
+ return context;
202
+ }
203
+ function useAuth() {
204
+ const {
205
+ user,
206
+ isAuthenticated,
207
+ isLoading,
208
+ error,
209
+ signIn,
210
+ signOut,
211
+ oxyServices
212
+ } = useWebOxy();
213
+ return {
214
+ user,
215
+ isAuthenticated,
216
+ isLoading,
217
+ isReady: !isLoading,
218
+ error,
219
+ signIn,
220
+ signOut,
221
+ oxyServices
222
+ };
223
+ }
224
+ //# sourceMappingURL=WebOxyContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_index","_reactQuery","_queryClient","_jsxRuntime","WebOxyContext","createContext","WebOxyProvider","children","baseURL","authWebUrl","onAuthStateChange","oxyServices","useState","OxyServices","user","setUser","isLoading","setIsLoading","error","setError","queryClient","createQueryClient","isAuthenticated","useEffect","mounted","initAuth","sessions","getAllSessions","length","activeSession","find","s","isCurrent","userId","userProfile","getProfile","err","console","log","window","credential","navigator","credentials","get","identity","providers","configURL","clientId","location","origin","session","authenticateWithToken","token","fedcmError","Error","message","signIn","useCallback","popup","open","encodeURIComponent","handleMessage","event","data","type","sessionId","accessToken","authUser","deviceId","expiresAt","lastActive","Date","toISOString","id","storeSession","removeEventListener","close","addEventListener","checkClosed","setInterval","closed","clearInterval","signOut","logout","contextValue","jsx","QueryClientProvider","client","Provider","value","useWebOxy","context","useContext","useAuth","isReady"],"sourceRoot":"../../../src","sources":["web/WebOxyContext.tsx"],"mappings":";;;;;;;;AAKA,IAAAA,MAAA,GAAAC,OAAA;AAQA,IAAAC,MAAA,GAAAD,OAAA;AAGA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAA4D,IAAAI,WAAA,GAAAJ,O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AAE,CAAC9E,SAAS;IACnBE,KAAK;IACLsC,MAAM;IACN0B,OAAO;IACPvE;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "CrossDomainAuth", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _index.CrossDomainAuth;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "DeviceManager", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _index.DeviceManager;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "OXY_CLOUD_URL", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _index.OXY_CLOUD_URL;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "OxyAuthenticationError", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _index.OxyAuthenticationError;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "OxyAuthenticationTimeoutError", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _index.OxyAuthenticationTimeoutError;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "OxyServices", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _index.OxyServices;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "SUPPORTED_LANGUAGES", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _languageUtils.SUPPORTED_LANGUAGES;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "WebOxyProvider", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _WebOxyContext.WebOxyProvider;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "createCrossDomainAuth", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _index.createCrossDomainAuth;
58
+ }
59
+ });
60
+ exports.default = void 0;
61
+ Object.defineProperty(exports, "getLanguageMetadata", {
62
+ enumerable: true,
63
+ get: function () {
64
+ return _languageUtils.getLanguageMetadata;
65
+ }
66
+ });
67
+ Object.defineProperty(exports, "getLanguageName", {
68
+ enumerable: true,
69
+ get: function () {
70
+ return _languageUtils.getLanguageName;
71
+ }
72
+ });
73
+ Object.defineProperty(exports, "getNativeLanguageName", {
74
+ enumerable: true,
75
+ get: function () {
76
+ return _languageUtils.getNativeLanguageName;
77
+ }
78
+ });
79
+ Object.defineProperty(exports, "normalizeLanguageCode", {
80
+ enumerable: true,
81
+ get: function () {
82
+ return _languageUtils.normalizeLanguageCode;
83
+ }
84
+ });
85
+ Object.defineProperty(exports, "oxyClient", {
86
+ enumerable: true,
87
+ get: function () {
88
+ return _index.oxyClient;
89
+ }
90
+ });
91
+ Object.defineProperty(exports, "useAuth", {
92
+ enumerable: true,
93
+ get: function () {
94
+ return _WebOxyContext.useAuth;
95
+ }
96
+ });
97
+ Object.defineProperty(exports, "useWebOxy", {
98
+ enumerable: true,
99
+ get: function () {
100
+ return _WebOxyContext.useWebOxy;
101
+ }
102
+ });
103
+ var _index = require("../core/index.js");
104
+ var _WebOxyContext = require("./WebOxyContext.js");
105
+ var _languageUtils = require("../utils/languageUtils.js");
106
+ /**
107
+ * @oxyhq/services/web - Web-Only Module
108
+ *
109
+ * Clean, professional web module with ZERO React Native dependencies.
110
+ * Perfect for Next.js, Vite, Create React App, and other pure React web apps.
111
+ *
112
+ * Features:
113
+ * - WebOxyProvider for React context
114
+ * - useAuth hook for authentication
115
+ * - Cross-domain SSO via FedCM
116
+ * - Full TypeScript support
117
+ * - Zero bundler configuration needed
118
+ *
119
+ * Usage:
120
+ * ```tsx
121
+ * import { WebOxyProvider, useAuth } from '@oxyhq/services/web';
122
+ *
123
+ * function App() {
124
+ * return (
125
+ * <WebOxyProvider baseURL="https://api.oxy.so">
126
+ * <YourApp />
127
+ * </WebOxyProvider>
128
+ * );
129
+ * }
130
+ *
131
+ * function YourApp() {
132
+ * const { user, isAuthenticated, signIn, signOut } = useAuth();
133
+ * // ... your app logic
134
+ * }
135
+ * ```
136
+ */
137
+ // ==================== Core API ====================
138
+ // Re-export core services (zero React Native deps)
139
+ // ==================== Web Components ====================
140
+ // ==================== Models & Types ====================
141
+ // Re-export commonly used types
142
+ // Re-export session types
143
+ // ==================== Utilities ====================
144
+ // Default export for convenience
145
+ var _default = exports.default = _WebOxyContext.WebOxyProvider;
146
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_index","require","_WebOxyContext","_languageUtils","_default","exports","default","WebOxyProvider"],"sourceRoot":"../../../src","sources":["web/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAAA,MAAA,GAAAC,OAAA;AAkBA,IAAAC,cAAA,GAAAD,OAAA;AAsBA,IAAAE,cAAA,GAAAF,OAAA;AA1EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAkBA;AAIA;AACA;AAcA;AAGA;AAWA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEeC,6BAAc","ignoreList":[]}
@@ -73,8 +73,6 @@ var _exportNames = {
73
73
  SessionSyncRequiredError: true,
74
74
  AuthenticationFailedError: true,
75
75
  useFileFiltering: true,
76
- OxySignInButton: true,
77
- OxyLogo: true,
78
76
  ErrorCodes: true,
79
77
  createApiError: true,
80
78
  handleHttpError: true,
@@ -82,7 +80,6 @@ var _exportNames = {
82
80
  retryWithBackoff: true,
83
81
  logger: true,
84
82
  LogLevel: true,
85
- LogContext: true,
86
83
  logAuth: true,
87
84
  logApi: true,
88
85
  logSession: true,
@@ -121,12 +118,6 @@ Object.defineProperty(exports, "KeyManager", {
121
118
  return _index2.KeyManager;
122
119
  }
123
120
  });
124
- Object.defineProperty(exports, "LogContext", {
125
- enumerable: true,
126
- get: function () {
127
- return _loggerUtils.LogContext;
128
- }
129
- });
130
121
  Object.defineProperty(exports, "LogLevel", {
131
122
  enumerable: true,
132
123
  get: function () {
@@ -151,24 +142,12 @@ Object.defineProperty(exports, "OxyAuthenticationTimeoutError", {
151
142
  return _index.OxyAuthenticationTimeoutError;
152
143
  }
153
144
  });
154
- Object.defineProperty(exports, "OxyLogo", {
155
- enumerable: true,
156
- get: function () {
157
- return _OxyLogo.OxyLogo;
158
- }
159
- });
160
145
  Object.defineProperty(exports, "OxyServices", {
161
146
  enumerable: true,
162
147
  get: function () {
163
148
  return _index.OxyServices;
164
149
  }
165
150
  });
166
- Object.defineProperty(exports, "OxySignInButton", {
167
- enumerable: true,
168
- get: function () {
169
- return _OxySignInButton.OxySignInButton;
170
- }
171
- });
172
151
  Object.defineProperty(exports, "RecoveryPhraseService", {
173
152
  enumerable: true,
174
153
  get: function () {
@@ -626,8 +605,6 @@ var _index4 = require("./ui/hooks/mutations/index.js");
626
605
  var _mutationFactory = require("./ui/hooks/mutations/mutationFactory.js");
627
606
  var _authHelpers = require("./ui/utils/authHelpers.js");
628
607
  var _useFileFiltering = require("./ui/hooks/useFileFiltering.js");
629
- var _OxySignInButton = require("./ui/components/OxySignInButton.js");
630
- var _OxyLogo = require("./ui/components/OxyLogo.js");
631
608
  var _apiUtils = require("./utils/apiUtils.js");
632
609
  Object.keys(_apiUtils).forEach(function (key) {
633
610
  if (key === "default" || key === "__esModule") return;
@@ -1 +1 @@
1
- {"version":3,"names":["require","_index","_index2","_OxyContext","_useAuth","_WebOxyProvider","_interopRequireDefault","_deviceManager","_languageUtils","_interfaces","_authStore","_assetStore","_useSessionSocket","_useAssets","_useFileDownloadUrl","_index3","_index4","_mutationFactory","_authHelpers","_useFileFiltering","_OxySignInButton","_OxyLogo","_apiUtils","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_errorUtils","_validationUtils","_loggerUtils","_asyncUtils","_hookUtils","e","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GAAAtC,OAAA;AAAAuB,MAAA,CAAAC,IAAA,CAAAc,WAAA,EAAAb,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAY,WAAA,CAAAZ,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,WAAA,CAAAZ,GAAA;IAAA;EAAA;AAAA;AACA,IAAAa,UAAA,GAAAvC,OAAA;AAAAuB,MAAA,CAAAC,IAAA,CAAAe,UAAA,EAAAd,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAa,UAAA,CAAAb,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAK,UAAA,CAAAb,GAAA;IAAA;EAAA;AAAA;AAAkC,SAAApB,uBAAAkC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
1
+ {"version":3,"names":["require","_index","_index2","_OxyContext","_useAuth","_WebOxyProvider","_interopRequireDefault","_deviceManager","_languageUtils","_interfaces","_authStore","_assetStore","_useSessionSocket","_useAssets","_useFileDownloadUrl","_index3","_index4","_mutationFactory","_authHelpers","_useFileFiltering","_apiUtils","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_errorUtils","_validationUtils","_loggerUtils","_asyncUtils","_hookUtils","e","__esModule","default"],"sourceRoot":"../../src","sources":["web.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBAA,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AAQA,IAAAE,OAAA,GAAAF,OAAA;AAaA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAIA,IAAAK,eAAA,GAAAC,sBAAA,CAAAN,OAAA;AAGA,IAAAO,cAAA,GAAAP,OAAA;AAIA,IAAAQ,cAAA,GAAAR,OAAA;AAiEA,IAAAS,WAAA,GAAAT,OAAA;AASA,IAAAU,UAAA,GAAAV,OAAA;AACA,IAAAW,WAAA,GAAAX,OAAA;AAcA,IAAAY,iBAAA,GAAAZ,OAAA;AACA,IAAAa,UAAA,GAAAb,OAAA;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AAC,IAAA,CAAAc,WAAA,EAAAb,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAY,WAAA,CAAAZ,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,WAAA,CAAAZ,GAAA;IAAA;EAAA;AAAA;AACA,IAAAa,UAAA,GAAArC,OAAA;AAAAqB,MAAA,CAAAC,IAAA,CAAAe,UAAA,EAAAd,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAa,UAAA,CAAAb,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAK,UAAA,CAAAb,GAAA;IAAA;EAAA;AAAA;AAAkC,SAAAlB,uBAAAgC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Web-Only Oxy Context
5
+ * Clean implementation with ZERO React Native dependencies
6
+ */
7
+
8
+ import { createContext, useCallback, useContext, useEffect, useState } from 'react';
9
+ import { OxyServices } from "../core/index.js";
10
+ import { QueryClientProvider } from '@tanstack/react-query';
11
+ import { createQueryClient } from "../ui/hooks/queryClient.js";
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ const WebOxyContext = /*#__PURE__*/createContext(null);
14
+ /**
15
+ * Web-only Oxy Provider
16
+ * Minimal, clean implementation for web apps
17
+ */
18
+ export function WebOxyProvider({
19
+ children,
20
+ baseURL,
21
+ authWebUrl,
22
+ onAuthStateChange
23
+ }) {
24
+ const [oxyServices] = useState(() => new OxyServices({
25
+ baseURL,
26
+ authWebUrl
27
+ }));
28
+ const [user, setUser] = useState(null);
29
+ const [isLoading, setIsLoading] = useState(true);
30
+ const [error, setError] = useState(null);
31
+ const [queryClient] = useState(() => createQueryClient());
32
+ const isAuthenticated = !!user;
33
+
34
+ // Initialize - check for existing session
35
+ useEffect(() => {
36
+ let mounted = true;
37
+ const initAuth = async () => {
38
+ try {
39
+ // Try to get sessions from storage (localStorage)
40
+ const sessions = await oxyServices.getAllSessions();
41
+ if (sessions && sessions.length > 0) {
42
+ const activeSession = sessions.find(s => s.isCurrent) || sessions[0];
43
+
44
+ // Try to get user info from the active session's userId
45
+ if (activeSession && activeSession.userId) {
46
+ try {
47
+ const userProfile = await oxyServices.getProfile(activeSession.userId);
48
+ if (mounted && userProfile) {
49
+ setUser(userProfile);
50
+ setIsLoading(false);
51
+ return;
52
+ }
53
+ } catch (err) {
54
+ console.log('[WebOxy] Could not fetch user profile:', err);
55
+ }
56
+ }
57
+ }
58
+
59
+ // No active session - check for cross-domain SSO via FedCM
60
+ if (typeof window !== 'undefined' && 'IdentityCredential' in window) {
61
+ try {
62
+ const credential = await navigator.credentials.get({
63
+ // @ts-expect-error - FedCM identity property is not in standard types
64
+ identity: {
65
+ providers: [{
66
+ configURL: `${authWebUrl || 'https://auth.oxy.so'}/fedcm.json`,
67
+ clientId: window.location.origin
68
+ }]
69
+ }
70
+ });
71
+ if (credential && 'token' in credential) {
72
+ // Use the token to authenticate
73
+ const session = await oxyServices.authenticateWithToken(credential.token);
74
+ if (mounted && session.user) {
75
+ setUser(session.user);
76
+ }
77
+ }
78
+ } catch (fedcmError) {
79
+ // FedCM not available or user cancelled - this is fine
80
+ console.log('[WebOxy] FedCM SSO not available:', fedcmError);
81
+ }
82
+ }
83
+ } catch (err) {
84
+ console.error('[WebOxy] Init error:', err);
85
+ if (mounted) {
86
+ setError(err instanceof Error ? err.message : 'Failed to initialize auth');
87
+ }
88
+ } finally {
89
+ if (mounted) {
90
+ setIsLoading(false);
91
+ }
92
+ }
93
+ };
94
+ initAuth();
95
+ return () => {
96
+ mounted = false;
97
+ };
98
+ }, [oxyServices, authWebUrl]);
99
+
100
+ // Notify parent of auth state changes
101
+ useEffect(() => {
102
+ onAuthStateChange?.(user);
103
+ }, [user, onAuthStateChange]);
104
+ const signIn = useCallback(async () => {
105
+ setError(null);
106
+ setIsLoading(true);
107
+ try {
108
+ // Open popup to auth.oxy.so
109
+ const popup = window.open(`${authWebUrl || 'https://auth.oxy.so'}/login?origin=${encodeURIComponent(window.location.origin)}`, 'oxy-auth', 'width=500,height=700,popup=yes');
110
+ if (!popup) {
111
+ throw new Error('Popup blocked. Please allow popups for this site.');
112
+ }
113
+
114
+ // Listen for message from popup
115
+ const handleMessage = async event => {
116
+ if (event.origin !== (authWebUrl || 'https://auth.oxy.so')) {
117
+ return;
118
+ }
119
+ if (event.data.type === 'oxy-auth-success') {
120
+ const {
121
+ sessionId,
122
+ accessToken,
123
+ user: authUser
124
+ } = event.data;
125
+
126
+ // Store session (note: user property doesn't exist in ClientSession type)
127
+ const session = {
128
+ sessionId,
129
+ deviceId: event.data.deviceId || '',
130
+ expiresAt: event.data.expiresAt || '',
131
+ lastActive: new Date().toISOString(),
132
+ userId: authUser.id,
133
+ isCurrent: true
134
+ };
135
+ await oxyServices.storeSession(session);
136
+ setUser(authUser);
137
+ setIsLoading(false);
138
+ window.removeEventListener('message', handleMessage);
139
+ popup.close();
140
+ } else if (event.data.type === 'oxy-auth-error') {
141
+ setError(event.data.error || 'Authentication failed');
142
+ setIsLoading(false);
143
+ window.removeEventListener('message', handleMessage);
144
+ popup.close();
145
+ }
146
+ };
147
+ window.addEventListener('message', handleMessage);
148
+
149
+ // Check if popup was closed
150
+ const checkClosed = setInterval(() => {
151
+ if (popup.closed) {
152
+ clearInterval(checkClosed);
153
+ window.removeEventListener('message', handleMessage);
154
+ setIsLoading(false);
155
+ }
156
+ }, 500);
157
+ } catch (err) {
158
+ console.error('[WebOxy] Sign in error:', err);
159
+ setError(err instanceof Error ? err.message : 'Sign in failed');
160
+ setIsLoading(false);
161
+ }
162
+ }, [oxyServices, authWebUrl]);
163
+ const signOut = useCallback(async () => {
164
+ setError(null);
165
+ try {
166
+ await oxyServices.logout();
167
+ setUser(null);
168
+ } catch (err) {
169
+ console.error('[WebOxy] Sign out error:', err);
170
+ setError(err instanceof Error ? err.message : 'Sign out failed');
171
+ }
172
+ }, [oxyServices]);
173
+ const contextValue = {
174
+ user,
175
+ isAuthenticated,
176
+ isLoading,
177
+ error,
178
+ signIn,
179
+ signOut,
180
+ oxyServices
181
+ };
182
+ return /*#__PURE__*/_jsx(QueryClientProvider, {
183
+ client: queryClient,
184
+ children: /*#__PURE__*/_jsx(WebOxyContext.Provider, {
185
+ value: contextValue,
186
+ children: children
187
+ })
188
+ });
189
+ }
190
+ export function useWebOxy() {
191
+ const context = useContext(WebOxyContext);
192
+ if (!context) {
193
+ throw new Error('useWebOxy must be used within WebOxyProvider');
194
+ }
195
+ return context;
196
+ }
197
+ export function useAuth() {
198
+ const {
199
+ user,
200
+ isAuthenticated,
201
+ isLoading,
202
+ error,
203
+ signIn,
204
+ signOut,
205
+ oxyServices
206
+ } = useWebOxy();
207
+ return {
208
+ user,
209
+ isAuthenticated,
210
+ isLoading,
211
+ isReady: !isLoading,
212
+ error,
213
+ signIn,
214
+ signOut,
215
+ oxyServices
216
+ };
217
+ }
218
+ //# sourceMappingURL=WebOxyContext.js.map