@onairos/react-native 3.7.1 → 3.7.3
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/lib/commonjs/api/index.js +219 -9
- package/lib/commonjs/assets/icons/spotify.png +0 -0
- package/lib/commonjs/assets/images/spotify.png +0 -0
- package/lib/commonjs/components/BodyText.js +27 -9
- package/lib/commonjs/components/BrandMark.js +111 -10
- package/lib/commonjs/components/CodeInput.js +116 -9
- package/lib/commonjs/components/EmailInput.js +30 -8
- package/lib/commonjs/components/GoogleButton.js +56 -9
- package/lib/commonjs/components/HeadingGroup.js +43 -9
- package/lib/commonjs/components/LLMDataInputModal.js +664 -14
- package/lib/commonjs/components/ModalHeader.js +99 -9
- package/lib/commonjs/components/ModalSheet.js +47 -9
- package/lib/commonjs/components/Onairos.js +380 -14
- package/lib/commonjs/components/OnairosButton.js +313 -13
- package/lib/commonjs/components/OnairosSignInButton.js +130 -12
- package/lib/commonjs/components/Overlay.js +465 -13
- package/lib/commonjs/components/PersonaImage.js +137 -10
- package/lib/commonjs/components/PersonaLoadingScreen.js +318 -12
- package/lib/commonjs/components/PersonalizationConsentScreen.js +467 -13
- package/lib/commonjs/components/PinCreationScreen.js +403 -12
- package/lib/commonjs/components/PinInput.js +464 -9
- package/lib/commonjs/components/PlatformConnectorsStep.js +1311 -23
- package/lib/commonjs/components/PlatformList.js +137 -10
- package/lib/commonjs/components/PlatformToggle.js +180 -9
- package/lib/commonjs/components/PrimaryButton.js +180 -10
- package/lib/commonjs/components/SignInMatchAnimation.js +197 -9
- package/lib/commonjs/components/SignInStep.js +345 -12
- package/lib/commonjs/components/UniversalOnboarding.js +2780 -30
- package/lib/commonjs/components/VerificationStep.js +176 -11
- package/lib/commonjs/components/WelcomeScreen.js +461 -22
- package/lib/commonjs/components/icons/Basicproficon.js +37 -8
- package/lib/commonjs/components/icons/Basicprofile.js +21 -8
- package/lib/commonjs/components/icons/Checkbox.js +21 -8
- package/lib/commonjs/components/icons/Checkmark.js +27 -8
- package/lib/commonjs/components/icons/Contentanalysis.js +21 -8
- package/lib/commonjs/components/icons/Contenticon.js +39 -8
- package/lib/commonjs/components/icons/EnochE.js +41 -8
- package/lib/commonjs/components/icons/Personalityicon.js +30 -8
- package/lib/commonjs/components/icons/Personalityprofile.js +21 -8
- package/lib/commonjs/components/icons/Personalitytraits.js +21 -8
- package/lib/commonjs/components/icons/Userpreferences.js +21 -8
- package/lib/commonjs/components/icons/index.js +84 -17
- package/lib/commonjs/components/onboarding/OAuthWebView.js +1754 -18
- package/lib/commonjs/components/onboarding/OnboardingHeader.js +74 -10
- package/lib/commonjs/components/onboarding/PinInput.js +283 -10
- package/lib/commonjs/components/onboarding/PlatformConnector.js +249 -11
- package/lib/commonjs/config/PLATFORM_APIS.md +849 -0
- package/lib/commonjs/config/api.js +56 -7
- package/lib/commonjs/constants/index.js +120 -7
- package/lib/commonjs/context/AuthContext.js +345 -10
- package/lib/commonjs/hooks/useConnectedAccounts.js +111 -9
- package/lib/commonjs/hooks/useConnections.js +102 -8
- package/lib/commonjs/hooks/useCredentials.js +178 -10
- package/lib/commonjs/hooks/useUserConnections.js +148 -10
- package/lib/commonjs/index.js +439 -34
- package/lib/commonjs/services/apiClient.js +298 -8
- package/lib/commonjs/services/biometricPinService.js +180 -8
- package/lib/commonjs/services/chatGPTConversationExtractor.js +155 -8
- package/lib/commonjs/services/chatGPTConversationService.js +275 -9
- package/lib/commonjs/services/claudeConversationExtractor.js +103 -8
- package/lib/commonjs/services/claudeConversationService.js +158 -9
- package/lib/commonjs/services/connectedAccountsService.js +310 -10
- package/lib/commonjs/services/googleAuthService.js +252 -11
- package/lib/commonjs/services/hingeDataExtractor.js +105 -8
- package/lib/commonjs/services/hingeDataService.js +150 -9
- package/lib/commonjs/services/imageCompressionService.js +260 -7
- package/lib/commonjs/services/instagramDataExtractor.js +126 -8
- package/lib/commonjs/services/instagramDataService.js +163 -9
- package/lib/commonjs/services/jwtStorageService.js +276 -7
- package/lib/commonjs/services/linkedinDOMExtractor.js +245 -7
- package/lib/commonjs/services/linkedinProfileService.js +222 -9
- package/lib/commonjs/services/linkedinScrapingService.js +230 -8
- package/lib/commonjs/services/llmDataStorage.js +294 -8
- package/lib/commonjs/services/mobileTrainingService.js +186 -8
- package/lib/commonjs/services/netflixDataExtractor.js +120 -8
- package/lib/commonjs/services/netflixDataService.js +198 -9
- package/lib/commonjs/services/pinEncryptionService.js +84 -8
- package/lib/commonjs/services/pinStorageUtils.js +105 -7
- package/lib/commonjs/services/platformAuthService.js +1484 -12
- package/lib/commonjs/services/sephoraDataExtractor.js +140 -8
- package/lib/commonjs/services/sephoraDataService.js +200 -9
- package/lib/commonjs/services/spotifyDataExtractor.js +148 -8
- package/lib/commonjs/services/spotifyDataService.js +241 -9
- package/lib/commonjs/services/storageService.js +404 -8
- package/lib/commonjs/services/telegramDataExtractor.js +115 -8
- package/lib/commonjs/services/telegramDataService.js +499 -9
- package/lib/commonjs/services/trainingApiHelpers.js +73 -7
- package/lib/commonjs/services/userConnectionsService.js +340 -10
- package/lib/commonjs/services/youtubeMigrationService.js +416 -10
- package/lib/commonjs/theme/index.js +250 -7
- package/lib/commonjs/types/ambient.d.js +2 -1
- package/lib/commonjs/types/declarations.d.js +2 -1
- package/lib/commonjs/types/index.js +6 -1
- package/lib/commonjs/types/node-fix.d.js +2 -1
- package/lib/commonjs/types/node-override.d.js +2 -1
- package/lib/commonjs/types/opacity.d.js +2 -1
- package/lib/commonjs/types.js +14 -1
- package/lib/commonjs/utils/Portal.js +98 -8
- package/lib/commonjs/utils/api.js +130 -9
- package/lib/commonjs/utils/assetRegistry.js +210 -35
- package/lib/commonjs/utils/auth.js +112 -9
- package/lib/commonjs/utils/connectorTests.js +613 -29
- package/lib/commonjs/utils/crypto.js +62 -8
- package/lib/commonjs/utils/debugHelper.js +64 -1
- package/lib/commonjs/utils/encryption.js +76 -7
- package/lib/commonjs/utils/eventUtils.js +288 -1
- package/lib/commonjs/utils/haptics.js +66 -9
- package/lib/commonjs/utils/imagePreloader.js +6 -1
- package/lib/commonjs/utils/networkDiagnostics.js +226 -8
- package/lib/commonjs/utils/onairosApi.js +350 -9
- package/lib/commonjs/utils/programmaticFlow.js +117 -9
- package/lib/commonjs/utils/retryHelper.js +220 -1
- package/lib/commonjs/utils/secureStorage.js +349 -10
- package/lib/commonjs/utils/webviewScripts/chatgpt.js +551 -1
- package/lib/commonjs/utils/webviewScripts/claude.js +376 -1
- package/lib/commonjs/utils/webviewScripts/hinge.js +411 -1
- package/lib/commonjs/utils/webviewScripts/index.js +698 -15
- package/lib/commonjs/utils/webviewScripts/instagram.js +454 -1
- package/lib/commonjs/utils/webviewScripts/linkedin.js +880 -1
- package/lib/commonjs/utils/webviewScripts/netflix.js +382 -1
- package/lib/commonjs/utils/webviewScripts/sephora.js +516 -1
- package/lib/commonjs/utils/webviewScripts/spotify.js +419 -1
- package/lib/commonjs/utils/webviewScripts/telegram.js +678 -1
- package/lib/module/api/index.js +211 -1
- package/lib/module/assets/icons/spotify.png +0 -0
- package/lib/module/assets/images/spotify.png +0 -0
- package/lib/module/components/BodyText.js +20 -1
- package/lib/module/components/BrandMark.js +104 -1
- package/lib/module/components/CodeInput.js +109 -1
- package/lib/module/components/EmailInput.js +23 -1
- package/lib/module/components/GoogleButton.js +49 -1
- package/lib/module/components/HeadingGroup.js +36 -1
- package/lib/module/components/LLMDataInputModal.js +656 -7
- package/lib/module/components/ModalHeader.js +92 -1
- package/lib/module/components/ModalSheet.js +39 -1
- package/lib/module/components/Onairos.js +373 -1
- package/lib/module/components/OnairosButton.js +305 -1
- package/lib/module/components/OnairosSignInButton.js +121 -1
- package/lib/module/components/Overlay.js +456 -1
- package/lib/module/components/PersonaImage.js +129 -1
- package/lib/module/components/PersonaLoadingScreen.js +310 -1
- package/lib/module/components/PersonalizationConsentScreen.js +460 -1
- package/lib/module/components/PinCreationScreen.js +396 -1
- package/lib/module/components/PinInput.js +456 -1
- package/lib/module/components/PlatformConnectorsStep.js +1302 -6
- package/lib/module/components/PlatformList.js +129 -1
- package/lib/module/components/PlatformToggle.js +173 -1
- package/lib/module/components/PrimaryButton.js +172 -1
- package/lib/module/components/SignInMatchAnimation.js +189 -1
- package/lib/module/components/SignInStep.js +338 -1
- package/lib/module/components/UniversalOnboarding.js +2770 -1
- package/lib/module/components/VerificationStep.js +168 -1
- package/lib/module/components/WelcomeScreen.js +453 -1
- package/lib/module/components/icons/Basicproficon.js +30 -1
- package/lib/module/components/icons/Basicprofile.js +14 -1
- package/lib/module/components/icons/Checkbox.js +14 -1
- package/lib/module/components/icons/Checkmark.js +20 -1
- package/lib/module/components/icons/Contentanalysis.js +14 -1
- package/lib/module/components/icons/Contenticon.js +32 -1
- package/lib/module/components/icons/EnochE.js +34 -1
- package/lib/module/components/icons/Personalityicon.js +23 -1
- package/lib/module/components/icons/Personalityprofile.js +14 -1
- package/lib/module/components/icons/Personalitytraits.js +14 -1
- package/lib/module/components/icons/Userpreferences.js +14 -1
- package/lib/module/components/icons/index.js +13 -1
- package/lib/module/components/onboarding/OAuthWebView.js +1746 -1
- package/lib/module/components/onboarding/OnboardingHeader.js +66 -1
- package/lib/module/components/onboarding/PinInput.js +274 -1
- package/lib/module/components/onboarding/PlatformConnector.js +240 -1
- package/lib/module/config/PLATFORM_APIS.md +849 -0
- package/lib/module/config/api.js +47 -1
- package/lib/module/constants/index.js +114 -1
- package/lib/module/context/AuthContext.js +335 -1
- package/lib/module/hooks/useConnectedAccounts.js +106 -1
- package/lib/module/hooks/useConnections.js +95 -1
- package/lib/module/hooks/useCredentials.js +171 -6
- package/lib/module/hooks/useUserConnections.js +140 -1
- package/lib/module/index.js +172 -1
- package/lib/module/services/apiClient.js +295 -1
- package/lib/module/services/biometricPinService.js +169 -1
- package/lib/module/services/chatGPTConversationExtractor.js +149 -1
- package/lib/module/services/chatGPTConversationService.js +268 -1
- package/lib/module/services/claudeConversationExtractor.js +97 -1
- package/lib/module/services/claudeConversationService.js +151 -1
- package/lib/module/services/connectedAccountsService.js +293 -1
- package/lib/module/services/googleAuthService.js +241 -1
- package/lib/module/services/hingeDataExtractor.js +99 -1
- package/lib/module/services/hingeDataService.js +143 -1
- package/lib/module/services/imageCompressionService.js +250 -1
- package/lib/module/services/instagramDataExtractor.js +120 -1
- package/lib/module/services/instagramDataService.js +156 -1
- package/lib/module/services/jwtStorageService.js +257 -1
- package/lib/module/services/linkedinDOMExtractor.js +234 -1
- package/lib/module/services/linkedinProfileService.js +210 -1
- package/lib/module/services/linkedinScrapingService.js +219 -1
- package/lib/module/services/llmDataStorage.js +277 -1
- package/lib/module/services/mobileTrainingService.js +173 -1
- package/lib/module/services/netflixDataExtractor.js +114 -1
- package/lib/module/services/netflixDataService.js +191 -1
- package/lib/module/services/pinEncryptionService.js +74 -6
- package/lib/module/services/pinStorageUtils.js +93 -1
- package/lib/module/services/platformAuthService.js +1461 -1
- package/lib/module/services/sephoraDataExtractor.js +134 -1
- package/lib/module/services/sephoraDataService.js +193 -1
- package/lib/module/services/spotifyDataExtractor.js +142 -1
- package/lib/module/services/spotifyDataService.js +234 -1
- package/lib/module/services/storageService.js +383 -1
- package/lib/module/services/telegramDataExtractor.js +109 -1
- package/lib/module/services/telegramDataService.js +493 -1
- package/lib/module/services/trainingApiHelpers.js +67 -1
- package/lib/module/services/userConnectionsService.js +329 -1
- package/lib/module/services/youtubeMigrationService.js +405 -1
- package/lib/module/theme/index.js +245 -1
- package/lib/module/types.js +10 -1
- package/lib/module/utils/Portal.js +90 -1
- package/lib/module/utils/api.js +118 -1
- package/lib/module/utils/assetRegistry.js +200 -34
- package/lib/module/utils/auth.js +100 -1
- package/lib/module/utils/connectorTests.js +600 -27
- package/lib/module/utils/crypto.js +54 -1
- package/lib/module/utils/debugHelper.js +54 -1
- package/lib/module/utils/encryption.js +67 -1
- package/lib/module/utils/eventUtils.js +270 -1
- package/lib/module/utils/haptics.js +59 -8
- package/lib/module/utils/imagePreloader.js +3 -1
- package/lib/module/utils/networkDiagnostics.js +217 -1
- package/lib/module/utils/onairosApi.js +333 -1
- package/lib/module/utils/programmaticFlow.js +111 -1
- package/lib/module/utils/retryHelper.js +211 -1
- package/lib/module/utils/secureStorage.js +330 -6
- package/lib/module/utils/webviewScripts/chatgpt.js +545 -1
- package/lib/module/utils/webviewScripts/claude.js +370 -1
- package/lib/module/utils/webviewScripts/hinge.js +405 -1
- package/lib/module/utils/webviewScripts/index.js +434 -1
- package/lib/module/utils/webviewScripts/instagram.js +448 -1
- package/lib/module/utils/webviewScripts/linkedin.js +874 -1
- package/lib/module/utils/webviewScripts/netflix.js +376 -1
- package/lib/module/utils/webviewScripts/sephora.js +510 -1
- package/lib/module/utils/webviewScripts/spotify.js +413 -1
- package/lib/module/utils/webviewScripts/telegram.js +672 -1
- package/package.json +2 -2
|
@@ -1,9 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useConnectedAccounts = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _connectedAccountsService = require("../services/connectedAccountsService");
|
|
9
|
+
var _AuthContext = require("../context/AuthContext");
|
|
10
|
+
const useConnectedAccounts = () => {
|
|
11
|
+
const {
|
|
12
|
+
user
|
|
13
|
+
} = (0, _AuthContext.useAuth)();
|
|
14
|
+
const [connectedAccounts, setConnectedAccounts] = (0, _react.useState)([]);
|
|
15
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(true);
|
|
16
|
+
const [error, setError] = (0, _react.useState)(null);
|
|
17
|
+
const fetchConnectedAccounts = (0, _react.useCallback)(async () => {
|
|
18
|
+
if (!user) {
|
|
19
|
+
console.log('🔍 No user available for fetching connected accounts');
|
|
20
|
+
setIsLoading(false);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
setIsLoading(true);
|
|
25
|
+
setError(null);
|
|
26
|
+
console.log('🚀 [HOOK] Starting connected accounts fetch with new smart API...');
|
|
27
|
+
console.log('🚀 [HOOK] User info available:', {
|
|
28
|
+
email: user.email,
|
|
29
|
+
id: user.id,
|
|
30
|
+
name: user.name
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Use the new smart API function - makes only ONE request with intelligent fallbacks
|
|
34
|
+
const accounts = await (0, _connectedAccountsService.getConnectedAccountsSmart)(user.email,
|
|
35
|
+
// Primary identifier (email)
|
|
36
|
+
user.id,
|
|
37
|
+
// Secondary identifier (user ID)
|
|
38
|
+
user.name // Tertiary identifier (username)
|
|
39
|
+
);
|
|
40
|
+
console.log(`✅ [HOOK] Connected accounts loaded via smart API: ${accounts.length} accounts`);
|
|
41
|
+
setConnectedAccounts(accounts);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.error('❌ [HOOK] Error fetching connected accounts:', err);
|
|
44
|
+
setError('Failed to load connected accounts');
|
|
45
|
+
} finally {
|
|
46
|
+
setIsLoading(false);
|
|
47
|
+
}
|
|
48
|
+
}, [user]);
|
|
49
|
+
const refreshAccounts = (0, _react.useCallback)(async () => {
|
|
50
|
+
console.log('🔄 [HOOK] Refreshing connected accounts...');
|
|
51
|
+
await fetchConnectedAccounts();
|
|
52
|
+
}, [fetchConnectedAccounts]);
|
|
53
|
+
const addAccount = (0, _react.useCallback)((platform, username) => {
|
|
54
|
+
// Create a temporary URL for the account
|
|
55
|
+
const tempUrl = `https://${platform.toLowerCase()}.com/${username}`;
|
|
56
|
+
const newAccount = {
|
|
57
|
+
platform,
|
|
58
|
+
username,
|
|
59
|
+
url: tempUrl
|
|
60
|
+
};
|
|
61
|
+
setConnectedAccounts(prev => {
|
|
62
|
+
// Check if account already exists
|
|
63
|
+
const exists = prev.some(acc => acc.platform.toLowerCase() === platform.toLowerCase());
|
|
64
|
+
if (exists) {
|
|
65
|
+
// Update existing account
|
|
66
|
+
return prev.map(acc => acc.platform.toLowerCase() === platform.toLowerCase() ? newAccount : acc);
|
|
67
|
+
} else {
|
|
68
|
+
// Add new account
|
|
69
|
+
return [...prev, newAccount];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
console.log('✅ [HOOK] Account added locally:', newAccount);
|
|
73
|
+
|
|
74
|
+
// TODO: In a real implementation, you would also send this to your backend
|
|
75
|
+
// Example:
|
|
76
|
+
// try {
|
|
77
|
+
// await saveConnectedAccount(user.id, platform, username);
|
|
78
|
+
// } catch (error) {
|
|
79
|
+
// console.error('Failed to save account to backend:', error);
|
|
80
|
+
// // Optionally revert the local change
|
|
81
|
+
// }
|
|
82
|
+
}, []);
|
|
83
|
+
const removeAccount = (0, _react.useCallback)(platform => {
|
|
84
|
+
setConnectedAccounts(prev => prev.filter(acc => acc.platform.toLowerCase() !== platform.toLowerCase()));
|
|
85
|
+
console.log('✅ [HOOK] Account removed locally:', platform);
|
|
86
|
+
|
|
87
|
+
// TODO: In a real implementation, you would also remove this from your backend
|
|
88
|
+
// Example:
|
|
89
|
+
// try {
|
|
90
|
+
// await removeConnectedAccount(user.id, platform);
|
|
91
|
+
// } catch (error) {
|
|
92
|
+
// console.error('Failed to remove account from backend:', error);
|
|
93
|
+
// // Optionally revert the local change
|
|
94
|
+
// }
|
|
95
|
+
}, []);
|
|
96
|
+
|
|
97
|
+
// Fetch accounts when component mounts or user changes
|
|
98
|
+
(0, _react.useEffect)(() => {
|
|
99
|
+
fetchConnectedAccounts();
|
|
100
|
+
}, [fetchConnectedAccounts]);
|
|
101
|
+
return {
|
|
102
|
+
connectedAccounts,
|
|
103
|
+
isLoading,
|
|
104
|
+
error,
|
|
105
|
+
refreshAccounts,
|
|
106
|
+
addAccount,
|
|
107
|
+
removeAccount
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
exports.useConnectedAccounts = useConnectedAccounts;
|
|
111
|
+
//# sourceMappingURL=useConnectedAccounts.js.map
|
|
@@ -1,8 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useConnections = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _platformAuthService = require("../services/platformAuthService");
|
|
9
|
+
/**
|
|
10
|
+
* Hook for managing platform connections
|
|
11
|
+
* NOTE: This hook now only manages LOCAL state
|
|
12
|
+
* Consuming apps are responsible for syncing connection status to their backend
|
|
13
|
+
* (e.g., calling /enoch/users/update for Enoch apps)
|
|
14
|
+
*/
|
|
15
|
+
const useConnections = () => {
|
|
16
|
+
const [connections, setConnections] = (0, _react.useState)({});
|
|
17
|
+
const [isConnecting, setIsConnecting] = (0, _react.useState)(false);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Connect a platform using OAuth or native SDK
|
|
21
|
+
* NOTE: Only manages local state - backend sync removed from SDK
|
|
22
|
+
*/
|
|
23
|
+
const connectPlatform = (0, _react.useCallback)(async (platform, username) => {
|
|
24
|
+
try {
|
|
25
|
+
setIsConnecting(true);
|
|
26
|
+
|
|
27
|
+
// Determine if we should use native SDK or OAuth
|
|
28
|
+
const useNativeSDK = platform === 'youtube' || platform === 'instagram';
|
|
29
|
+
let success = false;
|
|
30
|
+
if (useNativeSDK) {
|
|
31
|
+
// Use native SDK
|
|
32
|
+
success = await (0, _platformAuthService.initiateNativeAuth)(platform, username);
|
|
33
|
+
} else {
|
|
34
|
+
// For demo purposes, we'll simulate a successful connection
|
|
35
|
+
await new Promise(resolve => setTimeout(() => resolve(undefined), 1000));
|
|
36
|
+
success = true;
|
|
37
|
+
}
|
|
38
|
+
if (success) {
|
|
39
|
+
// Update connections state locally only
|
|
40
|
+
// NOTE: Backend sync removed - consuming app should handle this
|
|
41
|
+
setConnections(prev => ({
|
|
42
|
+
...prev,
|
|
43
|
+
[platform]: {
|
|
44
|
+
userName: username,
|
|
45
|
+
connected: true
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
console.log(`✅ Platform ${platform} connected locally`);
|
|
49
|
+
console.log('ℹ️ NOTE: Backend sync removed from SDK - app should call /enoch/users/update if needed');
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(`Error connecting platform ${platform}:`, error);
|
|
55
|
+
return false;
|
|
56
|
+
} finally {
|
|
57
|
+
setIsConnecting(false);
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Disconnect a platform
|
|
63
|
+
* NOTE: Only manages local state - backend sync removed from SDK
|
|
64
|
+
*/
|
|
65
|
+
const disconnectPlatform = (0, _react.useCallback)(async (platform, _username) => {
|
|
66
|
+
try {
|
|
67
|
+
// Update local state only
|
|
68
|
+
// NOTE: Backend sync removed - consuming app should handle this
|
|
69
|
+
setConnections(prev => {
|
|
70
|
+
const newConnections = {
|
|
71
|
+
...prev
|
|
72
|
+
};
|
|
73
|
+
delete newConnections[platform];
|
|
74
|
+
return newConnections;
|
|
75
|
+
});
|
|
76
|
+
console.log(`✅ Platform ${platform} disconnected locally`);
|
|
77
|
+
console.log('ℹ️ NOTE: Backend sync removed from SDK - app should call /enoch/users/update if needed');
|
|
78
|
+
return true;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error(`Error disconnecting platform ${platform}:`, error);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get current connection status
|
|
87
|
+
*/
|
|
88
|
+
const getConnectionStatus = (0, _react.useCallback)(async () => {
|
|
89
|
+
// Returns local connection state
|
|
90
|
+
// Consuming app can fetch from backend if needed
|
|
91
|
+
return connections;
|
|
92
|
+
}, [connections]);
|
|
93
|
+
return {
|
|
94
|
+
connections,
|
|
95
|
+
connectPlatform,
|
|
96
|
+
disconnectPlatform,
|
|
97
|
+
getConnectionStatus,
|
|
98
|
+
isConnecting
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
exports.useConnections = useConnections;
|
|
102
|
+
//# sourceMappingURL=useConnections.js.map
|
|
@@ -1,10 +1,178 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object[_0x1cd1(0x0)](exports,_0x1cd1(0x1),{'value':!![]}),exports[_0x1cd1(0x2)]=void 0x0;var _react=__ONAIROS_REQ_FUNC__(0x0),_constants=__ONAIROS_REQ_FUNC__(0x1),_api=__ONAIROS_REQ_FUNC__(0x2);const mockCredentialStorage={};function _0x1cd1(_0x49c18c,_0x1cd1a1){_0x49c18c=_0x49c18c-0x0;const _0x5c96d8=_0x49c1();let _0x27fa15=_0x5c96d8[_0x49c18c];return _0x27fa15;}let Keychain=null;function _0x49c1(){const _0x2a2a1d=['defineProperty','__esModule','useCredentials','warn','function','YHKkB','getGenericPassword','zhSti','Keychain\x20access\x20failed,\x20using\x20mock\x20storage','AngSl','wsJFH','itIBw','CZLhL','service','nuyVi','ThkSH','SKdge','TWEcu','default','EZYvA','error','Error\x20clearing\x20credentials:','oheAK','SvesL','csqCD','OcqYX','gJBij','HUjFf','iwMuf','NfLss','XVtYr','HhaLA','BHJHh','vQAux','nEgbu','kGwYD','jyIDe','VDhbp','oSyCY','Error\x20validating\x20credentials:','LKaYR','qPUJC','LDNHc','Error\x20checking\x20credentials:','dWJyQ','HNFXR','Error\x20getting\x20credentials:','XvHJE','hVrtx','useCallback','DOrQc','STORAGE_KEYS','credentials','vjpZM','WQAKe','DYsId','wbwbk','fQsiC','iuCtb','plgUp','parse','sMqOX','ysZvy','EHKUi','bfPHa','BIOMETRY_ANY','WHEN_UNLOCKED','eMMkL','accessible','MmQqr','ACCESSIBLE','wTXcg','ZYVgh','GqxHa','Error\x20storing\x20credentials:','xQzfe','ymezI','mzxlk','API_CONFIG','BASE_URL','/validate','stringify','valid'];_0x49c1=function(){return _0x2a2a1d;};return _0x49c1();}try{Keychain=__ONAIROS_REQ_FUNC__(0x3);}catch(_0x5ed127){console[_0x1cd1(0x3)]('react-native-keychain module not available in useCredentials, using mock storage');}const isKeychainAvailable=()=>{const _0x1ab379={'YHKkB':function(_0x2589e5,_0x17da7c){return _0x2589e5===_0x17da7c;},'zhSti':_0x1cd1(0x4)};try{return Keychain&&_0x1ab379[_0x1cd1(0x5)](typeof Keychain[_0x1cd1(0x6)],_0x1ab379[_0x1cd1(0x7)]);}catch(_0x104543){return![];}},safeGetGenericPassword=async _0x44f59f=>{const _0x394765={'ThkSH':_0x1cd1(0x8),'itIBw':function(_0x178e6f,_0x2ee306){return _0x178e6f===_0x2ee306;},'SKdge':function(_0x1dbca2,_0x3b3f56){return _0x1dbca2===_0x3b3f56;},'nuyVi':'default','wsJFH':function(_0x4fa145){return _0x4fa145();},'CZLhL':_0x1cd1(0x9)};try{if(_0x394765[_0x1cd1(0xa)](isKeychainAvailable))return await Keychain['getGenericPassword'](_0x44f59f);else{if(_0x394765[_0x1cd1(0xb)](_0x394765[_0x1cd1(0xc)],_0x394765[_0x1cd1(0xc)])){const _0x59aabc=(_0x394765['SKdge'](_0x44f59f,null)||_0x44f59f===void 0x0?void 0x0:_0x44f59f[_0x1cd1(0xd)])||_0x394765[_0x1cd1(0xe)];return mockCredentialStorage[_0x59aabc]||null;}else{_0x3b0771[_0x1cd1(0x3)](_0x394765[_0x1cd1(0xf)],_0x955ac0);const _0x31ec74=(_0x394765[_0x1cd1(0xb)](_0x559d9d,null)||_0x394765[_0x1cd1(0x10)](_0x1c0812,void 0x0)?void 0x0:_0x211aef[_0x1cd1(0xd)])||_0x394765[_0x1cd1(0xe)];return delete _0x14485f[_0x31ec74],!![];}}}catch(_0x8d8cbc){console['warn']('Keychain\x20access\x20failed,\x20using\x20mock\x20storage',_0x8d8cbc);const _0x51c186=(_0x394765[_0x1cd1(0xb)](_0x44f59f,null)||_0x394765[_0x1cd1(0xb)](_0x44f59f,void 0x0)?void 0x0:_0x44f59f[_0x1cd1(0xd)])||_0x394765['nuyVi'];return mockCredentialStorage[_0x51c186]||null;}},safeSetGenericPassword=async(_0x58cdd1,_0x53b4b0,_0x581292)=>{const _0x24a9b5={'yFlzw':function(_0x18f45c){return _0x18f45c();},'bpxzp':function(_0x42d08b,_0x27a6d4){return _0x42d08b!==_0x27a6d4;},'EZYvA':_0x1cd1(0x11),'oheAK':function(_0x4f7f89,_0x4e0965){return _0x4f7f89===_0x4e0965;},'SvesL':_0x1cd1(0x12),'csqCD':function(_0x8974aa,_0xf4dfb1){return _0x8974aa===_0xf4dfb1;}};try{if(_0x24a9b5['yFlzw'](isKeychainAvailable)){if(_0x24a9b5['bpxzp'](_0x24a9b5[_0x1cd1(0x13)],_0x24a9b5[_0x1cd1(0x13)]))_0x29938f[_0x1cd1(0x14)](_0x1cd1(0x15),_0x35d3fe);else return await Keychain['setGenericPassword'](_0x58cdd1,_0x53b4b0,_0x581292);}else{const _0x2c8e99=(_0x581292===null||_0x24a9b5[_0x1cd1(0x16)](_0x581292,void 0x0)?void 0x0:_0x581292[_0x1cd1(0xd)])||_0x24a9b5[_0x1cd1(0x17)];return mockCredentialStorage[_0x2c8e99]={'username':_0x58cdd1,'password':_0x53b4b0},!![];}}catch(_0x2e1b9f){if(_0x24a9b5[_0x1cd1(0x18)]('OcqYX',_0x1cd1(0x19))){console['warn'](_0x1cd1(0x8),_0x2e1b9f);const _0x29f251=(_0x581292===null||_0x581292===void 0x0?void 0x0:_0x581292[_0x1cd1(0xd)])||_0x1cd1(0x12);return mockCredentialStorage[_0x29f251]={'username':_0x58cdd1,'password':_0x53b4b0},!![];}else return Keychain&&typeof Keychain['getGenericPassword']===_0x1cd1(0x4);}},safeResetGenericPassword=async _0x1be11f=>{const _0x1a822b={'nEgbu':_0x1cd1(0x4),'jyIDe':_0x1cd1(0x8),'ASmof':function(_0x47b0c8,_0x149fcb){return _0x47b0c8===_0x149fcb;},'VDhbp':function(_0xd57843,_0x528ea8){return _0xd57843===_0x528ea8;},'NfLss':function(_0x5c6b48,_0x56bc78){return _0x5c6b48!==_0x56bc78;},'XVtYr':_0x1cd1(0x1a),'pHDYB':_0x1cd1(0x1b),'HhaLA':function(_0x1a8432){return _0x1a8432();},'BHJHh':'QxjKM','kGwYD':_0x1cd1(0x1c),'rvcFW':function(_0x43467a,_0x234fe2){return _0x43467a===_0x234fe2;},'xKCmW':function(_0x51e1ad,_0xb8238f){return _0x51e1ad===_0xb8238f;},'oSyCY':_0x1cd1(0x12),'LKaYR':function(_0x4529d4,_0x4893d8){return _0x4529d4===_0x4893d8;},'qPUJC':function(_0x20b27c,_0x2be04a){return _0x20b27c===_0x2be04a;}};try{if(_0x1a822b[_0x1cd1(0x1d)](_0x1a822b[_0x1cd1(0x1e)],_0x1a822b['pHDYB'])){if(_0x1a822b[_0x1cd1(0x1f)](isKeychainAvailable)){if(_0x1a822b[_0x1cd1(0x20)]===_0x1cd1(0x21))try{return Keychain&&typeof Keychain[_0x1cd1(0x6)]===_0x1a822b[_0x1cd1(0x22)];}catch(_0x1cf7e4){return![];}else return await Keychain['resetGenericPassword'](_0x1be11f);}else{if(_0x1a822b[_0x1cd1(0x1d)](_0x1a822b[_0x1cd1(0x23)],_0x1a822b[_0x1cd1(0x23)])){_0x501bd1[_0x1cd1(0x3)](_0x1a822b[_0x1cd1(0x24)],_0x275c0b);const _0x48fd49=(_0x1a822b['ASmof'](_0x24f7f5,null)||_0x1a822b[_0x1cd1(0x25)](_0x3a82ed,void 0x0)?void 0x0:_0x364ad1['service'])||_0x1cd1(0x12);return _0x2c9e2b[_0x48fd49]={'username':_0x19a222,'password':_0x47eb90},!![];}else{const _0x1b0241=(_0x1a822b['rvcFW'](_0x1be11f,null)||_0x1a822b['xKCmW'](_0x1be11f,void 0x0)?void 0x0:_0x1be11f['service'])||_0x1a822b[_0x1cd1(0x26)];return delete mockCredentialStorage[_0x1b0241],!![];}}}else return _0x421030[_0x1cd1(0x14)](_0x1cd1(0x27),_0x117e51),{'success':![],'isValid':![]};}catch(_0xbc143e){console['warn'](_0x1a822b[_0x1cd1(0x24)],_0xbc143e);const _0x5bfde9=(_0x1a822b[_0x1cd1(0x28)](_0x1be11f,null)||_0x1a822b[_0x1cd1(0x29)](_0x1be11f,void 0x0)?void 0x0:_0x1be11f[_0x1cd1(0xd)])||_0x1a822b[_0x1cd1(0x26)];return delete mockCredentialStorage[_0x5bfde9],!![];}},useCredentials=()=>{const _0x326975={'WQAKe':function(_0x35547d,_0x49d645){return _0x35547d===_0x49d645;},'DYsId':function(_0x4a382a,_0x533c87){return _0x4a382a===_0x533c87;},'DOrQc':function(_0x585be3,_0x52ba67){return _0x585be3(_0x52ba67);},'ZYVgh':function(_0x41b02d,_0x471088){return _0x41b02d!==_0x471088;},'oYfCt':_0x1cd1(0x2a),'BlbYc':_0x1cd1(0x2b),'sMqOX':_0x1cd1(0x12),'wbwbk':function(_0x1f7ea8,_0x2faf02){return _0x1f7ea8!==_0x2faf02;},'fQsiC':_0x1cd1(0x2c),'plgUp':function(_0x153b11,_0x433443){return _0x153b11(_0x433443);},'ysZvy':function(_0xde1827,_0x1c1883){return _0xde1827!==_0x1c1883;},'kLExz':_0x1cd1(0x2d),'bfPHa':_0x1cd1(0x2e),'eMMkL':function(_0x249b31,_0xa08dfc){return _0x249b31===_0xa08dfc;},'MmQqr':function(_0xd3a4f3,_0x37578a){return _0xd3a4f3===_0x37578a;},'wTXcg':function(_0x2fb75e,_0x4c2666,_0x4792d4,_0x27b61c){return _0x2fb75e(_0x4c2666,_0x4792d4,_0x27b61c);},'GqxHa':'vLquS','XwKHn':_0x1cd1(0x15),'qcXOw':function(_0x2f57e1,_0x128512){return _0x2f57e1===_0x128512;},'mzxlk':function(_0x2b0922,_0x1d68db){return _0x2b0922===_0x1d68db;},'xQzfe':_0x1cd1(0x2f),'ymezI':_0x1cd1(0x30),'qgiRV':function(_0x51505d,_0x456bdd,_0x125701){return _0x51505d(_0x456bdd,_0x125701);}},_0x525915=(0x0,_react[_0x1cd1(0x31)])(async()=>{try{const _0xd1f190=await _0x326975[_0x1cd1(0x32)](safeGetGenericPassword,{'service':_constants[_0x1cd1(0x33)][_0x1cd1(0x34)]});return!!_0xd1f190;}catch(_0x8cb085){if(_0x326975['ZYVgh'](_0x1cd1(0x35),_0x326975['oYfCt']))return console['error'](_0x326975['BlbYc'],_0x8cb085),![];else{const _0x291c3c=(_0x326975[_0x1cd1(0x36)](_0x4f069b,null)||_0x326975[_0x1cd1(0x37)](_0x1274bd,void 0x0)?void 0x0:_0x4a735f['service'])||_0x1cd1(0x12);return delete _0x3937ba[_0x291c3c],!![];}}},[]),_0x3eeff8=(0x0,_react['useCallback'])(async()=>{try{if(_0x326975[_0x1cd1(0x38)](_0x326975[_0x1cd1(0x39)],_0x1cd1(0x3a))){const _0x5664d3=await _0x326975[_0x1cd1(0x3b)](safeGetGenericPassword,{'service':_constants[_0x1cd1(0x33)]['credentials']});if(_0x5664d3)return JSON[_0x1cd1(0x3c)](_0x5664d3['password']);return null;}else{_0x622702[_0x1cd1(0x3)]('Keychain\x20access\x20failed,\x20using\x20mock\x20storage',_0x16b758);const _0xd9ad3b=(_0x2674f6===null||_0x326975[_0x1cd1(0x36)](_0x4b9c95,void 0x0)?void 0x0:_0xe0c06d[_0x1cd1(0xd)])||_0x326975[_0x1cd1(0x3d)];return _0x2fbf66[_0xd9ad3b]||null;}}catch(_0x5048c1){if(_0x326975[_0x1cd1(0x3e)](_0x1cd1(0x3f),_0x326975['kLExz']))return console[_0x1cd1(0x14)](_0x326975[_0x1cd1(0x40)],_0x5048c1),null;else{var _0x12d814,_0xebec4c;_0x4d275c['accessControl']=_0x326975[_0x1cd1(0x37)](_0x12d814=Keychain['ACCESS_CONTROL'],null)||_0x12d814===void 0x0?void 0x0:_0x12d814[_0x1cd1(0x41)],_0x46a4c4['accessible']=(_0xebec4c=Keychain['ACCESSIBLE'])===null||_0xebec4c===void 0x0?void 0x0:_0xebec4c[_0x1cd1(0x42)];}}},[]),_0x5c696d=(0x0,_react[_0x1cd1(0x31)])(async(_0x12ae29,_0xb017d9,_0x282a7c)=>{const _0x2dfed8={'RyRZE':_0x326975[_0x1cd1(0x40)]};try{const _0xcb51e={'service':_constants[_0x1cd1(0x33)][_0x1cd1(0x34)]};if(isKeychainAvailable()){var _0x101d5a,_0x1f4362;_0xcb51e['accessControl']=_0x326975[_0x1cd1(0x37)](_0x101d5a=Keychain['ACCESS_CONTROL'],null)||_0x326975[_0x1cd1(0x43)](_0x101d5a,void 0x0)?void 0x0:_0x101d5a[_0x1cd1(0x41)],_0xcb51e[_0x1cd1(0x44)]=_0x326975[_0x1cd1(0x45)](_0x1f4362=Keychain[_0x1cd1(0x46)],null)||_0x1f4362===void 0x0?void 0x0:_0x1f4362['WHEN_UNLOCKED'];}return await _0x326975[_0x1cd1(0x47)](safeSetGenericPassword,_0x12ae29,JSON['stringify']({'userPin':_0xb017d9,'accessToken':_0x282a7c}),_0xcb51e),!![];}catch(_0x4e0471){return _0x326975[_0x1cd1(0x48)](_0x326975[_0x1cd1(0x49)],_0x326975['GqxHa'])?(_0x34d1aa[_0x1cd1(0x14)](_0x2dfed8['RyRZE'],_0xeee2b),null):(console[_0x1cd1(0x14)](_0x1cd1(0x4a),_0x4e0471),![]);}},[]),_0x496fda=(0x0,_react[_0x1cd1(0x31)])(async()=>{try{await _0x326975[_0x1cd1(0x32)](safeResetGenericPassword,{'service':_constants['STORAGE_KEYS'][_0x1cd1(0x34)]});}catch(_0x784ff1){console[_0x1cd1(0x14)](_0x326975['XwKHn'],_0x784ff1);}},[]),_0xa4cb3d=(0x0,_react[_0x1cd1(0x31)])(async _0xa5dfb0=>{if('XvHJE'!==_0x326975[_0x1cd1(0x4b)])_0x475993[_0x1cd1(0x3)]('react-native-keychain module not available in useCredentials, using mock storage');else try{if(_0x326975[_0x1cd1(0x38)]('hVrtx',_0x326975[_0x1cd1(0x4c)])){const _0x395301=(_0x326975['qcXOw'](_0x4add2d,null)||_0x326975[_0x1cd1(0x4d)](_0x23819f,void 0x0)?void 0x0:_0x1ee6c0['service'])||_0x326975[_0x1cd1(0x3d)];return _0x30654a[_0x395301]={'username':_0x34813d,'password':_0xab2f0},!![];}else{const _0x84debe=await _0x326975['qgiRV'](fetch,_api[_0x1cd1(0x4e)][_0x1cd1(0x4f)]+_0x1cd1(0x50),{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON[_0x1cd1(0x51)]({'username':_0xa5dfb0})}),_0xeb36db=await _0x84debe['json']();return{'success':!![],'isValid':_0xeb36db[_0x1cd1(0x52)],'credentials':_0xeb36db['credentials']};}}catch(_0x124795){return console[_0x1cd1(0x14)](_0x1cd1(0x27),_0x124795),{'success':![],'isValid':![]};}},[]);return{'hasCredentials':_0x525915,'getCredentials':_0x3eeff8,'storeCredentials':_0x5c696d,'clearCredentials':_0x496fda,'validateCredentials':_0xa4cb3d};};exports[_0x1cd1(0x2)]=useCredentials;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useCredentials = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
var _api = require("../config/api");
|
|
10
|
+
// Create a mock storage for environments without Keychain access
|
|
11
|
+
const mockCredentialStorage = {};
|
|
12
|
+
|
|
13
|
+
// Try to import Keychain, but provide fallbacks if not available
|
|
14
|
+
let Keychain = null;
|
|
15
|
+
try {
|
|
16
|
+
Keychain = require('react-native-keychain');
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.warn('react-native-keychain module not available in useCredentials, using mock storage');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Check if Keychain is properly initialized and available
|
|
22
|
+
const isKeychainAvailable = () => {
|
|
23
|
+
try {
|
|
24
|
+
return Keychain && typeof Keychain.getGenericPassword === 'function';
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Safe wrapper for getGenericPassword
|
|
31
|
+
const safeGetGenericPassword = async options => {
|
|
32
|
+
try {
|
|
33
|
+
if (isKeychainAvailable()) {
|
|
34
|
+
return await Keychain.getGenericPassword(options);
|
|
35
|
+
} else {
|
|
36
|
+
const key = (options === null || options === void 0 ? void 0 : options.service) || 'default';
|
|
37
|
+
return mockCredentialStorage[key] || null;
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.warn('Keychain access failed, using mock storage', error);
|
|
41
|
+
const key = (options === null || options === void 0 ? void 0 : options.service) || 'default';
|
|
42
|
+
return mockCredentialStorage[key] || null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Safe wrapper for setGenericPassword
|
|
47
|
+
const safeSetGenericPassword = async (username, password, options) => {
|
|
48
|
+
try {
|
|
49
|
+
if (isKeychainAvailable()) {
|
|
50
|
+
return await Keychain.setGenericPassword(username, password, options);
|
|
51
|
+
} else {
|
|
52
|
+
const key = (options === null || options === void 0 ? void 0 : options.service) || 'default';
|
|
53
|
+
mockCredentialStorage[key] = {
|
|
54
|
+
username,
|
|
55
|
+
password
|
|
56
|
+
};
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.warn('Keychain access failed, using mock storage', error);
|
|
61
|
+
const key = (options === null || options === void 0 ? void 0 : options.service) || 'default';
|
|
62
|
+
mockCredentialStorage[key] = {
|
|
63
|
+
username,
|
|
64
|
+
password
|
|
65
|
+
};
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Safe wrapper for resetGenericPassword
|
|
71
|
+
const safeResetGenericPassword = async options => {
|
|
72
|
+
try {
|
|
73
|
+
if (isKeychainAvailable()) {
|
|
74
|
+
return await Keychain.resetGenericPassword(options);
|
|
75
|
+
} else {
|
|
76
|
+
const key = (options === null || options === void 0 ? void 0 : options.service) || 'default';
|
|
77
|
+
delete mockCredentialStorage[key];
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.warn('Keychain access failed, using mock storage', error);
|
|
82
|
+
const key = (options === null || options === void 0 ? void 0 : options.service) || 'default';
|
|
83
|
+
delete mockCredentialStorage[key];
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const useCredentials = () => {
|
|
88
|
+
const hasCredentials = (0, _react.useCallback)(async () => {
|
|
89
|
+
try {
|
|
90
|
+
const credentials = await safeGetGenericPassword({
|
|
91
|
+
service: _constants.STORAGE_KEYS.credentials
|
|
92
|
+
});
|
|
93
|
+
return !!credentials;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error('Error checking credentials:', error);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}, []);
|
|
99
|
+
const getCredentials = (0, _react.useCallback)(async () => {
|
|
100
|
+
try {
|
|
101
|
+
const credentials = await safeGetGenericPassword({
|
|
102
|
+
service: _constants.STORAGE_KEYS.credentials
|
|
103
|
+
});
|
|
104
|
+
if (credentials) {
|
|
105
|
+
return JSON.parse(credentials.password);
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error('Error getting credentials:', error);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}, []);
|
|
113
|
+
const storeCredentials = (0, _react.useCallback)(async (username, userPin, accessToken) => {
|
|
114
|
+
try {
|
|
115
|
+
const options = {
|
|
116
|
+
service: _constants.STORAGE_KEYS.credentials
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Only use secure storage options on real devices
|
|
120
|
+
if (isKeychainAvailable()) {
|
|
121
|
+
var _Keychain$ACCESS_CONT, _Keychain$ACCESSIBLE;
|
|
122
|
+
options.accessControl = (_Keychain$ACCESS_CONT = Keychain.ACCESS_CONTROL) === null || _Keychain$ACCESS_CONT === void 0 ? void 0 : _Keychain$ACCESS_CONT.BIOMETRY_ANY;
|
|
123
|
+
options.accessible = (_Keychain$ACCESSIBLE = Keychain.ACCESSIBLE) === null || _Keychain$ACCESSIBLE === void 0 ? void 0 : _Keychain$ACCESSIBLE.WHEN_UNLOCKED;
|
|
124
|
+
}
|
|
125
|
+
await safeSetGenericPassword(username, JSON.stringify({
|
|
126
|
+
userPin,
|
|
127
|
+
accessToken
|
|
128
|
+
}), options);
|
|
129
|
+
return true;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.error('Error storing credentials:', error);
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}, []);
|
|
135
|
+
const clearCredentials = (0, _react.useCallback)(async () => {
|
|
136
|
+
try {
|
|
137
|
+
await safeResetGenericPassword({
|
|
138
|
+
service: _constants.STORAGE_KEYS.credentials
|
|
139
|
+
});
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error('Error clearing credentials:', error);
|
|
142
|
+
}
|
|
143
|
+
}, []);
|
|
144
|
+
const validateCredentials = (0, _react.useCallback)(async username => {
|
|
145
|
+
try {
|
|
146
|
+
const response = await fetch(`${_api.API_CONFIG.BASE_URL}/validate`, {
|
|
147
|
+
method: 'POST',
|
|
148
|
+
headers: {
|
|
149
|
+
'Content-Type': 'application/json'
|
|
150
|
+
},
|
|
151
|
+
body: JSON.stringify({
|
|
152
|
+
username
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
|
+
const data = await response.json();
|
|
156
|
+
return {
|
|
157
|
+
success: true,
|
|
158
|
+
isValid: data.valid,
|
|
159
|
+
credentials: data.credentials
|
|
160
|
+
};
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error('Error validating credentials:', error);
|
|
163
|
+
return {
|
|
164
|
+
success: false,
|
|
165
|
+
isValid: false
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}, []);
|
|
169
|
+
return {
|
|
170
|
+
hasCredentials,
|
|
171
|
+
getCredentials,
|
|
172
|
+
storeCredentials,
|
|
173
|
+
clearCredentials,
|
|
174
|
+
validateCredentials
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
exports.useCredentials = useCredentials;
|
|
178
|
+
//# sourceMappingURL=useCredentials.js.map
|
|
@@ -1,10 +1,148 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useUserConnections = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _userConnectionsService = require("../services/userConnectionsService");
|
|
9
|
+
var _authService = require("../services/authService");
|
|
10
|
+
var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
const useUserConnections = () => {
|
|
13
|
+
const [connections, setConnections] = (0, _react.useState)([]);
|
|
14
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(true);
|
|
15
|
+
const [error, setError] = (0, _react.useState)(null);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Load connections from API with authentication validation
|
|
19
|
+
*/
|
|
20
|
+
const loadConnections = (0, _react.useCallback)(async () => {
|
|
21
|
+
try {
|
|
22
|
+
setIsLoading(true);
|
|
23
|
+
setError(null);
|
|
24
|
+
|
|
25
|
+
// ✅ CRITICAL: Validate authentication before making API calls
|
|
26
|
+
const authToken = await (0, _authService.getAuthToken)();
|
|
27
|
+
|
|
28
|
+
// Check for demo mode (reviewer bypass)
|
|
29
|
+
const reviewerToken = await _asyncStorage.default.getItem('onairos_jwt_token');
|
|
30
|
+
const isDemoMode = reviewerToken === 'reviewer-bypass-token';
|
|
31
|
+
if (!authToken && !isDemoMode) {
|
|
32
|
+
console.warn('⚠️ [CONNECTIONS HOOK] No authentication token available for connections refresh');
|
|
33
|
+
console.warn('⚠️ [CONNECTIONS HOOK] Skipping API call to prevent unauthenticated requests');
|
|
34
|
+
setConnections([]);
|
|
35
|
+
setError('Authentication required for connections');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (isDemoMode) {
|
|
39
|
+
console.log('🎯 [DEMO MODE] Reviewer bypass detected - skipping API call for demo');
|
|
40
|
+
// For demo mode, return empty connections - ResultsScreen will use fallback data
|
|
41
|
+
setConnections([]);
|
|
42
|
+
setError(null);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// At this point, authToken must be valid (not null) because we've checked both cases above
|
|
47
|
+
if (!authToken) {
|
|
48
|
+
console.error('❌ [CONNECTIONS HOOK] Unexpected null token after validation');
|
|
49
|
+
setConnections([]);
|
|
50
|
+
setError('Authentication error');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
console.log('🔄 Loading user connections with authentication...');
|
|
54
|
+
console.log('🔑 [CONNECTIONS HOOK] Using auth token:', `${authToken.substring(0, 20)}...`);
|
|
55
|
+
const fetchedConnections = await (0, _userConnectionsService.getUserConnections)();
|
|
56
|
+
setConnections(fetchedConnections);
|
|
57
|
+
console.log('✅ Connections loaded:', fetchedConnections.length);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to load connections';
|
|
60
|
+
console.error('❌ Error loading connections:', errorMessage);
|
|
61
|
+
setError(errorMessage);
|
|
62
|
+
|
|
63
|
+
// Set empty array on error - screens will handle their own fallbacks
|
|
64
|
+
setConnections([]);
|
|
65
|
+
} finally {
|
|
66
|
+
setIsLoading(false);
|
|
67
|
+
}
|
|
68
|
+
}, []);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Refresh connections with authentication validation
|
|
72
|
+
*/
|
|
73
|
+
const refreshConnections = (0, _react.useCallback)(async () => {
|
|
74
|
+
console.log('🔄 [CONNECTIONS HOOK] Refreshing connections...');
|
|
75
|
+
await loadConnections();
|
|
76
|
+
console.log('✅ [CONNECTIONS HOOK] Connections refresh completed');
|
|
77
|
+
}, [loadConnections]);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get connections by username with authentication validation
|
|
81
|
+
*/
|
|
82
|
+
const getConnectionsByUsername = (0, _react.useCallback)(async username => {
|
|
83
|
+
try {
|
|
84
|
+
// ✅ Validate authentication before making API calls
|
|
85
|
+
const authToken = await (0, _authService.getAuthToken)();
|
|
86
|
+
if (!authToken) {
|
|
87
|
+
console.warn('⚠️ [CONNECTIONS HOOK] No authentication token available for username connections');
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
console.log('🔍 Fetching connections by username:', username);
|
|
91
|
+
console.log('🔑 [CONNECTIONS HOOK] Using auth token:', `${authToken.substring(0, 20)}...`);
|
|
92
|
+
return await (0, _userConnectionsService.getUserConnectionsByUsername)(username);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('❌ Error fetching connections by username:', error);
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
}, []);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get connections by user ID with authentication validation
|
|
101
|
+
*/
|
|
102
|
+
const getConnectionsByUserId = (0, _react.useCallback)(async userId => {
|
|
103
|
+
try {
|
|
104
|
+
// ✅ Validate authentication before making API calls
|
|
105
|
+
const authToken = await (0, _authService.getAuthToken)();
|
|
106
|
+
if (!authToken) {
|
|
107
|
+
console.warn('⚠️ [CONNECTIONS HOOK] No authentication token available for user ID connections');
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
console.log('🔍 Fetching connections by userId:', userId);
|
|
111
|
+
console.log('🔑 [CONNECTIONS HOOK] Using auth token:', `${authToken.substring(0, 20)}...`);
|
|
112
|
+
return await (0, _userConnectionsService.getUserConnectionsByUserId)(userId);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error('❌ Error fetching connections by userId:', error);
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
}, []);
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Upload profile picture
|
|
121
|
+
*/
|
|
122
|
+
const uploadUserProfilePicture = (0, _react.useCallback)(async (imageData, fileType = 'jpg') => {
|
|
123
|
+
try {
|
|
124
|
+
console.log('📷 Uploading profile picture for user:');
|
|
125
|
+
const result = await (0, _userConnectionsService.uploadProfilePicture)(imageData, fileType);
|
|
126
|
+
return result.success;
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error('❌ Error uploading profile picture:', error);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}, []);
|
|
132
|
+
|
|
133
|
+
// Load connections on mount
|
|
134
|
+
(0, _react.useEffect)(() => {
|
|
135
|
+
loadConnections();
|
|
136
|
+
}, [loadConnections]);
|
|
137
|
+
return {
|
|
138
|
+
connections,
|
|
139
|
+
isLoading,
|
|
140
|
+
error,
|
|
141
|
+
refreshConnections,
|
|
142
|
+
getConnectionsByUsername,
|
|
143
|
+
getConnectionsByUserId,
|
|
144
|
+
uploadUserProfilePicture
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
exports.useUserConnections = useUserConnections;
|
|
148
|
+
//# sourceMappingURL=useUserConnections.js.map
|