@onairos/react-native 3.7.2 → 3.7.4
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 +120 -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 +113 -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 +1,120 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Instagram Data Extractor
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates the Instagram data export flow:
|
|
5
|
+
* 1. Receives extracted activity data from WebView
|
|
6
|
+
* 2. Validates and formats data
|
|
7
|
+
* 3. Sends to backend via instagramDataService
|
|
8
|
+
*
|
|
9
|
+
* This acts as the bridge between OAuthWebView and the backend API.
|
|
10
|
+
*
|
|
11
|
+
* @reference ChatGPT implementation: src/services/chatGPTConversationExtractor.ts
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { storeInstagramData } from './instagramDataService';
|
|
15
|
+
import { Alert } from 'react-native';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Combined Instagram export data from WebView
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Hook for Instagram data extraction operations
|
|
23
|
+
*/
|
|
24
|
+
export const useInstagramDataExtractor = () => {
|
|
25
|
+
/**
|
|
26
|
+
* Initiate data export to backend
|
|
27
|
+
*
|
|
28
|
+
* @param username - User identifier
|
|
29
|
+
* @param data - Extracted Instagram data (likes, saves, collections)
|
|
30
|
+
* @returns true if successful, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
const initiateDataExport = async (username, data) => {
|
|
33
|
+
var _data$likes, _data$saves, _data$collections, _data$likes2, _data$saves2, _data$collections2;
|
|
34
|
+
console.log('🚀 [INSTAGRAM_EXTRACTOR] Initiating data export');
|
|
35
|
+
console.log('👤 [INSTAGRAM_EXTRACTOR] Username:', username);
|
|
36
|
+
console.log('📊 [INSTAGRAM_EXTRACTOR] Likes:', data.total_likes);
|
|
37
|
+
console.log('📊 [INSTAGRAM_EXTRACTOR] Saves:', data.total_saves);
|
|
38
|
+
console.log('📊 [INSTAGRAM_EXTRACTOR] Collections:', data.total_collections);
|
|
39
|
+
|
|
40
|
+
// Validation
|
|
41
|
+
if (!username) {
|
|
42
|
+
console.error('❌ [INSTAGRAM_EXTRACTOR] Username is required');
|
|
43
|
+
Alert.alert('Error', 'Username is required to export Instagram data.', [{
|
|
44
|
+
text: 'OK',
|
|
45
|
+
style: 'default'
|
|
46
|
+
}]);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Handle empty data as success - user might be new or have private activity
|
|
51
|
+
const totalItems = (((_data$likes = data.likes) === null || _data$likes === void 0 ? void 0 : _data$likes.length) || 0) + (((_data$saves = data.saves) === null || _data$saves === void 0 ? void 0 : _data$saves.length) || 0) + (((_data$collections = data.collections) === null || _data$collections === void 0 ? void 0 : _data$collections.length) || 0);
|
|
52
|
+
if (totalItems === 0) {
|
|
53
|
+
console.log('ℹ️ [INSTAGRAM_EXTRACTOR] No data to export - treating as success (connected)');
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Validate likes structure
|
|
58
|
+
const validLikes = (data.likes || []).filter(like => {
|
|
59
|
+
const isValid = like.id && like.type === 'like';
|
|
60
|
+
if (!isValid) {
|
|
61
|
+
console.warn('⚠️ [INSTAGRAM_EXTRACTOR] Invalid like:', like);
|
|
62
|
+
}
|
|
63
|
+
return isValid;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Validate saves structure
|
|
67
|
+
const validSaves = (data.saves || []).filter(save => {
|
|
68
|
+
const isValid = save.id && save.type === 'save';
|
|
69
|
+
if (!isValid) {
|
|
70
|
+
console.warn('⚠️ [INSTAGRAM_EXTRACTOR] Invalid save:', save);
|
|
71
|
+
}
|
|
72
|
+
return isValid;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Validate collections structure
|
|
76
|
+
const validCollections = (data.collections || []).filter(col => {
|
|
77
|
+
const isValid = col.id && col.name;
|
|
78
|
+
if (!isValid) {
|
|
79
|
+
console.warn('⚠️ [INSTAGRAM_EXTRACTOR] Invalid collection:', col);
|
|
80
|
+
}
|
|
81
|
+
return isValid;
|
|
82
|
+
});
|
|
83
|
+
const filteredOut = (((_data$likes2 = data.likes) === null || _data$likes2 === void 0 ? void 0 : _data$likes2.length) || 0) - validLikes.length + (((_data$saves2 = data.saves) === null || _data$saves2 === void 0 ? void 0 : _data$saves2.length) || 0) - validSaves.length + (((_data$collections2 = data.collections) === null || _data$collections2 === void 0 ? void 0 : _data$collections2.length) || 0) - validCollections.length;
|
|
84
|
+
if (filteredOut > 0) {
|
|
85
|
+
console.warn(`⚠️ [INSTAGRAM_EXTRACTOR] Filtered out ${filteredOut} invalid items`);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
console.log('📡 [INSTAGRAM_EXTRACTOR] Sending to backend...');
|
|
89
|
+
const result = await storeInstagramData(username, {
|
|
90
|
+
likes: validLikes,
|
|
91
|
+
saves: validSaves,
|
|
92
|
+
collections: validCollections,
|
|
93
|
+
userId: data.userId
|
|
94
|
+
});
|
|
95
|
+
if (result.success) {
|
|
96
|
+
console.log('✅ [INSTAGRAM_EXTRACTOR] Export completed successfully');
|
|
97
|
+
console.log('📊 [INSTAGRAM_EXTRACTOR] Backend response:', result.data);
|
|
98
|
+
return true;
|
|
99
|
+
} else {
|
|
100
|
+
console.error('❌ [INSTAGRAM_EXTRACTOR] Backend storage failed:', result.error);
|
|
101
|
+
Alert.alert('Export Failed', result.error || 'An unknown error occurred during data storage.', [{
|
|
102
|
+
text: 'OK',
|
|
103
|
+
style: 'default'
|
|
104
|
+
}]);
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error('❌ [INSTAGRAM_EXTRACTOR] Unexpected error during export:', error);
|
|
109
|
+
Alert.alert('Export Error', 'Failed to connect to the data storage service. Please check your network connection.', [{
|
|
110
|
+
text: 'OK',
|
|
111
|
+
style: 'default'
|
|
112
|
+
}]);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
initiateDataExport
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=instagramDataExtractor.js.map
|
|
@@ -1 +1,156 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Instagram Data Service
|
|
3
|
+
*
|
|
4
|
+
* API layer for storing Instagram activity data on backend.
|
|
5
|
+
* Sends extracted likes, saves, and collections to /platform-data/store endpoint.
|
|
6
|
+
*
|
|
7
|
+
* MATCHES ChatGPT implementation pattern
|
|
8
|
+
* - Uses format: { platform, data, metadata }
|
|
9
|
+
* - Platform: "mobile-instagram"
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { API_CONFIG } from '../config/api';
|
|
13
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
14
|
+
import { Platform } from 'react-native';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Structure of a liked post
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Structure of a saved post
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Structure of a collection
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Combined Instagram data to store
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Response from backend endpoint
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Store Instagram data on backend
|
|
38
|
+
*
|
|
39
|
+
* @param userId - Username or identifier
|
|
40
|
+
* @param data - Instagram likes, saves, and collections data
|
|
41
|
+
* @returns Response indicating success/failure with metadata
|
|
42
|
+
*/
|
|
43
|
+
export const storeInstagramData = async (userId, data) => {
|
|
44
|
+
console.log('🚀 [INSTAGRAM_SERVICE] Storing Instagram data for:', userId);
|
|
45
|
+
console.log('📊 [INSTAGRAM_SERVICE] Likes:', data.likes.length);
|
|
46
|
+
console.log('📊 [INSTAGRAM_SERVICE] Saves:', data.saves.length);
|
|
47
|
+
console.log('📊 [INSTAGRAM_SERVICE] Collections:', data.collections.length);
|
|
48
|
+
|
|
49
|
+
// Input validation
|
|
50
|
+
if (!userId) {
|
|
51
|
+
console.error('❌ [INSTAGRAM_SERVICE] Invalid input: userId missing');
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: 'Invalid input: userId missing.'
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
// Get auth token - check all possible storage keys
|
|
59
|
+
const authToken = (await AsyncStorage.getItem('onairos_jwt_token')) || (await AsyncStorage.getItem('enoch_token')) || (await AsyncStorage.getItem('auth_token'));
|
|
60
|
+
if (!authToken) {
|
|
61
|
+
console.error('❌ [INSTAGRAM_SERVICE] No auth token found');
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
error: 'Authentication token not found. Please log in again.'
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
console.log('🔑 [INSTAGRAM_SERVICE] Auth token found');
|
|
68
|
+
|
|
69
|
+
// Mobile metadata
|
|
70
|
+
const mobileMetadata = {
|
|
71
|
+
platform: Platform.OS,
|
|
72
|
+
appVersion: '1.0.0',
|
|
73
|
+
osVersion: Platform.OS === 'ios' ? '17.0' : Platform.OS,
|
|
74
|
+
deviceModel: Platform.OS === 'ios' ? 'iPhone' : 'Android',
|
|
75
|
+
isOfflineSync: false,
|
|
76
|
+
extractedAt: new Date().toISOString()
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Build request body
|
|
80
|
+
const requestBody = {
|
|
81
|
+
platform: 'mobile-instagram',
|
|
82
|
+
dataType: 'social',
|
|
83
|
+
data: {
|
|
84
|
+
likes: data.likes.map(like => ({
|
|
85
|
+
postId: like.id,
|
|
86
|
+
type: 'like',
|
|
87
|
+
mediaType: like.mediaType,
|
|
88
|
+
caption: like.caption,
|
|
89
|
+
owner: like.owner,
|
|
90
|
+
timestamp: like.timestamp,
|
|
91
|
+
url: like.url
|
|
92
|
+
})),
|
|
93
|
+
saves: data.saves.map(save => ({
|
|
94
|
+
postId: save.id,
|
|
95
|
+
type: 'save',
|
|
96
|
+
mediaType: save.mediaType,
|
|
97
|
+
caption: save.caption,
|
|
98
|
+
owner: save.owner,
|
|
99
|
+
timestamp: save.timestamp,
|
|
100
|
+
url: save.url
|
|
101
|
+
})),
|
|
102
|
+
collections: data.collections.map(col => ({
|
|
103
|
+
collectionId: col.id,
|
|
104
|
+
name: col.name,
|
|
105
|
+
mediaCount: col.mediaCount,
|
|
106
|
+
coverUrl: col.coverUrl
|
|
107
|
+
})),
|
|
108
|
+
instagramUserId: data.userId
|
|
109
|
+
},
|
|
110
|
+
summary: {
|
|
111
|
+
likeCount: data.likes.length,
|
|
112
|
+
saveCount: data.saves.length,
|
|
113
|
+
collectionCount: data.collections.length,
|
|
114
|
+
totalEngagements: data.likes.length + data.saves.length
|
|
115
|
+
},
|
|
116
|
+
mobileMetadata: mobileMetadata
|
|
117
|
+
};
|
|
118
|
+
console.log('📡 [INSTAGRAM_SERVICE] Sending to backend...');
|
|
119
|
+
console.log('📍 [INSTAGRAM_SERVICE] URL:', `${API_CONFIG.BASE_URL}/platform-data/store`);
|
|
120
|
+
const response = await fetch(`${API_CONFIG.BASE_URL}/platform-data/store`, {
|
|
121
|
+
method: 'POST',
|
|
122
|
+
headers: {
|
|
123
|
+
'Content-Type': 'application/json',
|
|
124
|
+
'Authorization': `Bearer ${authToken}`,
|
|
125
|
+
'User-Agent': `OnairosSDK/1.0.0 (${Platform.OS})`
|
|
126
|
+
},
|
|
127
|
+
body: JSON.stringify(requestBody)
|
|
128
|
+
});
|
|
129
|
+
const responseData = await response.json();
|
|
130
|
+
if (response.ok) {
|
|
131
|
+
console.log('✅ [INSTAGRAM_SERVICE] Successfully stored Instagram data');
|
|
132
|
+
if (responseData.message) {
|
|
133
|
+
console.log(`📝 [INSTAGRAM_SERVICE] Backend response: ${responseData.message}`);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
success: true,
|
|
137
|
+
message: responseData.message || 'Instagram data stored successfully',
|
|
138
|
+
data: responseData.data
|
|
139
|
+
};
|
|
140
|
+
} else {
|
|
141
|
+
console.warn(`⚠️ [INSTAGRAM_SERVICE] Backend returned status: ${response.status}`);
|
|
142
|
+
console.warn(`⚠️ [INSTAGRAM_SERVICE] Error: ${responseData.error || 'Unknown error'}`);
|
|
143
|
+
return {
|
|
144
|
+
success: false,
|
|
145
|
+
error: responseData.error || `HTTP ${response.status}`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error('❌ [INSTAGRAM_SERVICE] Network error:', error);
|
|
150
|
+
return {
|
|
151
|
+
success: false,
|
|
152
|
+
error: error.message || 'Network error. Please check your connection.'
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=instagramDataService.js.map
|
|
@@ -1 +1,257 @@
|
|
|
1
|
-
import AsyncStorage from'@react-native-async-storage/async-storage';const SDK_TOKEN_KEY=_0x2261(0x0),isValidJWTFormat=_0x176a6e=>{const _0x1583ad={'VFWWG':_0x2261(0x1),'ktrIP':function(_0x2ee008,_0x5a4462){return _0x2ee008<_0x5a4462;},'fNueA':function(_0x330f69,_0x35c231){return _0x330f69!==_0x35c231;}};if(!_0x176a6e||_0x176a6e[_0x2261(0x2)]<0x14)return![];if(_0x176a6e[_0x2261(0x3)]('@')&&_0x176a6e['includes']('.')&&!_0x176a6e['includes']('Bearer')&&_0x1583ad[_0x2261(0x4)](_0x176a6e[_0x2261(0x2)],0x64))return _0x2261(0x5)===_0x2261(0x5)?![]:(_0x32ec1e[_0x2261(0x6)](_0x1583ad[_0x2261(0x7)]),null);const _0x354bfe=_0x176a6e['split']('.');if(_0x1583ad[_0x2261(0x8)](_0x354bfe[_0x2261(0x2)],0x3))return![];if(_0x176a6e[_0x2261(0x2)]<0x32)return![];return!![];};export const storeJWT=async _0x58a710=>{const _0x450426={'CwMrF':_0x2261(0x9),'NIbdv':_0x2261(0xa),'zQJAJ':function(_0x42a1df){return _0x42a1df();},'hEvan':function(_0x2e88a7,_0x3787fe){return _0x2e88a7===_0x3787fe;},'vbgHw':_0x2261(0xb),'ZNxAK':_0x2261(0xc),'mjavE':_0x2261(0xd),'htfde':_0x2261(0xe),'mEfvh':_0x2261(0xf),'PXcib':_0x2261(0x10)};try{if(!_0x58a710||_0x450426[_0x2261(0x11)](_0x58a710['trim'](),''))return _0x450426[_0x2261(0x11)](_0x450426['vbgHw'],'LrmJn')?(console['warn'](_0x450426['ZNxAK']),![]):(_0x342039[_0x2261(0x12)](_0x450426[_0x2261(0x13)],_0x26f0c2),null);if(!isValidJWTFormat(_0x58a710))return _0x450426[_0x2261(0x11)](_0x450426[_0x2261(0x14)],_0x450426[_0x2261(0x15)])?(_0x19fab4[_0x2261(0x6)](_0x450426[_0x2261(0x16)],_0x2ee089['userId']),_0x24bba4[_0x2261(0x17)]):(console[_0x2261(0x18)]('⚠️\x20[JWT\x20Storage]\x20Invalid\x20JWT\x20format\x20-\x20token\x20should\x20have\x203\x20parts'),![]);return await AsyncStorage[_0x2261(0x19)](SDK_TOKEN_KEY,_0x58a710),console['log'](_0x450426[_0x2261(0x1a)]),!![];}catch(_0x3d895b){return _0x2261(0x1b)===_0x450426['PXcib']?(_0x563719[_0x2261(0x18)](_0x2261(0x1c)),_0x450426[_0x2261(0x1d)](_0xa57cf9)):(console['error'](_0x2261(0x1e),_0x3d895b),![]);}};export const getJWT=async()=>{const _0x2b3e8d={'BluFP':'❌\x20[JWT\x20Storage]\x20Failed\x20to\x20store\x20token:','LIiVw':_0x2261(0x1f),'Gkdbk':'⚠️\x20[JWT\x20Storage]\x20Invalid\x20JWT\x20format\x20for\x20userId\x20extraction','CvcOg':function(_0xdd95e0,_0x28c182){return _0xdd95e0!==_0x28c182;},'DkuHW':_0x2261(0x20),'lbyfI':_0x2261(0x1),'pbesr':function(_0x3fbdb9,_0x41edb5){return _0x3fbdb9===_0x41edb5;},'RRUWC':_0x2261(0x21),'pyxhC':_0x2261(0x22),'dOfZl':_0x2261(0x23),'XKtXz':_0x2261(0x24),'NFHfv':_0x2261(0x9)};try{if(_0x2b3e8d[_0x2261(0x25)](_0x2b3e8d[_0x2261(0x26)],_0x2b3e8d[_0x2261(0x26)]))return _0x3cd4ad[_0x2261(0x12)](_0x2b3e8d['BluFP'],_0x6ad3ea),![];else{const _0x4347c2=await AsyncStorage[_0x2261(0x27)](SDK_TOKEN_KEY);if(!_0x4347c2)return console[_0x2261(0x6)](_0x2b3e8d[_0x2261(0x28)]),null;if(!isValidJWTFormat(_0x4347c2))return _0x2b3e8d[_0x2261(0x29)](_0x2b3e8d[_0x2261(0x2a)],_0x2b3e8d['RRUWC'])?(console['warn'](_0x2b3e8d[_0x2261(0x2b)]),await clearJWT(),null):(_0x1e0f4d[_0x2261(0x12)](_0x2b3e8d[_0x2261(0x2c)]),![]);return console[_0x2261(0x6)](_0x2261(0x2d)),_0x4347c2;}}catch(_0x5556ab){return _0x2b3e8d['pbesr'](_0x2b3e8d[_0x2261(0x2e)],_0x2b3e8d[_0x2261(0x2f)])?(_0x2db43f[_0x2261(0x18)](_0x2b3e8d['Gkdbk']),null):(console[_0x2261(0x12)](_0x2b3e8d['NFHfv'],_0x5556ab),null);}};export const clearJWT=async()=>{const _0x26e0b3={'aFYGI':'❌\x20[JWT\x20Storage]\x20Failed\x20to\x20clear\x20token:'};try{return await AsyncStorage[_0x2261(0x30)](SDK_TOKEN_KEY),console[_0x2261(0x6)](_0x2261(0x31)),!![];}catch(_0xd1a2b5){return console[_0x2261(0x12)](_0x26e0b3[_0x2261(0x32)],_0xd1a2b5),![];}};function _0x2261(_0x776fe4,_0x2261c3){_0x776fe4=_0x776fe4-0x0;const _0x10ef2e=_0x776f();let _0x27cbdb=_0x10ef2e[_0x776fe4];return _0x27cbdb;}export const hasValidJWT=async()=>{const _0x85bd05={'jVivE':function(_0x46b7b8){return _0x46b7b8();},'lfVzA':function(_0x43ec36,_0x360795){return _0x43ec36!==_0x360795;}},_0x5d07fb=await _0x85bd05[_0x2261(0x33)](getJWT);return _0x85bd05[_0x2261(0x34)](_0x5d07fb,null);};const base64Decode=_0x4bb212=>{const _0x3f403f={'NjQNA':_0x2261(0x35),'WkTLQ':function(_0x2af7f1,_0x42f97a){return _0x2af7f1<_0x42f97a;},'BeGRX':function(_0x50c223,_0x44d4d1){return _0x50c223+_0x44d4d1;},'ntiNg':function(_0x2f82e7,_0x40f038){return _0x2f82e7+_0x40f038;},'VyOkS':function(_0x3f40ba,_0x2dec3c){return _0x3f40ba|_0x2dec3c;},'GUoYn':function(_0x25c1d4,_0x2bde65){return _0x25c1d4>>_0x2bde65;},'RguKh':function(_0x2122b4,_0x53c038){return _0x2122b4<<_0x53c038;},'pLZXC':function(_0x41d9b1,_0x10ad06){return _0x41d9b1&_0x10ad06;},'kBEpZ':function(_0x47ed5e,_0x2c0dc4){return _0x47ed5e|_0x2c0dc4;},'kZvhA':function(_0xee3351,_0x20b80f){return _0xee3351!==_0x20b80f;},'cwUUT':function(_0x4ba5b7,_0x206395){return _0x4ba5b7(_0x206395);},'ydpju':function(_0x5b777a,_0x35fc7d){return _0x5b777a(_0x35fc7d);}},_0xe9286a=_0x3f403f[_0x2261(0x36)];let _0xb0958d='';_0x4bb212=_0x4bb212[_0x2261(0x37)](/=+$/,'');for(let _0x259b51=0x0;_0x3f403f[_0x2261(0x38)](_0x259b51,_0x4bb212[_0x2261(0x2)]);_0x259b51+=0x4){const _0x16df42=_0xe9286a[_0x2261(0x39)](_0x4bb212['charAt'](_0x259b51)),_0x4bbafc=_0xe9286a['indexOf'](_0x4bb212[_0x2261(0x3a)](_0x3f403f[_0x2261(0x3b)](_0x259b51,0x1))),_0x401976=_0xe9286a[_0x2261(0x39)](_0x4bb212[_0x2261(0x3a)](_0x3f403f['BeGRX'](_0x259b51,0x2))),_0x1c2065=_0xe9286a['indexOf'](_0x4bb212[_0x2261(0x3a)](_0x3f403f[_0x2261(0x3c)](_0x259b51,0x3))),_0x5bf37e=_0x3f403f['VyOkS'](_0x16df42<<0x2,_0x3f403f[_0x2261(0x3d)](_0x4bbafc,0x4)),_0x2d718e=_0x3f403f[_0x2261(0x3e)](_0x3f403f[_0x2261(0x3f)](_0x3f403f[_0x2261(0x40)](_0x4bbafc,0xf),0x4),_0x3f403f[_0x2261(0x3d)](_0x401976,0x2)),_0x362390=_0x3f403f[_0x2261(0x41)](_0x3f403f[_0x2261(0x40)](_0x401976,0x3)<<0x6,_0x1c2065);_0xb0958d+=String['fromCharCode'](_0x5bf37e);if(_0x3f403f[_0x2261(0x42)](_0x401976,0x40))_0xb0958d+=String[_0x2261(0x43)](_0x2d718e);if(_0x3f403f['kZvhA'](_0x1c2065,0x40))_0xb0958d+=String[_0x2261(0x43)](_0x362390);}return _0x3f403f[_0x2261(0x44)](decodeURIComponent,_0x3f403f['ydpju'](escape,_0xb0958d));};function _0x776f(){const _0x3b7e4d=['sdk_jwt_token','📭\x20[JWT\x20Storage]\x20No\x20token\x20found\x20in\x20storage','length','includes','ktrIP','eOkRY','log','VFWWG','fNueA','❌\x20[JWT\x20Storage]\x20Failed\x20to\x20retrieve\x20token:','✅\x20[JWT\x20Storage]\x20Extracted\x20userId\x20from\x20JWT:','LrmJn','⚠️\x20[JWT\x20Storage]\x20Attempted\x20to\x20store\x20empty/null\x20token','UPDRy','zCmOV','✅\x20[JWT\x20Storage]\x20Token\x20stored\x20successfully','XYPRn','hEvan','error','CwMrF','mjavE','htfde','NIbdv','userId','warn','setItem','mEfvh','hDXpt','⚠️\x20[JWT\x20Storage]\x20clearAllJWT\x20is\x20deprecated\x20-\x20use\x20clearJWT()\x20instead','zQJAJ','❌\x20[JWT\x20Storage]\x20Failed\x20to\x20store\x20token:','❌\x20[JWT\x20Storage]\x20Invalid\x20token\x20provided\x20for\x20replacement','iMRQl','fNyZN','⚠️\x20[JWT\x20Storage]\x20Invalid\x20JWT\x20format\x20found,\x20removing','EGZUK','yYqLI','CvcOg','DkuHW','getItem','lbyfI','pbesr','RRUWC','pyxhC','LIiVw','🔐\x20[JWT\x20Storage]\x20Token\x20retrieved\x20successfully','dOfZl','XKtXz','removeItem','✅\x20[JWT\x20Storage]\x20Token\x20cleared\x20successfully','aFYGI','jVivE','lfVzA','ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=','NjQNA','replace','WkTLQ','indexOf','charAt','BeGRX','ntiNg','GUoYn','VyOkS','RguKh','pLZXC','kBEpZ','kZvhA','fromCharCode','cwUUT','⚠️\x20[JWT\x20Storage]\x20storeAuthToken\x20is\x20deprecated\x20-\x20use\x20storeJWT()\x20instead','ENOCH','enoch_token','ONAIROS','onairos_jwt_token','auth_token','wNlSk','⚠️\x20[JWT\x20Storage]\x20No\x20userId\x20field\x20found\x20in\x20JWT\x20payload','❌\x20[JWT\x20Storage]\x20Failed\x20to\x20extract\x20userId\x20from\x20token:','fadeH','CJVbc','zuOjo','📭\x20[JWT\x20Storage]\x20No\x20token\x20found\x20for\x20userId\x20extraction','Xxigy','split','cRPKS','aydDy','WYgsF','ElnpB','MEiWJ','AcnwU','DfMtu','⚠️\x20[JWT\x20Storage]\x20getJWTForRoute\x20is\x20deprecated\x20-\x20use\x20getJWT()\x20instead','DiDtA','mxKNI','PLvuf','GJLXL','oBOBu','KNMXp','❌\x20[JWT\x20Storage]\x20Failed\x20to\x20replace\x20token:','AUTH','VwmBU','lNFrC','EFtVT','⚠️\x20[JWT\x20Storage]\x20getTokenTypeForRoute\x20is\x20deprecated\x20-\x20SDK\x20uses\x20single\x20token','VltWB','EMLUw','QmYwK','UouQB','⚠️\x20[JWT\x20Storage]\x20replaceJWTAfterVerification\x20is\x20deprecated\x20-\x20use\x20replaceJWT()\x20instead','AEuFG','AfxdJ','NHlMV'];_0x776f=function(){return _0x3b7e4d;};return _0x776f();}export const getUserIdFromToken=async()=>{const _0x2fd346={'XkQnK':_0x2261(0x45),'Xxigy':function(_0x420188,_0x4cfe28){return _0x420188(_0x4cfe28);},'ElnpB':_0x2261(0x46),'MEiWJ':_0x2261(0x47),'AcnwU':_0x2261(0x48),'Ncmzj':_0x2261(0x49),'TVrTG':_0x2261(0x4a),'DKxEy':function(_0x4ed78b,_0x2a23af){return _0x4ed78b===_0x2a23af;},'fadeH':'CJVbc','cRPKS':function(_0x1e686a,_0x49ed0c){return _0x1e686a!==_0x49ed0c;},'PziiS':_0x2261(0x4b),'dPHmB':'⚠️\x20[JWT\x20Storage]\x20Invalid\x20JWT\x20format\x20for\x20userId\x20extraction','aydDy':_0x2261(0xa),'WYgsF':_0x2261(0x4c),'DfMtu':_0x2261(0x4d)};try{if(_0x2fd346['DKxEy'](_0x2fd346[_0x2261(0x4e)],_0x2261(0x4f))){const _0x3fbe10=await getJWT();if(!_0x3fbe10)return _0x2fd346['cRPKS'](_0x2fd346['PziiS'],_0x2261(0x50))?(console[_0x2261(0x6)](_0x2261(0x51)),null):(_0x22be57[_0x2261(0x18)](_0x2fd346['XkQnK']),_0x2fd346[_0x2261(0x52)](_0x2b4ce8,_0x28a3d8));const _0x4bb14e=_0x3fbe10[_0x2261(0x53)]('.');if(_0x2fd346[_0x2261(0x54)](_0x4bb14e[_0x2261(0x2)],0x3))return console['warn'](_0x2fd346['dPHmB']),null;const _0x2faedc=JSON['parse'](_0x2fd346['Xxigy'](base64Decode,_0x4bb14e[0x1]));if(_0x2faedc[_0x2261(0x17)])return console[_0x2261(0x6)](_0x2fd346[_0x2261(0x55)],_0x2faedc[_0x2261(0x17)]),_0x2faedc[_0x2261(0x17)];return console[_0x2261(0x18)](_0x2fd346[_0x2261(0x56)]),null;}else return _0x529763[_0x2fd346[_0x2261(0x57)]]=_0x2fd346[_0x2261(0x58)],_0x8095d4[_0x2fd346[_0x2261(0x59)]]=_0x2fd346['Ncmzj'],_0x3f01c3['AUTH']=_0x2fd346['TVrTG'],_0x2646ba;}catch(_0x288425){return console[_0x2261(0x12)](_0x2fd346[_0x2261(0x5a)],_0x288425),null;}};export const replaceJWT=async _0x255613=>{const _0x292ddd={'eaeQw':_0x2261(0x5b),'mxKNI':function(_0x29f4ed,_0x4cfd17){return _0x29f4ed(_0x4cfd17);},'PLvuf':function(_0x5db987,_0x3b6da0){return _0x5db987!==_0x3b6da0;},'GJLXL':'eJFJF','AZuOE':_0x2261(0x5c),'oBOBu':'❌\x20[JWT\x20Storage]\x20Invalid\x20token\x20provided\x20for\x20replacement','BCmaQ':function(_0x2e843f){return _0x2e843f();},'KNMXp':'✅\x20[JWT\x20Storage]\x20Token\x20successfully\x20replaced'};try{if(!_0x255613||!_0x292ddd[_0x2261(0x5d)](isValidJWTFormat,_0x255613))return _0x292ddd[_0x2261(0x5e)](_0x292ddd[_0x2261(0x5f)],_0x292ddd['AZuOE'])?(console[_0x2261(0x12)](_0x292ddd[_0x2261(0x60)]),![]):(_0x4d26d7[_0x2261(0x18)](_0x292ddd['eaeQw']),_0xedd197());await _0x292ddd['BCmaQ'](clearJWT);const _0x51df79=await storeJWT(_0x255613);return _0x51df79&&console[_0x2261(0x6)](_0x292ddd[_0x2261(0x61)]),_0x51df79;}catch(_0x4c8f5e){return console[_0x2261(0x12)](_0x2261(0x62),_0x4c8f5e),![];}};export let TokenType=function(_0x377245){const _0x1a8eb2={'VwmBU':_0x2261(0x46),'uprFH':_0x2261(0x48),'lNFrC':_0x2261(0x63),'EFtVT':'auth_token'};return _0x377245[_0x1a8eb2[_0x2261(0x64)]]=_0x2261(0x47),_0x377245[_0x1a8eb2['uprFH']]='onairos_jwt_token',_0x377245[_0x1a8eb2[_0x2261(0x65)]]=_0x1a8eb2[_0x2261(0x66)],_0x377245;}({});export const getTokenTypeForRoute=_0x496c07=>{const _0x1ee48d={'YdgBL':_0x2261(0x67)};return console[_0x2261(0x18)](_0x1ee48d['YdgBL']),TokenType[_0x2261(0x63)];};export const getJWTForRoute=async _0xb7e339=>{const _0x272a36={'VltWB':'⚠️\x20[JWT\x20Storage]\x20getJWTForRoute\x20is\x20deprecated\x20-\x20use\x20getJWT()\x20instead','EMLUw':function(_0x4cfcbf){return _0x4cfcbf();}};return console[_0x2261(0x18)](_0x272a36[_0x2261(0x68)]),_0x272a36[_0x2261(0x69)](getJWT);};export const clearAllJWT=async()=>{const _0x39bc3c={'YgNFF':function(_0x9d02c2){return _0x9d02c2();}};return console['warn'](_0x2261(0x1c)),_0x39bc3c['YgNFF'](clearJWT);};export const storeEnochJWT=async _0x548548=>{const _0x551ea9={'QmYwK':'⚠️\x20[JWT\x20Storage]\x20storeEnochJWT\x20is\x20deprecated\x20-\x20use\x20storeJWT()\x20instead','TunVO':function(_0xa0e938,_0x41690d){return _0xa0e938(_0x41690d);}};return console['warn'](_0x551ea9[_0x2261(0x6a)]),_0x551ea9['TunVO'](storeJWT,_0x548548);};export const storeOnairosJWT=async _0x1400bf=>{const _0x4f7314={'wasoz':'⚠️\x20[JWT\x20Storage]\x20storeOnairosJWT\x20is\x20deprecated\x20-\x20use\x20storeJWT()\x20instead','KEWpp':function(_0x2c80b9,_0x33d983){return _0x2c80b9(_0x33d983);}};return console[_0x2261(0x18)](_0x4f7314['wasoz']),_0x4f7314['KEWpp'](storeJWT,_0x1400bf);};export const storeAuthToken=async _0x40618e=>{const _0x3bd218={'UouQB':'⚠️\x20[JWT\x20Storage]\x20storeAuthToken\x20is\x20deprecated\x20-\x20use\x20storeJWT()\x20instead'};return console[_0x2261(0x18)](_0x3bd218[_0x2261(0x6b)]),storeJWT(_0x40618e);};export const replaceJWTAfterVerification=async(_0x1f9134,_0x55075b)=>{const _0x91d25c={'AEuFG':_0x2261(0x6c),'AfxdJ':function(_0x227f82,_0x2ad76a){return _0x227f82(_0x2ad76a);}};return console[_0x2261(0x18)](_0x91d25c[_0x2261(0x6d)]),_0x91d25c[_0x2261(0x6e)](replaceJWT,_0x55075b);};export const getAllTokens=async()=>{const _0x5ec0d5={'NHlMV':function(_0x331e37){return _0x331e37();}},_0x362133=await _0x5ec0d5[_0x2261(0x6f)](getJWT);return{'sdk_token':_0x362133,[TokenType[_0x2261(0x46)]]:null,[TokenType['ONAIROS']]:null,[TokenType[_0x2261(0x63)]]:null};};
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* JWT Token Storage Service - SIMPLIFIED
|
|
5
|
+
* SDK uses a single JWT token for all authentication
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This is the generic SDK JWT storage.
|
|
8
|
+
* Consuming apps that need multiple token types (like Enoch/Onairos separation)
|
|
9
|
+
* should implement their own token management.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const SDK_TOKEN_KEY = 'sdk_jwt_token';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Validate JWT format
|
|
16
|
+
* @param token - Token to validate
|
|
17
|
+
* @returns boolean - True if valid JWT format
|
|
18
|
+
*/
|
|
19
|
+
const isValidJWTFormat = token => {
|
|
20
|
+
if (!token || token.length < 20) return false;
|
|
21
|
+
|
|
22
|
+
// Check if it's an email address (invalid JWT)
|
|
23
|
+
if (token.includes('@') && token.includes('.') && !token.includes('Bearer') && token.length < 100) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Check if it has JWT structure (3 parts separated by dots)
|
|
28
|
+
const tokenParts = token.split('.');
|
|
29
|
+
if (tokenParts.length !== 3) return false;
|
|
30
|
+
|
|
31
|
+
// Additional validation - JWT should be longer than 50 characters typically
|
|
32
|
+
if (token.length < 50) return false;
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Store JWT token
|
|
38
|
+
* @param token - JWT token to store
|
|
39
|
+
* @returns Promise<boolean> - Success status
|
|
40
|
+
*/
|
|
41
|
+
export const storeJWT = async token => {
|
|
42
|
+
try {
|
|
43
|
+
if (!token || token.trim() === '') {
|
|
44
|
+
console.warn('⚠️ [JWT Storage] Attempted to store empty/null token');
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Validate JWT format
|
|
49
|
+
if (!isValidJWTFormat(token)) {
|
|
50
|
+
console.warn('⚠️ [JWT Storage] Invalid JWT format - token should have 3 parts');
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
await AsyncStorage.setItem(SDK_TOKEN_KEY, token);
|
|
54
|
+
console.log('✅ [JWT Storage] Token stored successfully');
|
|
55
|
+
return true;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('❌ [JWT Storage] Failed to store token:', error);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Retrieve JWT token
|
|
64
|
+
* @returns Promise<string | null> - JWT token or null if not found
|
|
65
|
+
*/
|
|
66
|
+
export const getJWT = async () => {
|
|
67
|
+
try {
|
|
68
|
+
const token = await AsyncStorage.getItem(SDK_TOKEN_KEY);
|
|
69
|
+
if (!token) {
|
|
70
|
+
console.log('📭 [JWT Storage] No token found in storage');
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Validate JWT format
|
|
75
|
+
if (!isValidJWTFormat(token)) {
|
|
76
|
+
console.warn('⚠️ [JWT Storage] Invalid JWT format found, removing');
|
|
77
|
+
await clearJWT();
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
console.log('🔐 [JWT Storage] Token retrieved successfully');
|
|
81
|
+
return token;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('❌ [JWT Storage] Failed to retrieve token:', error);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Clear JWT token
|
|
90
|
+
* @returns Promise<boolean> - Success status
|
|
91
|
+
*/
|
|
92
|
+
export const clearJWT = async () => {
|
|
93
|
+
try {
|
|
94
|
+
await AsyncStorage.removeItem(SDK_TOKEN_KEY);
|
|
95
|
+
console.log('✅ [JWT Storage] Token cleared successfully');
|
|
96
|
+
return true;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error('❌ [JWT Storage] Failed to clear token:', error);
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Check if valid JWT token exists
|
|
105
|
+
* @returns Promise<boolean> - True if valid token exists
|
|
106
|
+
*/
|
|
107
|
+
export const hasValidJWT = async () => {
|
|
108
|
+
const token = await getJWT();
|
|
109
|
+
return token !== null;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Base64 decode helper for React Native (atob not available)
|
|
114
|
+
*/
|
|
115
|
+
const base64Decode = str => {
|
|
116
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
117
|
+
let output = '';
|
|
118
|
+
str = str.replace(/=+$/, '');
|
|
119
|
+
for (let i = 0; i < str.length; i += 4) {
|
|
120
|
+
const enc1 = chars.indexOf(str.charAt(i));
|
|
121
|
+
const enc2 = chars.indexOf(str.charAt(i + 1));
|
|
122
|
+
const enc3 = chars.indexOf(str.charAt(i + 2));
|
|
123
|
+
const enc4 = chars.indexOf(str.charAt(i + 3));
|
|
124
|
+
const chr1 = enc1 << 2 | enc2 >> 4;
|
|
125
|
+
const chr2 = (enc2 & 15) << 4 | enc3 >> 2;
|
|
126
|
+
const chr3 = (enc3 & 3) << 6 | enc4;
|
|
127
|
+
output += String.fromCharCode(chr1);
|
|
128
|
+
if (enc3 !== 64) output += String.fromCharCode(chr2);
|
|
129
|
+
if (enc4 !== 64) output += String.fromCharCode(chr3);
|
|
130
|
+
}
|
|
131
|
+
return decodeURIComponent(escape(output));
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Decode JWT payload and extract userId (UUID)
|
|
136
|
+
* Used specifically for LinkedIn scraping which needs the main DB userId
|
|
137
|
+
* @returns Promise<string | null> - User ID (UUID) or null if not found
|
|
138
|
+
*/
|
|
139
|
+
export const getUserIdFromToken = async () => {
|
|
140
|
+
try {
|
|
141
|
+
const token = await getJWT();
|
|
142
|
+
if (!token) {
|
|
143
|
+
console.log('📭 [JWT Storage] No token found for userId extraction');
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const parts = token.split('.');
|
|
147
|
+
if (parts.length !== 3) {
|
|
148
|
+
console.warn('⚠️ [JWT Storage] Invalid JWT format for userId extraction');
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Decode the payload (middle part) - use custom base64 decode for React Native
|
|
153
|
+
const payload = JSON.parse(base64Decode(parts[1]));
|
|
154
|
+
|
|
155
|
+
// Look for userId field (this is the UUID from the backend)
|
|
156
|
+
if (payload.userId) {
|
|
157
|
+
console.log('✅ [JWT Storage] Extracted userId from JWT:', payload.userId);
|
|
158
|
+
return payload.userId;
|
|
159
|
+
}
|
|
160
|
+
console.warn('⚠️ [JWT Storage] No userId field found in JWT payload');
|
|
161
|
+
return null;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error('❌ [JWT Storage] Failed to extract userId from token:', error);
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Replace JWT token (for token refresh scenarios)
|
|
170
|
+
* @param newToken - New JWT token
|
|
171
|
+
* @returns Promise<boolean> - Success status
|
|
172
|
+
*/
|
|
173
|
+
export const replaceJWT = async newToken => {
|
|
174
|
+
try {
|
|
175
|
+
if (!newToken || !isValidJWTFormat(newToken)) {
|
|
176
|
+
console.error('❌ [JWT Storage] Invalid token provided for replacement');
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
await clearJWT();
|
|
180
|
+
const stored = await storeJWT(newToken);
|
|
181
|
+
if (stored) {
|
|
182
|
+
console.log('✅ [JWT Storage] Token successfully replaced');
|
|
183
|
+
}
|
|
184
|
+
return stored;
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.error('❌ [JWT Storage] Failed to replace token:', error);
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// ============================================
|
|
192
|
+
// DEPRECATED: Legacy token type support
|
|
193
|
+
// These are kept for backward compatibility but should not be used
|
|
194
|
+
// ============================================
|
|
195
|
+
|
|
196
|
+
/** @deprecated Use storeJWT instead */
|
|
197
|
+
export let TokenType = /*#__PURE__*/function (TokenType) {
|
|
198
|
+
TokenType["ENOCH"] = "enoch_token";
|
|
199
|
+
TokenType["ONAIROS"] = "onairos_jwt_token";
|
|
200
|
+
TokenType["AUTH"] = "auth_token";
|
|
201
|
+
return TokenType;
|
|
202
|
+
}({});
|
|
203
|
+
|
|
204
|
+
/** @deprecated Route-based token selection removed - SDK uses single token */
|
|
205
|
+
export const getTokenTypeForRoute = _route => {
|
|
206
|
+
console.warn('⚠️ [JWT Storage] getTokenTypeForRoute is deprecated - SDK uses single token');
|
|
207
|
+
return TokenType.AUTH;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/** @deprecated Use getJWT() instead */
|
|
211
|
+
export const getJWTForRoute = async _route => {
|
|
212
|
+
console.warn('⚠️ [JWT Storage] getJWTForRoute is deprecated - use getJWT() instead');
|
|
213
|
+
return getJWT();
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/** @deprecated Use clearJWT() instead */
|
|
217
|
+
export const clearAllJWT = async () => {
|
|
218
|
+
console.warn('⚠️ [JWT Storage] clearAllJWT is deprecated - use clearJWT() instead');
|
|
219
|
+
return clearJWT();
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/** @deprecated Use storeJWT() instead */
|
|
223
|
+
export const storeEnochJWT = async token => {
|
|
224
|
+
console.warn('⚠️ [JWT Storage] storeEnochJWT is deprecated - use storeJWT() instead');
|
|
225
|
+
return storeJWT(token);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/** @deprecated Use storeJWT() instead */
|
|
229
|
+
export const storeOnairosJWT = async token => {
|
|
230
|
+
console.warn('⚠️ [JWT Storage] storeOnairosJWT is deprecated - use storeJWT() instead');
|
|
231
|
+
return storeJWT(token);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/** @deprecated Use storeJWT() instead */
|
|
235
|
+
export const storeAuthToken = async token => {
|
|
236
|
+
console.warn('⚠️ [JWT Storage] storeAuthToken is deprecated - use storeJWT() instead');
|
|
237
|
+
return storeJWT(token);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/** @deprecated Use replaceJWT() instead */
|
|
241
|
+
export const replaceJWTAfterVerification = async (_tokenType, newToken) => {
|
|
242
|
+
console.warn('⚠️ [JWT Storage] replaceJWTAfterVerification is deprecated - use replaceJWT() instead');
|
|
243
|
+
return replaceJWT(newToken);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/** @deprecated For debugging only */
|
|
247
|
+
export const getAllTokens = async () => {
|
|
248
|
+
const token = await getJWT();
|
|
249
|
+
return {
|
|
250
|
+
sdk_token: token,
|
|
251
|
+
// Legacy keys for debugging
|
|
252
|
+
[TokenType.ENOCH]: null,
|
|
253
|
+
[TokenType.ONAIROS]: null,
|
|
254
|
+
[TokenType.AUTH]: null
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
//# sourceMappingURL=jwtStorageService.js.map
|