@onairos/react-native 3.7.2 → 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/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/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
|
-
function _0x3319(){const _0x18b449=['defineProperty','__esModule','useCredentials','warn','function','bXaAM','PNQpz','TiNSo','Error\x20storing\x20credentials:','default','tdDNv','sSGkA','PzoKy','viGbt','getGenericPassword','TlnKh','service','aVLLU','vLCkN','aGpBX','wqPBF','XmXlD','hEUuI','XqcpN','FVvIE','setGenericPassword','iuuGm','LEukI','pXyEG','DQDtm','GqCJu','Keychain\x20access\x20failed,\x20using\x20mock\x20storage','fJQnw','rCnRB','bzcYn','LIbCC','accessControl','BIOMETRY_ANY','accessible','oMTtR','MZXoS','GuebW','NPPtG','QivSV','UktfP','Error\x20clearing\x20credentials:','aPlyR','qwPrT','Error\x20validating\x20credentials:','useCallback','XTPPj','LlqRp','credentials','error','qBZpT','YFdGu','IontZ','mhUnq','STORAGE_KEYS','kWJMW','parse','password','NgTsA','Error\x20getting\x20credentials:','aOxUW','iEnXC','jGdqB','uueNY','stringify','XuYuz','xPfuI','UkShx','LbQUx','bDees','API_CONFIG','BASE_URL','/validate','json','valid','DifcW','btyad','eQjHN','YVMek','CpKiy'];_0x3319=function(){return _0x18b449;};return _0x3319();}function _0x53e2(_0x331957,_0x53e25b){_0x331957=_0x331957-0x0;const _0x1c6cca=_0x3319();let _0x1ddb17=_0x1c6cca[_0x331957];return _0x1ddb17;}Object[_0x53e2(0x0)](exports,_0x53e2(0x1),{'value':!![]}),exports[_0x53e2(0x2)]=void 0x0;var _react=__ONAIROS_REQ_FUNC__(0x0),_constants=__ONAIROS_REQ_FUNC__(0x1),_api=__ONAIROS_REQ_FUNC__(0x2);const mockCredentialStorage={};let Keychain=null;try{Keychain=__ONAIROS_REQ_FUNC__(0x3);}catch(_0x37f614){console[_0x53e2(0x3)]('react-native-keychain module not available in useCredentials, using mock storage');}const isKeychainAvailable=()=>{const _0xd0917={'bXaAM':function(_0x34873b,_0x5f1cf4){return _0x34873b===_0x5f1cf4;},'FPLMH':'kCFLX','PNQpz':function(_0x215465,_0x5641f3){return _0x215465===_0x5641f3;},'TiNSo':_0x53e2(0x4)};try{return _0xd0917[_0x53e2(0x5)](_0xd0917['FPLMH'],_0xd0917['FPLMH'])?Keychain&&_0xd0917[_0x53e2(0x6)](typeof Keychain['getGenericPassword'],_0xd0917[_0x53e2(0x7)]):Keychain&&typeof Keychain['getGenericPassword']===_0x53e2(0x4);}catch(_0x32313f){return![];}},safeGetGenericPassword=async _0x3a4024=>{const _0x426900={'defDI':_0x53e2(0x8),'vLCkN':function(_0x16056f,_0x4badd4){return _0x16056f===_0x4badd4;},'aVLLU':_0x53e2(0x9),'kajQt':function(_0x9a6c8f,_0x288d18){return _0x9a6c8f===_0x288d18;},'sSGkA':_0x53e2(0xa),'PzoKy':function(_0x344114){return _0x344114();},'prsYc':function(_0x1f6fda,_0x457a19){return _0x1f6fda===_0x457a19;},'TlnKh':function(_0x411725,_0x10c804){return _0x411725===_0x10c804;},'aGpBX':'Keychain\x20access\x20failed,\x20using\x20mock\x20storage','wqPBF':function(_0x297a15,_0x1138d3){return _0x297a15===_0x1138d3;},'vcegw':function(_0x167d47,_0x3cbf0c){return _0x167d47===_0x3cbf0c;}};try{if(_0x426900['kajQt'](_0x426900[_0x53e2(0xb)],_0x53e2(0xa))){if(_0x426900[_0x53e2(0xc)](isKeychainAvailable))return _0x53e2(0xd)!==_0x53e2(0xd)?(_0x4ebdc9['error'](_0x426900['defDI'],_0x33b159),![]):await Keychain[_0x53e2(0xe)](_0x3a4024);else{const _0x432b21=(_0x426900['prsYc'](_0x3a4024,null)||_0x426900[_0x53e2(0xf)](_0x3a4024,void 0x0)?void 0x0:_0x3a4024[_0x53e2(0x10)])||_0x426900[_0x53e2(0x11)];return mockCredentialStorage[_0x432b21]||null;}}else{const _0x59c835=(_0x426900[_0x53e2(0x12)](_0x1ca92e,null)||_0x426900['vLCkN'](_0x2e9d36,void 0x0)?void 0x0:_0x33668e[_0x53e2(0x10)])||_0x426900[_0x53e2(0x11)];return _0x283000[_0x59c835]={'username':_0x1121b5,'password':_0x8c340e},!![];}}catch(_0x586229){console[_0x53e2(0x3)](_0x426900[_0x53e2(0x13)],_0x586229);const _0x5d3736=(_0x426900[_0x53e2(0x14)](_0x3a4024,null)||_0x426900['vcegw'](_0x3a4024,void 0x0)?void 0x0:_0x3a4024[_0x53e2(0x10)])||_0x426900[_0x53e2(0x11)];return mockCredentialStorage[_0x5d3736]||null;}},safeSetGenericPassword=async(_0x35e915,_0x5a9727,_0xe8899f)=>{const _0x4efbac={'XqcpN':function(_0x4191bf){return _0x4191bf();},'LEukI':function(_0x412d51,_0x3411cb){return _0x412d51===_0x3411cb;},'lIWzz':_0x53e2(0x15),'FVvIE':_0x53e2(0x16),'iuuGm':function(_0x5f45b3,_0x292901){return _0x5f45b3===_0x292901;},'pXyEG':_0x53e2(0x9),'DQDtm':'Keychain\x20access\x20failed,\x20using\x20mock\x20storage','GqCJu':function(_0x1cbb80,_0x55436a){return _0x1cbb80===_0x55436a;}};try{if(_0x4efbac[_0x53e2(0x17)](isKeychainAvailable))return _0x4efbac['LEukI'](_0x4efbac['lIWzz'],_0x4efbac[_0x53e2(0x18)])?![]:await Keychain[_0x53e2(0x19)](_0x35e915,_0x5a9727,_0xe8899f);else{const _0x102939=(_0x4efbac[_0x53e2(0x1a)](_0xe8899f,null)||_0x4efbac[_0x53e2(0x1b)](_0xe8899f,void 0x0)?void 0x0:_0xe8899f[_0x53e2(0x10)])||_0x4efbac[_0x53e2(0x1c)];return mockCredentialStorage[_0x102939]={'username':_0x35e915,'password':_0x5a9727},!![];}}catch(_0x2c2bea){console[_0x53e2(0x3)](_0x4efbac[_0x53e2(0x1d)],_0x2c2bea);const _0x226196=(_0x4efbac[_0x53e2(0x1e)](_0xe8899f,null)||_0x4efbac[_0x53e2(0x1e)](_0xe8899f,void 0x0)?void 0x0:_0xe8899f['service'])||_0x4efbac[_0x53e2(0x1c)];return mockCredentialStorage[_0x226196]={'username':_0x35e915,'password':_0x5a9727},!![];}},safeResetGenericPassword=async _0x41a21b=>{const _0x1dbe8d={'rCnRB':function(_0x50e42b,_0x50f730){return _0x50e42b===_0x50f730;},'qklCR':'qRaih','fJQnw':function(_0x59727f){return _0x59727f();},'bzcYn':function(_0x1d8147,_0xf3d2d7){return _0x1d8147===_0xf3d2d7;},'LIbCC':_0x53e2(0x9),'oMTtR':_0x53e2(0x1f),'MZXoS':function(_0xfacda3,_0x5d864b){return _0xfacda3===_0x5d864b;}};try{if(_0x1dbe8d['qklCR']===_0x1dbe8d['qklCR']){if(_0x1dbe8d[_0x53e2(0x20)](isKeychainAvailable))return await Keychain['resetGenericPassword'](_0x41a21b);else{const _0x145140=(_0x1dbe8d[_0x53e2(0x21)](_0x41a21b,null)||_0x1dbe8d[_0x53e2(0x22)](_0x41a21b,void 0x0)?void 0x0:_0x41a21b['service'])||_0x1dbe8d[_0x53e2(0x23)];return delete mockCredentialStorage[_0x145140],!![];}}else{var _0x24f5c7,_0x4b82ba;_0x313494[_0x53e2(0x24)]=_0x1dbe8d[_0x53e2(0x21)](_0x24f5c7=Keychain['ACCESS_CONTROL'],null)||_0x1dbe8d[_0x53e2(0x21)](_0x24f5c7,void 0x0)?void 0x0:_0x24f5c7[_0x53e2(0x25)],_0x4fbe14[_0x53e2(0x26)]=(_0x4b82ba=Keychain['ACCESSIBLE'])===null||_0x1dbe8d[_0x53e2(0x21)](_0x4b82ba,void 0x0)?void 0x0:_0x4b82ba['WHEN_UNLOCKED'];}}catch(_0x42a52c){console[_0x53e2(0x3)](_0x1dbe8d[_0x53e2(0x27)],_0x42a52c);const _0x15fcaa=(_0x41a21b===null||_0x1dbe8d[_0x53e2(0x28)](_0x41a21b,void 0x0)?void 0x0:_0x41a21b[_0x53e2(0x10)])||_0x1dbe8d[_0x53e2(0x23)];return delete mockCredentialStorage[_0x15fcaa],!![];}},useCredentials=()=>{const _0x4d33eb={'XTPPj':_0x53e2(0x29),'mhUnq':function(_0x1e6362,_0x2027a9){return _0x1e6362(_0x2027a9);},'qBZpT':'Error\x20checking\x20credentials:','NgTsA':function(_0x4f1d72,_0x139311){return _0x4f1d72(_0x139311);},'YFdGu':function(_0x30cff6,_0x128f3f){return _0x30cff6===_0x128f3f;},'IontZ':_0x53e2(0x2a),'kWJMW':_0x53e2(0x2b),'aOxUW':function(_0x39da1){return _0x39da1();},'iEnXC':function(_0x3d7b63,_0x4556e7){return _0x3d7b63===_0x4556e7;},'jGdqB':function(_0x2e3462,_0x55c55c){return _0x2e3462===_0x55c55c;},'uueNY':function(_0x387f51,_0x4b8d27,_0x2f9c81,_0x4a1cd7){return _0x387f51(_0x4b8d27,_0x2f9c81,_0x4a1cd7);},'XuYuz':'Error\x20storing\x20credentials:','xPfuI':_0x53e2(0x2c),'ERANC':_0x53e2(0x2d),'qjPIl':function(_0xc5680a,_0x53ccb1){return _0xc5680a===_0x53ccb1;},'ughME':_0x53e2(0x9),'UkShx':function(_0x903a7f,_0x2b2253){return _0x903a7f===_0x2b2253;},'bDees':function(_0x10b132,_0x2b8d5a,_0x29226e){return _0x10b132(_0x2b8d5a,_0x29226e);},'DifcW':_0x53e2(0x2e),'btyad':_0x53e2(0x2f),'eQjHN':_0x53e2(0x30)},_0x492806=(0x0,_react[_0x53e2(0x31)])(async()=>{try{if(_0x4d33eb[_0x53e2(0x32)]!==_0x53e2(0x33)){const _0x13c7a2=await _0x4d33eb['mhUnq'](safeGetGenericPassword,{'service':_constants['STORAGE_KEYS'][_0x53e2(0x34)]});return!!_0x13c7a2;}else return _0x14753f[_0x53e2(0x35)]('Error\x20checking\x20credentials:',_0x590be1),![];}catch(_0xde1afd){return console[_0x53e2(0x35)](_0x4d33eb[_0x53e2(0x36)],_0xde1afd),![];}},[]),_0x4e2c1c=(0x0,_react[_0x53e2(0x31)])(async()=>{const _0x265628={'dIQSH':_0x53e2(0x30)};try{if(_0x4d33eb[_0x53e2(0x37)](_0x4d33eb[_0x53e2(0x38)],_0x53e2(0x2a))){const _0x1b0a0e=await _0x4d33eb[_0x53e2(0x39)](safeGetGenericPassword,{'service':_constants[_0x53e2(0x3a)][_0x53e2(0x34)]});if(_0x1b0a0e)return _0x4d33eb[_0x53e2(0x37)](_0x4d33eb[_0x53e2(0x3b)],_0x4d33eb[_0x53e2(0x3b)])?JSON[_0x53e2(0x3c)](_0x1b0a0e[_0x53e2(0x3d)]):(_0x16fa87[_0x53e2(0x35)](_0x265628['dIQSH'],_0x21039a),{'success':![],'isValid':![]});return null;}else Keychain=_0x4d33eb[_0x53e2(0x3e)](_0x1473b3,0x3);}catch(_0x46a955){return console[_0x53e2(0x35)](_0x53e2(0x3f),_0x46a955),null;}},[]),_0x508b1a=(0x0,_react[_0x53e2(0x31)])(async(_0x52481e,_0x24b7e8,_0x41597d)=>{try{const _0x455399={'service':_constants['STORAGE_KEYS'][_0x53e2(0x34)]};if(_0x4d33eb[_0x53e2(0x40)](isKeychainAvailable)){var _0x349174,_0xc0c003;_0x455399[_0x53e2(0x24)]=_0x4d33eb[_0x53e2(0x37)](_0x349174=Keychain['ACCESS_CONTROL'],null)||_0x4d33eb['YFdGu'](_0x349174,void 0x0)?void 0x0:_0x349174[_0x53e2(0x25)],_0x455399[_0x53e2(0x26)]=_0x4d33eb[_0x53e2(0x41)](_0xc0c003=Keychain['ACCESSIBLE'],null)||_0x4d33eb[_0x53e2(0x42)](_0xc0c003,void 0x0)?void 0x0:_0xc0c003['WHEN_UNLOCKED'];}return await _0x4d33eb[_0x53e2(0x43)](safeSetGenericPassword,_0x52481e,JSON[_0x53e2(0x44)]({'userPin':_0x24b7e8,'accessToken':_0x41597d}),_0x455399),!![];}catch(_0x1d07e5){return console[_0x53e2(0x35)](_0x4d33eb[_0x53e2(0x45)],_0x1d07e5),![];}},[]),_0x5a512f=(0x0,_react['useCallback'])(async()=>{try{await _0x4d33eb[_0x53e2(0x39)](safeResetGenericPassword,{'service':_constants['STORAGE_KEYS'][_0x53e2(0x34)]});}catch(_0xe90d1b){_0x4d33eb[_0x53e2(0x46)]!==_0x4d33eb[_0x53e2(0x46)]?_0x7f4102['warn']('react-native-keychain module not available in useCredentials, using mock storage'):console['error'](_0x4d33eb['ERANC'],_0xe90d1b);}},[]),_0x2120e6=(0x0,_react[_0x53e2(0x31)])(async _0x532fd4=>{const _0x1204a1={'YVMek':function(_0x55d704,_0x39a8f3){return _0x4d33eb['qjPIl'](_0x55d704,_0x39a8f3);},'CpKiy':_0x4d33eb['ughME']};try{if(_0x4d33eb[_0x53e2(0x47)](_0x53e2(0x48),_0x53e2(0x48))){const _0x31aab2=await _0x4d33eb[_0x53e2(0x49)](fetch,_api[_0x53e2(0x4a)][_0x53e2(0x4b)]+_0x53e2(0x4c),{'method':'POST','headers':{'Content-Type':'application/json'},'body':JSON['stringify']({'username':_0x532fd4})}),_0x597a39=await _0x31aab2[_0x53e2(0x4d)]();return{'success':!![],'isValid':_0x597a39[_0x53e2(0x4e)],'credentials':_0x597a39['credentials']};}else try{return Keychain&&typeof Keychain[_0x53e2(0xe)]===_0x53e2(0x4);}catch(_0x40e170){return![];}}catch(_0x444980){if(_0x4d33eb[_0x53e2(0x4f)]!==_0x4d33eb[_0x53e2(0x50)])return console[_0x53e2(0x35)](_0x4d33eb[_0x53e2(0x51)],_0x444980),{'success':![],'isValid':![]};else{const _0x5cbc60=(_0x1204a1[_0x53e2(0x52)](_0x3dbb05,null)||_0x3b8d12===void 0x0?void 0x0:_0x1e092a[_0x53e2(0x10)])||_0x1204a1[_0x53e2(0x53)];return _0x2ef49c[_0x5cbc60]||null;}}},[]);return{'hasCredentials':_0x492806,'getCredentials':_0x4e2c1c,'storeCredentials':_0x508b1a,'clearCredentials':_0x5a512f,'validateCredentials':_0x2120e6};};exports['useCredentials']=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
|