@oxyhq/services 6.9.19 → 6.9.21

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 (35) hide show
  1. package/lib/commonjs/index.js +3 -4
  2. package/lib/commonjs/index.js.map +1 -1
  3. package/lib/commonjs/ui/context/OxyContext.js +33 -1
  4. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  5. package/lib/commonjs/ui/hooks/useAuth.js +8 -0
  6. package/lib/commonjs/ui/hooks/useAuth.js.map +1 -1
  7. package/lib/commonjs/ui/index.js +95 -131
  8. package/lib/commonjs/ui/index.js.map +1 -1
  9. package/lib/module/index.js +1 -2
  10. package/lib/module/index.js.map +1 -1
  11. package/lib/module/ui/context/OxyContext.js +33 -1
  12. package/lib/module/ui/context/OxyContext.js.map +1 -1
  13. package/lib/module/ui/hooks/useAuth.js +3 -0
  14. package/lib/module/ui/hooks/useAuth.js.map +1 -1
  15. package/lib/module/ui/index.js +86 -34
  16. package/lib/module/ui/index.js.map +1 -1
  17. package/lib/typescript/commonjs/index.d.ts +1 -2
  18. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  19. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
  20. package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts +1 -0
  21. package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts.map +1 -1
  22. package/lib/typescript/commonjs/ui/index.d.ts +21 -28
  23. package/lib/typescript/commonjs/ui/index.d.ts.map +1 -1
  24. package/lib/typescript/module/index.d.ts +1 -2
  25. package/lib/typescript/module/index.d.ts.map +1 -1
  26. package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
  27. package/lib/typescript/module/ui/hooks/useAuth.d.ts +1 -0
  28. package/lib/typescript/module/ui/hooks/useAuth.d.ts.map +1 -1
  29. package/lib/typescript/module/ui/index.d.ts +21 -28
  30. package/lib/typescript/module/ui/index.d.ts.map +1 -1
  31. package/package.json +10 -3
  32. package/src/index.ts +1 -2
  33. package/src/ui/context/OxyContext.tsx +35 -1
  34. package/src/ui/hooks/useAuth.ts +2 -0
  35. package/src/ui/index.ts +104 -33
@@ -712,10 +712,44 @@ export const OxyProvider: React.FC<OxyContextProviderProps> = ({
712
712
 
713
713
  export const OxyContextProvider = OxyProvider;
714
714
 
715
+ const noop = () => Promise.resolve() as any;
716
+
717
+ const LOADING_STATE: OxyContextState = {
718
+ user: null,
719
+ sessions: [],
720
+ activeSessionId: null,
721
+ isAuthenticated: false,
722
+ isLoading: true,
723
+ isTokenReady: false,
724
+ isStorageReady: false,
725
+ error: null,
726
+ currentLanguage: 'en',
727
+ currentLanguageMetadata: {} as any,
728
+ currentLanguageName: 'English',
729
+ currentNativeLanguageName: 'English',
730
+ hasIdentity: () => Promise.resolve(false),
731
+ getPublicKey: () => Promise.resolve(null),
732
+ signIn: noop,
733
+ handlePopupSession: noop,
734
+ logout: noop,
735
+ logoutAll: noop,
736
+ switchSession: noop,
737
+ removeSession: noop,
738
+ refreshSessions: noop,
739
+ setLanguage: noop,
740
+ getDeviceSessions: () => Promise.resolve([]),
741
+ logoutAllDeviceSessions: noop,
742
+ updateDeviceName: noop,
743
+ clearSessionState: noop,
744
+ clearAllAccountData: noop,
745
+ oxyServices: null as any,
746
+ openAvatarPicker: () => {},
747
+ };
748
+
715
749
  export const useOxy = (): OxyContextState => {
716
750
  const context = useContext(OxyContext);
717
751
  if (!context) {
718
- throw new Error('useOxy must be used within an OxyContextProvider');
752
+ return LOADING_STATE;
719
753
  }
720
754
  return context;
721
755
  };
@@ -209,3 +209,5 @@ export function useAuth(): UseAuthReturn {
209
209
  };
210
210
  }
211
211
 
212
+ // Re-export useOxy for backward compatibility and advanced usage
213
+ export { useOxy } from '../context/OxyContext';
package/src/ui/index.ts CHANGED
@@ -1,47 +1,115 @@
1
1
  /**
2
- * UI Component exports
2
+ * UI Component exports - Frontend Only (with backend-safe fallbacks)
3
3
  *
4
- * This is a React Native / Expo SDK — all exports are static imports.
5
- * For SSR environments, use '@oxyhq/services/ui/server' instead.
4
+ * This module exports all React/React Native UI components and hooks.
5
+ * In backend, all exports are no-ops or empty objects.
6
+ *
7
+ * NOTE: This entry point uses runtime detection which prevents tree-shaking.
8
+ * For better bundle optimization, use:
9
+ * - '@oxyhq/services/ui/client' for client bundles (tree-shakeable)
10
+ * - '@oxyhq/services/ui/server' for SSR environments (all noops)
6
11
  *
7
12
  * @example
8
- * import { OxyProvider, useOxy, Avatar } from '@oxyhq/services/ui';
13
+ * // Client bundle (tree-shakeable)
14
+ * import { OxyProvider, useOxy } from '@oxyhq/services/ui/client';
15
+ *
16
+ * // SSR (noops)
17
+ * import { OxyProvider, useOxy } from '@oxyhq/services/ui/server';
9
18
  */
19
+ import isFrontend from './isFrontend';
10
20
 
11
- // Components
12
- export { default as OxyProvider } from './components/OxyProvider';
13
- export { default as OxySignInButton } from './components/OxySignInButton';
14
- export { default as OxyLogo } from './components/OxyLogo';
15
- export { default as Avatar } from './components/Avatar';
16
- export { default as FollowButton } from './components/FollowButton';
17
- export { default as OxyPayButton } from './components/OxyPayButton';
18
- export { FontLoader, setupFonts } from './components/FontLoader';
19
- export { OxyIcon } from './components/icon';
20
-
21
- // Context
22
- export { useOxy } from './context/OxyContext';
23
-
24
- // Hooks
25
- export { useAuth } from './hooks/useAuth';
26
- export type { AuthState, AuthActions, UseAuthReturn } from './hooks/useAuth';
27
- export { useFollow } from './hooks';
28
- export { useStorage } from './hooks/useStorage';
29
- export type { UseStorageOptions, UseStorageResult } from './hooks/useStorage';
21
+ // UI exports
22
+ let OxyProvider;
23
+ let OxySignInButton;
24
+ let OxyLogo;
25
+ let Avatar;
26
+ let FollowButton;
27
+ let OxyPayButton;
28
+ let FontLoader;
29
+ let setupFonts;
30
+ let OxyIcon;
31
+ let useOxy;
32
+ let useAuth;
33
+ let useFollow;
34
+ let ProfileScreen;
35
+ let useAuthStore;
36
+ let useAccountStore;
37
+ let fontFamilies;
38
+ let fontStyles;
39
+ let toast;
40
+ let useStorage;
30
41
 
31
- // Screens
32
- export { default as ProfileScreen } from './screens/ProfileScreen';
42
+ if (isFrontend) {
43
+ OxyProvider = require('./components/OxyProvider').default;
44
+ OxySignInButton = require('./components/OxySignInButton').default;
45
+ OxyLogo = require('./components/OxyLogo').default;
46
+ Avatar = require('./components/Avatar').default;
47
+ FollowButton = require('./components/FollowButton').default;
48
+ OxyPayButton = require('./components/OxyPayButton').default;
49
+ FontLoader = require('./components/FontLoader').FontLoader;
50
+ setupFonts = require('./components/FontLoader').setupFonts;
51
+ OxyIcon = require('./components/icon').OxyIcon;
52
+ useOxy = require('./context/OxyContext').useOxy;
53
+ useAuth = require('./hooks/useAuth').useAuth;
54
+ useFollow = require('./hooks').useFollow;
55
+ ProfileScreen = require('./screens/ProfileScreen').default;
56
+ useAuthStore = require('./stores/authStore').useAuthStore;
57
+ useAccountStore = require('./stores/accountStore').useAccountStore;
58
+ fontFamilies = require('./styles/fonts').fontFamilies;
59
+ fontStyles = require('./styles/fonts').fontStyles;
60
+ toast = require('../lib/sonner').toast;
61
+ useStorage = require('./hooks/useStorage').useStorage;
62
+ } else {
63
+ // Backend: no-op fallbacks
64
+ const noopComponent = () => null;
65
+ const noopHook = () => ({});
66
+ const noopStorageResult = { storage: null, isReady: false };
33
67
 
34
- // Stores
35
- export { useAuthStore } from './stores/authStore';
36
- export { useAccountStore } from './stores/accountStore';
68
+ OxyProvider = noopComponent;
69
+ OxySignInButton = noopComponent;
70
+ OxyLogo = noopComponent;
71
+ Avatar = noopComponent;
72
+ FollowButton = noopComponent;
73
+ OxyPayButton = noopComponent;
74
+ FontLoader = noopComponent;
75
+ setupFonts = () => {};
76
+ OxyIcon = noopComponent;
77
+ useOxy = noopHook;
78
+ useAuth = noopHook;
79
+ useFollow = noopHook;
80
+ ProfileScreen = noopComponent;
81
+ useAuthStore = noopHook;
82
+ useAccountStore = noopHook;
83
+ fontFamilies = {};
84
+ fontStyles = {};
85
+ toast = () => {};
86
+ useStorage = () => noopStorageResult;
87
+ }
37
88
 
38
- // Styles
39
- export { fontFamilies, fontStyles } from './styles/fonts';
89
+ export {
90
+ OxyProvider,
91
+ OxySignInButton,
92
+ OxyLogo,
93
+ Avatar,
94
+ FollowButton,
95
+ OxyPayButton,
96
+ FontLoader,
97
+ setupFonts,
98
+ OxyIcon,
99
+ useOxy,
100
+ useAuth,
101
+ useFollow,
102
+ ProfileScreen,
103
+ useAuthStore,
104
+ useAccountStore,
105
+ fontFamilies,
106
+ fontStyles,
107
+ toast,
108
+ useStorage,
109
+ };
40
110
 
41
- // Toast
42
- export { toast } from '../lib/sonner';
43
111
 
44
- // Error handler utilities
112
+ // Export error handler utilities (pure functions, no conditional needed)
45
113
  export {
46
114
  handleAuthError,
47
115
  isInvalidSessionError,
@@ -49,3 +117,6 @@ export {
49
117
  extractErrorMessage,
50
118
  } from './utils/errorHandlers';
51
119
  export type { HandleAuthErrorOptions } from './utils/errorHandlers';
120
+
121
+ // Export useStorage hook and types (kept for external consumers)
122
+ export type { UseStorageOptions, UseStorageResult } from './hooks/useStorage';