@oxyhq/services 0.1.18 → 5.1.7
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.
- package/README.md +17 -138
- package/UI_COMPONENTS.md +142 -0
- package/lib/commonjs/assets/OxyLogo.svg +1 -0
- package/lib/commonjs/assets/assets/OxyLogo.svg +1 -0
- package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
- package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
- package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
- package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
- package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
- package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
- package/lib/commonjs/assets/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
- package/lib/commonjs/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
- package/lib/commonjs/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
- package/lib/commonjs/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
- package/lib/commonjs/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
- package/lib/commonjs/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
- package/lib/commonjs/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
- package/lib/commonjs/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
- package/lib/commonjs/core/index.js +783 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/index.js +128 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/models/interfaces.js +2 -0
- package/lib/commonjs/models/interfaces.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/ui/components/FontLoader.js +181 -0
- package/lib/commonjs/ui/components/FontLoader.js.map +1 -0
- package/lib/commonjs/ui/components/OxyLogo.js +56 -0
- package/lib/commonjs/ui/components/OxyLogo.js.map +1 -0
- package/lib/commonjs/ui/components/OxyProvider.js +464 -0
- package/lib/commonjs/ui/components/OxyProvider.js.map +1 -0
- package/lib/commonjs/ui/components/OxySignInButton.js +178 -0
- package/lib/commonjs/ui/components/OxySignInButton.js.map +1 -0
- package/lib/commonjs/ui/components/bottomSheet/index.js +37 -0
- package/lib/commonjs/ui/components/bottomSheet/index.js.map +1 -0
- package/lib/commonjs/ui/context/OxyContext.js +296 -0
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -0
- package/lib/commonjs/ui/index.js +136 -0
- package/lib/commonjs/ui/index.js.map +1 -0
- package/lib/commonjs/ui/navigation/OxyRouter.js +140 -0
- package/lib/commonjs/ui/navigation/OxyRouter.js.map +1 -0
- package/lib/commonjs/ui/navigation/types.js +6 -0
- package/lib/commonjs/ui/navigation/types.js.map +1 -0
- package/lib/commonjs/ui/screens/AccountCenterScreen.js +280 -0
- package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -0
- package/lib/commonjs/ui/screens/AccountOverviewScreen.js +578 -0
- package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -0
- package/lib/commonjs/ui/screens/SignInScreen.js +230 -0
- package/lib/commonjs/ui/screens/SignInScreen.js.map +1 -0
- package/lib/commonjs/ui/screens/SignUpScreen.js +673 -0
- package/lib/commonjs/ui/screens/SignUpScreen.js.map +1 -0
- package/lib/commonjs/ui/styles/FONTS.md +126 -0
- package/lib/commonjs/ui/styles/fonts.js +84 -0
- package/lib/commonjs/ui/styles/fonts.js.map +1 -0
- package/lib/commonjs/ui/styles/index.js +28 -0
- package/lib/commonjs/ui/styles/index.js.map +1 -0
- package/lib/commonjs/ui/styles/theme.js +122 -0
- package/lib/commonjs/ui/styles/theme.js.map +1 -0
- package/lib/module/assets/OxyLogo.svg +1 -0
- package/lib/module/assets/assets/OxyLogo.svg +1 -0
- package/lib/module/assets/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
- package/lib/module/assets/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
- package/lib/module/assets/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
- package/lib/module/assets/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
- package/lib/module/assets/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
- package/lib/module/assets/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
- package/lib/module/assets/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
- package/lib/module/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
- package/lib/module/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
- package/lib/module/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
- package/lib/module/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
- package/lib/module/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
- package/lib/module/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
- package/lib/module/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
- package/lib/module/core/index.js +777 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/index.js +29 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/models/interfaces.js +2 -0
- package/lib/module/models/interfaces.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/ui/components/FontLoader.js +176 -0
- package/lib/module/ui/components/FontLoader.js.map +1 -0
- package/lib/module/ui/components/OxyLogo.js +49 -0
- package/lib/module/ui/components/OxyLogo.js.map +1 -0
- package/lib/module/ui/components/OxyProvider.js +458 -0
- package/lib/module/ui/components/OxyProvider.js.map +1 -0
- package/lib/module/ui/components/OxySignInButton.js +172 -0
- package/lib/module/ui/components/OxySignInButton.js.map +1 -0
- package/lib/module/ui/components/bottomSheet/index.js +8 -0
- package/lib/module/ui/components/bottomSheet/index.js.map +1 -0
- package/lib/module/ui/context/OxyContext.js +291 -0
- package/lib/module/ui/context/OxyContext.js.map +1 -0
- package/lib/module/ui/index.js +25 -0
- package/lib/module/ui/index.js.map +1 -0
- package/lib/module/ui/navigation/OxyRouter.js +133 -0
- package/lib/module/ui/navigation/OxyRouter.js.map +1 -0
- package/lib/module/ui/navigation/types.js +4 -0
- package/lib/module/ui/navigation/types.js.map +1 -0
- package/lib/module/ui/screens/AccountCenterScreen.js +275 -0
- package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -0
- package/lib/module/ui/screens/AccountOverviewScreen.js +573 -0
- package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -0
- package/lib/module/ui/screens/SignInScreen.js +224 -0
- package/lib/module/ui/screens/SignInScreen.js.map +1 -0
- package/lib/module/ui/screens/SignUpScreen.js +668 -0
- package/lib/module/ui/screens/SignUpScreen.js.map +1 -0
- package/lib/module/ui/styles/FONTS.md +126 -0
- package/lib/module/ui/styles/fonts.js +81 -0
- package/lib/module/ui/styles/fonts.js.map +1 -0
- package/lib/module/ui/styles/index.js +5 -0
- package/lib/module/ui/styles/index.js.map +1 -0
- package/lib/module/ui/styles/theme.js +115 -0
- package/lib/module/ui/styles/theme.js.map +1 -0
- package/lib/typescript/core/index.d.ts +304 -0
- package/lib/typescript/core/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +11 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/models/interfaces.d.ts +98 -0
- package/lib/typescript/models/interfaces.d.ts.map +1 -0
- package/lib/typescript/ui/components/FontLoader.d.ts +15 -0
- package/lib/typescript/ui/components/FontLoader.d.ts.map +1 -0
- package/lib/typescript/ui/components/OxyLogo.d.ts +29 -0
- package/lib/typescript/ui/components/OxyLogo.d.ts.map +1 -0
- package/lib/typescript/ui/components/OxyProvider.d.ts +12 -0
- package/lib/typescript/ui/components/OxyProvider.d.ts.map +1 -0
- package/lib/typescript/ui/components/OxySignInButton.d.ts +65 -0
- package/lib/typescript/ui/components/OxySignInButton.d.ts.map +1 -0
- package/lib/typescript/ui/components/bottomSheet/index.d.ts +3 -0
- package/lib/typescript/ui/components/bottomSheet/index.d.ts.map +1 -0
- package/lib/typescript/ui/context/OxyContext.d.ts +26 -0
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -0
- package/lib/typescript/ui/index.d.ts +15 -0
- package/lib/typescript/ui/index.d.ts.map +1 -0
- package/lib/typescript/ui/navigation/OxyRouter.d.ts +5 -0
- package/lib/typescript/ui/navigation/OxyRouter.d.ts.map +1 -0
- package/lib/typescript/ui/navigation/types.d.ts +107 -0
- package/lib/typescript/ui/navigation/types.d.ts.map +1 -0
- package/lib/typescript/ui/screens/AccountCenterScreen.d.ts +5 -0
- package/lib/typescript/ui/screens/AccountCenterScreen.d.ts.map +1 -0
- package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts +5 -0
- package/lib/typescript/ui/screens/AccountOverviewScreen.d.ts.map +1 -0
- package/lib/typescript/ui/screens/SignInScreen.d.ts +5 -0
- package/lib/typescript/ui/screens/SignInScreen.d.ts.map +1 -0
- package/lib/typescript/ui/screens/SignUpScreen.d.ts +5 -0
- package/lib/typescript/ui/screens/SignUpScreen.d.ts.map +1 -0
- package/lib/typescript/ui/styles/fonts.d.ts +21 -0
- package/lib/typescript/ui/styles/fonts.d.ts.map +1 -0
- package/lib/typescript/ui/styles/index.d.ts +3 -0
- package/lib/typescript/ui/styles/index.d.ts.map +1 -0
- package/lib/typescript/ui/styles/theme.d.ts +69 -0
- package/lib/typescript/ui/styles/theme.d.ts.map +1 -0
- package/package.json +95 -51
- package/src/assets/OxyLogo.svg +1 -0
- package/src/assets/fonts/Phudu/Phudu-Black.ttf +0 -0
- package/src/assets/fonts/Phudu/Phudu-Bold.ttf +0 -0
- package/src/assets/fonts/Phudu/Phudu-ExtraBold.ttf +0 -0
- package/src/assets/fonts/Phudu/Phudu-Light.ttf +0 -0
- package/src/assets/fonts/Phudu/Phudu-Medium.ttf +0 -0
- package/src/assets/fonts/Phudu/Phudu-Regular.ttf +0 -0
- package/src/assets/fonts/Phudu/Phudu-SemiBold.ttf +0 -0
- package/src/core/index.ts +768 -0
- package/src/index.ts +46 -0
- package/src/models/interfaces.ts +128 -0
- package/src/ui/components/FontLoader.tsx +180 -0
- package/src/ui/components/OxyLogo.tsx +73 -0
- package/src/ui/components/OxyProvider.tsx +490 -0
- package/src/ui/components/OxySignInButton.tsx +207 -0
- package/src/ui/components/bottomSheet/index.tsx +12 -0
- package/src/ui/context/OxyContext.tsx +344 -0
- package/src/ui/index.ts +27 -0
- package/src/ui/navigation/OxyRouter.tsx +137 -0
- package/src/ui/navigation/types.ts +124 -0
- package/src/ui/screens/AccountCenterScreen.tsx +240 -0
- package/src/ui/screens/AccountOverviewScreen.tsx +519 -0
- package/src/ui/screens/SignInScreen.tsx +210 -0
- package/src/ui/screens/SignUpScreen.tsx +607 -0
- package/src/ui/styles/FONTS.md +126 -0
- package/src/ui/styles/fonts.ts +77 -0
- package/src/ui/styles/index.ts +2 -0
- package/src/ui/styles/theme.ts +142 -0
- package/dist/index.d.ts +0 -152
- package/dist/index.js +0 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
// Define the context shape
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
// Create the context with default values
|
|
8
|
+
const OxyContext = /*#__PURE__*/createContext(null);
|
|
9
|
+
|
|
10
|
+
// Props for the OxyContextProvider
|
|
11
|
+
|
|
12
|
+
// Platform storage implementation
|
|
13
|
+
|
|
14
|
+
// Web localStorage implementation
|
|
15
|
+
class WebStorage {
|
|
16
|
+
async getItem(key) {
|
|
17
|
+
return localStorage.getItem(key);
|
|
18
|
+
}
|
|
19
|
+
async setItem(key, value) {
|
|
20
|
+
localStorage.setItem(key, value);
|
|
21
|
+
}
|
|
22
|
+
async removeItem(key) {
|
|
23
|
+
localStorage.removeItem(key);
|
|
24
|
+
}
|
|
25
|
+
async clear() {
|
|
26
|
+
localStorage.clear();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// React Native AsyncStorage implementation
|
|
31
|
+
// This will be dynamically imported only in React Native environment
|
|
32
|
+
let AsyncStorage;
|
|
33
|
+
|
|
34
|
+
// Determine the platform and set up storage
|
|
35
|
+
const isReactNative = () => {
|
|
36
|
+
return typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Get appropriate storage for the platform
|
|
40
|
+
const getStorage = async () => {
|
|
41
|
+
if (isReactNative()) {
|
|
42
|
+
// Dynamically import AsyncStorage only in React Native environment
|
|
43
|
+
if (!AsyncStorage) {
|
|
44
|
+
try {
|
|
45
|
+
const asyncStorageModule = await import('@react-native-async-storage/async-storage');
|
|
46
|
+
AsyncStorage = asyncStorageModule.default;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error('Failed to import AsyncStorage:', error);
|
|
49
|
+
throw new Error('AsyncStorage is required in React Native environment');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return AsyncStorage;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Default to web storage
|
|
56
|
+
return new WebStorage();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Storage keys
|
|
60
|
+
const getStorageKeys = (prefix = 'oxy') => ({
|
|
61
|
+
accessToken: `${prefix}_access_token`,
|
|
62
|
+
refreshToken: `${prefix}_refresh_token`,
|
|
63
|
+
user: `${prefix}_user`
|
|
64
|
+
});
|
|
65
|
+
export const OxyContextProvider = ({
|
|
66
|
+
children,
|
|
67
|
+
oxyServices,
|
|
68
|
+
storageKeyPrefix = 'oxy',
|
|
69
|
+
onAuthStateChange,
|
|
70
|
+
bottomSheetRef
|
|
71
|
+
}) => {
|
|
72
|
+
// Authentication state
|
|
73
|
+
const [user, setUser] = useState(null);
|
|
74
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
75
|
+
const [error, setError] = useState(null);
|
|
76
|
+
const [storage, setStorage] = useState(null);
|
|
77
|
+
|
|
78
|
+
// Storage keys
|
|
79
|
+
const keys = getStorageKeys(storageKeyPrefix);
|
|
80
|
+
|
|
81
|
+
// Initialize storage
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const initStorage = async () => {
|
|
84
|
+
try {
|
|
85
|
+
const platformStorage = await getStorage();
|
|
86
|
+
setStorage(platformStorage);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Failed to initialize storage:', error);
|
|
89
|
+
setError('Failed to initialize storage');
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
initStorage();
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
// Effect to initialize authentication state
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const initAuth = async () => {
|
|
98
|
+
if (!storage) return;
|
|
99
|
+
setIsLoading(true);
|
|
100
|
+
try {
|
|
101
|
+
// Try to load tokens from storage
|
|
102
|
+
const accessToken = await storage.getItem(keys.accessToken);
|
|
103
|
+
const refreshToken = await storage.getItem(keys.refreshToken);
|
|
104
|
+
const storedUser = await storage.getItem(keys.user);
|
|
105
|
+
if (accessToken) {
|
|
106
|
+
// Set tokens in OxyServices
|
|
107
|
+
if (refreshToken) {
|
|
108
|
+
oxyServices.setTokens(accessToken, refreshToken);
|
|
109
|
+
} else {
|
|
110
|
+
// Use setTokens with the same token if setToken is not available
|
|
111
|
+
oxyServices.setTokens(accessToken, accessToken);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Validate the tokens
|
|
115
|
+
const isValid = await oxyServices.validate();
|
|
116
|
+
if (isValid && storedUser) {
|
|
117
|
+
// Set user state
|
|
118
|
+
const parsedUser = JSON.parse(storedUser);
|
|
119
|
+
setUser(parsedUser);
|
|
120
|
+
|
|
121
|
+
// Notify about auth state change
|
|
122
|
+
if (onAuthStateChange) {
|
|
123
|
+
onAuthStateChange(parsedUser);
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
// Tokens are invalid, clear everything
|
|
127
|
+
await clearStorage();
|
|
128
|
+
oxyServices.clearTokens();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.error('Auth initialization error:', err);
|
|
133
|
+
await clearStorage();
|
|
134
|
+
oxyServices.clearTokens();
|
|
135
|
+
} finally {
|
|
136
|
+
setIsLoading(false);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
if (storage) {
|
|
140
|
+
initAuth();
|
|
141
|
+
}
|
|
142
|
+
}, [storage, oxyServices, keys.accessToken, keys.refreshToken, keys.user, onAuthStateChange]);
|
|
143
|
+
|
|
144
|
+
// Helper to clear storage
|
|
145
|
+
const clearStorage = async () => {
|
|
146
|
+
if (!storage) return;
|
|
147
|
+
try {
|
|
148
|
+
await storage.removeItem(keys.accessToken);
|
|
149
|
+
await storage.removeItem(keys.refreshToken);
|
|
150
|
+
await storage.removeItem(keys.user);
|
|
151
|
+
} catch (err) {
|
|
152
|
+
console.error('Clear storage error:', err);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// Utility function to handle different token response formats
|
|
157
|
+
const storeTokens = async response => {
|
|
158
|
+
// Store token and user data
|
|
159
|
+
if (response.accessToken) {
|
|
160
|
+
await storage?.setItem(keys.accessToken, response.accessToken);
|
|
161
|
+
if (response.refreshToken) {
|
|
162
|
+
await storage?.setItem(keys.refreshToken, response.refreshToken);
|
|
163
|
+
}
|
|
164
|
+
} else if (response.token) {
|
|
165
|
+
// Handle legacy API response
|
|
166
|
+
await storage?.setItem(keys.accessToken, response.token);
|
|
167
|
+
}
|
|
168
|
+
await storage?.setItem(keys.user, JSON.stringify(response.user));
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// Login method
|
|
172
|
+
const login = async (username, password) => {
|
|
173
|
+
if (!storage) throw new Error('Storage not initialized');
|
|
174
|
+
setIsLoading(true);
|
|
175
|
+
setError(null);
|
|
176
|
+
try {
|
|
177
|
+
const response = await oxyServices.login(username, password);
|
|
178
|
+
setUser(response.user);
|
|
179
|
+
|
|
180
|
+
// Store tokens
|
|
181
|
+
await storeTokens(response);
|
|
182
|
+
|
|
183
|
+
// Notify about auth state change
|
|
184
|
+
if (onAuthStateChange) {
|
|
185
|
+
onAuthStateChange(response.user);
|
|
186
|
+
}
|
|
187
|
+
return response.user;
|
|
188
|
+
} catch (err) {
|
|
189
|
+
setError(err.message || 'Login failed');
|
|
190
|
+
throw err;
|
|
191
|
+
} finally {
|
|
192
|
+
setIsLoading(false);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// Logout method
|
|
197
|
+
const logout = async () => {
|
|
198
|
+
if (!storage) throw new Error('Storage not initialized');
|
|
199
|
+
setIsLoading(true);
|
|
200
|
+
setError(null);
|
|
201
|
+
try {
|
|
202
|
+
await oxyServices.logout();
|
|
203
|
+
await clearStorage();
|
|
204
|
+
setUser(null);
|
|
205
|
+
|
|
206
|
+
// Notify about auth state change
|
|
207
|
+
if (onAuthStateChange) {
|
|
208
|
+
onAuthStateChange(null);
|
|
209
|
+
}
|
|
210
|
+
} catch (err) {
|
|
211
|
+
setError(err.message || 'Logout failed');
|
|
212
|
+
throw err;
|
|
213
|
+
} finally {
|
|
214
|
+
setIsLoading(false);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Sign up method
|
|
219
|
+
const signUp = async (username, email, password) => {
|
|
220
|
+
if (!storage) throw new Error('Storage not initialized');
|
|
221
|
+
setIsLoading(true);
|
|
222
|
+
setError(null);
|
|
223
|
+
try {
|
|
224
|
+
const response = await oxyServices.signUp(username, email, password);
|
|
225
|
+
setUser(response.user);
|
|
226
|
+
|
|
227
|
+
// Store tokens
|
|
228
|
+
await storeTokens(response);
|
|
229
|
+
|
|
230
|
+
// Notify about auth state change
|
|
231
|
+
if (onAuthStateChange) {
|
|
232
|
+
onAuthStateChange(response.user);
|
|
233
|
+
}
|
|
234
|
+
return response.user;
|
|
235
|
+
} catch (err) {
|
|
236
|
+
setError(err.message || 'Sign up failed');
|
|
237
|
+
throw err;
|
|
238
|
+
} finally {
|
|
239
|
+
setIsLoading(false);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// Methods to control the bottom sheet
|
|
244
|
+
const showBottomSheet = useCallback(screen => {
|
|
245
|
+
if (bottomSheetRef?.current) {
|
|
246
|
+
// Expand the bottom sheet
|
|
247
|
+
bottomSheetRef.current.expand();
|
|
248
|
+
|
|
249
|
+
// If a screen is specified, navigate to it
|
|
250
|
+
if (screen && bottomSheetRef.current._navigateToScreen) {
|
|
251
|
+
setTimeout(() => {
|
|
252
|
+
bottomSheetRef.current._navigateToScreen(screen);
|
|
253
|
+
}, 100); // Small delay to ensure the sheet is expanded first
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}, [bottomSheetRef]);
|
|
257
|
+
const hideBottomSheet = useCallback(() => {
|
|
258
|
+
if (bottomSheetRef?.current) {
|
|
259
|
+
bottomSheetRef.current.close();
|
|
260
|
+
}
|
|
261
|
+
}, [bottomSheetRef]);
|
|
262
|
+
|
|
263
|
+
// Build context value
|
|
264
|
+
const contextValue = {
|
|
265
|
+
user,
|
|
266
|
+
isAuthenticated: !!user,
|
|
267
|
+
isLoading,
|
|
268
|
+
error,
|
|
269
|
+
login,
|
|
270
|
+
logout,
|
|
271
|
+
signUp,
|
|
272
|
+
oxyServices,
|
|
273
|
+
bottomSheetRef,
|
|
274
|
+
showBottomSheet,
|
|
275
|
+
hideBottomSheet
|
|
276
|
+
};
|
|
277
|
+
return /*#__PURE__*/_jsx(OxyContext.Provider, {
|
|
278
|
+
value: contextValue,
|
|
279
|
+
children: children
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// Hook to use the context
|
|
284
|
+
export const useOxy = () => {
|
|
285
|
+
const context = useContext(OxyContext);
|
|
286
|
+
if (!context) {
|
|
287
|
+
throw new Error('useOxy must be used within an OxyContextProvider');
|
|
288
|
+
}
|
|
289
|
+
return context;
|
|
290
|
+
};
|
|
291
|
+
//# sourceMappingURL=OxyContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","createContext","useContext","useState","useEffect","useCallback","jsx","_jsx","OxyContext","WebStorage","getItem","key","localStorage","setItem","value","removeItem","clear","AsyncStorage","isReactNative","navigator","product","getStorage","asyncStorageModule","default","error","console","Error","getStorageKeys","prefix","accessToken","refreshToken","user","OxyContextProvider","children","oxyServices","storageKeyPrefix","onAuthStateChange","bottomSheetRef","setUser","isLoading","setIsLoading","setError","storage","setStorage","keys","initStorage","platformStorage","initAuth","storedUser","setTokens","isValid","validate","parsedUser","JSON","parse","clearStorage","clearTokens","err","storeTokens","response","token","stringify","login","username","password","message","logout","signUp","email","showBottomSheet","screen","current","expand","_navigateToScreen","setTimeout","hideBottomSheet","close","contextValue","isAuthenticated","Provider","useOxy","context"],"sourceRoot":"../../../../src","sources":["ui/context/OxyContext.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,WAAW,QAAmB,OAAO;;AAIrG;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAsBA;AACA,MAAMC,UAAU,gBAAGP,aAAa,CAAyB,IAAI,CAAC;;AAE9D;;AASA;;AAQA;AACA,MAAMQ,UAAU,CAA6B;EACzC,MAAMC,OAAOA,CAACC,GAAW,EAA0B;IAC/C,OAAOC,YAAY,CAACF,OAAO,CAACC,GAAG,CAAC;EACpC;EAEA,MAAME,OAAOA,CAACF,GAAW,EAAEG,KAAa,EAAiB;IACrDF,YAAY,CAACC,OAAO,CAACF,GAAG,EAAEG,KAAK,CAAC;EACpC;EAEA,MAAMC,UAAUA,CAACJ,GAAW,EAAiB;IACzCC,YAAY,CAACG,UAAU,CAACJ,GAAG,CAAC;EAChC;EAEA,MAAMK,KAAKA,CAAA,EAAkB;IACzBJ,YAAY,CAACI,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DAAkD,CAAC;EACvE;EACA,OAAOuD,OAAO;AAClB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* UI Component exports
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Export the main provider component and context
|
|
8
|
+
export { default as OxyProvider } from './components/OxyProvider';
|
|
9
|
+
export { default as OxySignInButton } from './components/OxySignInButton';
|
|
10
|
+
export { default as OxyLogo } from './components/OxyLogo';
|
|
11
|
+
export { FontLoader, setupFonts } from './components/FontLoader';
|
|
12
|
+
export { OxyContextProvider, useOxy, OxyContextState, OxyContextProviderProps } from './context/OxyContext';
|
|
13
|
+
|
|
14
|
+
// Export styles
|
|
15
|
+
export { fontFamilies, fontStyles } from './styles/fonts';
|
|
16
|
+
|
|
17
|
+
// Export screen components
|
|
18
|
+
export { default as SignInScreen } from './screens/SignInScreen';
|
|
19
|
+
export { default as SignUpScreen } from './screens/SignUpScreen';
|
|
20
|
+
export { default as AccountCenterScreen } from './screens/AccountCenterScreen';
|
|
21
|
+
export { default as AccountOverviewScreen } from './screens/AccountOverviewScreen';
|
|
22
|
+
|
|
23
|
+
// Export types
|
|
24
|
+
export * from './navigation/types';
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["default","OxyProvider","OxySignInButton","OxyLogo","FontLoader","setupFonts","OxyContextProvider","useOxy","OxyContextState","OxyContextProviderProps","fontFamilies","fontStyles","SignInScreen","SignUpScreen","AccountCenterScreen","AccountOverviewScreen"],"sourceRoot":"../../../src","sources":["ui/index.ts"],"mappings":";;AAAA;AACA;AACA;;AAEA;AACA,SAASA,OAAO,IAAIC,WAAW,QAAQ,0BAA0B;AACjE,SAASD,OAAO,IAAIE,eAAe,QAAQ,8BAA8B;AACzE,SAASF,OAAO,IAAIG,OAAO,QAAQ,sBAAsB;AACzD,SAASC,UAAU,EAAEC,UAAU,QAAQ,yBAAyB;AAChE,SACEC,kBAAkB,EAClBC,MAAM,EACNC,eAAe,EACfC,uBAAuB,QAClB,sBAAsB;;AAE7B;AACA,SAASC,YAAY,EAAEC,UAAU,QAAQ,gBAAgB;;AAEzD;AACA,SAASX,OAAO,IAAIY,YAAY,QAAQ,wBAAwB;AAChE,SAASZ,OAAO,IAAIa,YAAY,QAAQ,wBAAwB;AAChE,SAASb,OAAO,IAAIc,mBAAmB,QAAQ,+BAA+B;AAC9E,SAASd,OAAO,IAAIe,qBAAqB,QAAQ,iCAAiC;;AAElF;AACA,cAAc,oBAAoB","ignoreList":[]}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { useState, useEffect } from 'react';
|
|
4
|
+
import { View, StyleSheet } from 'react-native';
|
|
5
|
+
// Import screens
|
|
6
|
+
import SignInScreen from '../screens/SignInScreen';
|
|
7
|
+
import SignUpScreen from '../screens/SignUpScreen';
|
|
8
|
+
import AccountCenterScreen from '../screens/AccountCenterScreen';
|
|
9
|
+
import AccountOverviewScreen from '../screens/AccountOverviewScreen';
|
|
10
|
+
|
|
11
|
+
// Import types
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
// Define route configuration with screen components and default snap points
|
|
14
|
+
const routes = {
|
|
15
|
+
SignIn: {
|
|
16
|
+
component: SignInScreen,
|
|
17
|
+
snapPoints: ['60%', '80%']
|
|
18
|
+
},
|
|
19
|
+
SignUp: {
|
|
20
|
+
component: SignUpScreen,
|
|
21
|
+
snapPoints: ['70%', '90%']
|
|
22
|
+
},
|
|
23
|
+
AccountCenter: {
|
|
24
|
+
component: AccountCenterScreen,
|
|
25
|
+
snapPoints: ['60%', '100%']
|
|
26
|
+
},
|
|
27
|
+
AccountOverview: {
|
|
28
|
+
component: AccountOverviewScreen,
|
|
29
|
+
snapPoints: ['60%', '85%']
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const OxyRouter = ({
|
|
33
|
+
oxyServices,
|
|
34
|
+
initialScreen,
|
|
35
|
+
onClose,
|
|
36
|
+
onAuthenticated,
|
|
37
|
+
theme,
|
|
38
|
+
adjustSnapPoints
|
|
39
|
+
}) => {
|
|
40
|
+
const [currentScreen, setCurrentScreen] = useState(initialScreen);
|
|
41
|
+
const [screenHistory, setScreenHistory] = useState([initialScreen]);
|
|
42
|
+
const [screenProps, setScreenProps] = useState({});
|
|
43
|
+
|
|
44
|
+
// Update snap points when the screen changes
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (routes[currentScreen]) {
|
|
47
|
+
adjustSnapPoints(routes[currentScreen].snapPoints);
|
|
48
|
+
}
|
|
49
|
+
}, [currentScreen, adjustSnapPoints]);
|
|
50
|
+
|
|
51
|
+
// Navigation methods
|
|
52
|
+
const navigate = (screen, props = {}) => {
|
|
53
|
+
if (routes[screen]) {
|
|
54
|
+
setCurrentScreen(screen);
|
|
55
|
+
setScreenHistory(prev => [...prev, screen]);
|
|
56
|
+
setScreenProps(props);
|
|
57
|
+
} else {
|
|
58
|
+
console.error(`Screen "${screen}" not found`);
|
|
59
|
+
}
|
|
60
|
+
}; // Expose the navigate method to the parent component (OxyProvider)
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
// Set up event listener for navigation events
|
|
63
|
+
const handleNavigationEvent = event => {
|
|
64
|
+
if (event && event.detail) {
|
|
65
|
+
const screenName = event.detail;
|
|
66
|
+
console.log(`Navigation event received for screen: ${screenName}`);
|
|
67
|
+
navigate(screenName);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Add event listener (web only)
|
|
72
|
+
if (typeof document !== 'undefined') {
|
|
73
|
+
document.addEventListener('oxy:navigate', handleNavigationEvent);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Cleanup
|
|
77
|
+
return () => {
|
|
78
|
+
if (typeof document !== 'undefined') {
|
|
79
|
+
document.removeEventListener('oxy:navigate', handleNavigationEvent);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}, []);
|
|
83
|
+
const goBack = () => {
|
|
84
|
+
if (screenHistory.length > 1) {
|
|
85
|
+
const newHistory = [...screenHistory];
|
|
86
|
+
newHistory.pop();
|
|
87
|
+
const previousScreen = newHistory[newHistory.length - 1];
|
|
88
|
+
setCurrentScreen(previousScreen);
|
|
89
|
+
setScreenHistory(newHistory);
|
|
90
|
+
} else {
|
|
91
|
+
// If no history, close the UI
|
|
92
|
+
if (onClose) {
|
|
93
|
+
onClose();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Render the current screen component
|
|
99
|
+
const renderScreen = () => {
|
|
100
|
+
const CurrentScreen = routes[currentScreen]?.component;
|
|
101
|
+
if (!CurrentScreen) {
|
|
102
|
+
console.error(`Screen "${currentScreen}" not found`);
|
|
103
|
+
return /*#__PURE__*/_jsx(View, {
|
|
104
|
+
style: styles.errorContainer
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return /*#__PURE__*/_jsx(CurrentScreen, {
|
|
108
|
+
oxyServices: oxyServices,
|
|
109
|
+
navigate: navigate,
|
|
110
|
+
goBack: goBack,
|
|
111
|
+
onClose: onClose,
|
|
112
|
+
onAuthenticated: onAuthenticated,
|
|
113
|
+
theme: theme,
|
|
114
|
+
...screenProps
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
return /*#__PURE__*/_jsx(View, {
|
|
118
|
+
style: styles.container,
|
|
119
|
+
children: renderScreen()
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const styles = StyleSheet.create({
|
|
123
|
+
container: {
|
|
124
|
+
flex: 1
|
|
125
|
+
},
|
|
126
|
+
errorContainer: {
|
|
127
|
+
flex: 1,
|
|
128
|
+
justifyContent: 'center',
|
|
129
|
+
alignItems: 'center'
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
export default OxyRouter;
|
|
133
|
+
//# sourceMappingURL=OxyRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useState","useEffect","View","StyleSheet","SignInScreen","SignUpScreen","AccountCenterScreen","AccountOverviewScreen","jsx","_jsx","routes","SignIn","component","snapPoints","SignUp","AccountCenter","AccountOverview","OxyRouter","oxyServices","initialScreen","onClose","onAuthenticated","theme","adjustSnapPoints","currentScreen","setCurrentScreen","screenHistory","setScreenHistory","screenProps","setScreenProps","navigate","screen","props","prev","console","error","handleNavigationEvent","event","detail","screenName","log","document","addEventListener","removeEventListener","goBack","length","newHistory","pop","previousScreen","renderScreen","CurrentScreen","style","styles","errorContainer","container","children","create","flex","justifyContent","alignItems"],"sourceRoot":"../../../../src","sources":["ui/navigation/OxyRouter.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,SAAS,QAAQ,OAAO;AAClD,SAASC,IAAI,EAAEC,UAAU,QAAQ,cAAc;AAG/C;AACA,OAAOC,YAAY,MAAM,yBAAyB;AAClD,OAAOC,YAAY,MAAM,yBAAyB;AAClD,OAAOC,mBAAmB,MAAM,gCAAgC;AAChE,OAAOC,qBAAqB,MAAM,kCAAkC;;AAEpE;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAGA;AACA,MAAMC,MAAmC,GAAG;EACxCC,MAAM,EAAE;IACJC,SAAS,EAAER,YAAY;IACvBS,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK;EAC7B,CAAC;EACDC,MAAM,EAAE;IACJF,SAAS,EAAEP,YAAY;IACvBQ,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK;EAC7B,CAAC;EACDE,aAAa,EAAE;IACXH,SAAS,EAAEN,mBAAmB;IAC9BO,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM;EAC9B,CAAC;EACDG,eAAe,EAAE;IACbJ,SAAS,EAAEL,qBAAqB;IAChCM,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK;EAC7B;AACJ,CAAC;AAED,MAAMI,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,CAAC;EAED,oBAAOnB,IAAA,CAACP,IAAI;IAACiD,KAAK,EAAEC,MAAM,CAACE,SAAU;IAAAC,QAAA,EAAEN,YAAY,CAAC;EAAC,CAAO,CAAC;AACjE,CAAC;AAED,MAAMG,MAAM,GAAGjD,UAAU,CAACqD,MAAM,CAAC;EAC7BF,SAAS,EAAE;IACPG,IAAI,EAAE;EACV,CAAC;EACDJ,cAAc,EAAE;IACZI,IAAI,EAAE,CAAC;IACPC,cAAc,EAAE,QAAQ;IACxBC,UAAU,EAAE;EAChB;AACJ,CAAC,CAAC;AAEF,eAAe1C,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["ui/navigation/types.ts"],"mappings":"","ignoreList":[]}
|