@onairos/react-native 3.7.1 → 3.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/api/index.js +219 -9
- package/lib/commonjs/assets/icons/spotify.png +0 -0
- package/lib/commonjs/assets/images/spotify.png +0 -0
- package/lib/commonjs/components/BodyText.js +27 -9
- package/lib/commonjs/components/BrandMark.js +111 -10
- package/lib/commonjs/components/CodeInput.js +116 -9
- package/lib/commonjs/components/EmailInput.js +30 -8
- package/lib/commonjs/components/GoogleButton.js +56 -9
- package/lib/commonjs/components/HeadingGroup.js +43 -9
- package/lib/commonjs/components/LLMDataInputModal.js +664 -14
- package/lib/commonjs/components/ModalHeader.js +99 -9
- package/lib/commonjs/components/ModalSheet.js +47 -9
- package/lib/commonjs/components/Onairos.js +380 -14
- package/lib/commonjs/components/OnairosButton.js +313 -13
- package/lib/commonjs/components/OnairosSignInButton.js +130 -12
- package/lib/commonjs/components/Overlay.js +465 -13
- package/lib/commonjs/components/PersonaImage.js +137 -10
- package/lib/commonjs/components/PersonaLoadingScreen.js +318 -12
- package/lib/commonjs/components/PersonalizationConsentScreen.js +467 -13
- package/lib/commonjs/components/PinCreationScreen.js +403 -12
- package/lib/commonjs/components/PinInput.js +464 -9
- package/lib/commonjs/components/PlatformConnectorsStep.js +1311 -23
- package/lib/commonjs/components/PlatformList.js +137 -10
- package/lib/commonjs/components/PlatformToggle.js +180 -9
- package/lib/commonjs/components/PrimaryButton.js +180 -10
- package/lib/commonjs/components/SignInMatchAnimation.js +197 -9
- package/lib/commonjs/components/SignInStep.js +345 -12
- package/lib/commonjs/components/UniversalOnboarding.js +2780 -30
- package/lib/commonjs/components/VerificationStep.js +176 -11
- package/lib/commonjs/components/WelcomeScreen.js +461 -22
- package/lib/commonjs/components/icons/Basicproficon.js +37 -8
- package/lib/commonjs/components/icons/Basicprofile.js +21 -8
- package/lib/commonjs/components/icons/Checkbox.js +21 -8
- package/lib/commonjs/components/icons/Checkmark.js +27 -8
- package/lib/commonjs/components/icons/Contentanalysis.js +21 -8
- package/lib/commonjs/components/icons/Contenticon.js +39 -8
- package/lib/commonjs/components/icons/EnochE.js +41 -8
- package/lib/commonjs/components/icons/Personalityicon.js +30 -8
- package/lib/commonjs/components/icons/Personalityprofile.js +21 -8
- package/lib/commonjs/components/icons/Personalitytraits.js +21 -8
- package/lib/commonjs/components/icons/Userpreferences.js +21 -8
- package/lib/commonjs/components/icons/index.js +84 -17
- package/lib/commonjs/components/onboarding/OAuthWebView.js +1754 -18
- package/lib/commonjs/components/onboarding/OnboardingHeader.js +74 -10
- package/lib/commonjs/components/onboarding/PinInput.js +283 -10
- package/lib/commonjs/components/onboarding/PlatformConnector.js +249 -11
- package/lib/commonjs/config/PLATFORM_APIS.md +849 -0
- package/lib/commonjs/config/api.js +56 -7
- package/lib/commonjs/constants/index.js +120 -7
- package/lib/commonjs/context/AuthContext.js +345 -10
- package/lib/commonjs/hooks/useConnectedAccounts.js +111 -9
- package/lib/commonjs/hooks/useConnections.js +102 -8
- package/lib/commonjs/hooks/useCredentials.js +178 -10
- package/lib/commonjs/hooks/useUserConnections.js +148 -10
- package/lib/commonjs/index.js +439 -34
- package/lib/commonjs/services/apiClient.js +298 -8
- package/lib/commonjs/services/biometricPinService.js +180 -8
- package/lib/commonjs/services/chatGPTConversationExtractor.js +155 -8
- package/lib/commonjs/services/chatGPTConversationService.js +275 -9
- package/lib/commonjs/services/claudeConversationExtractor.js +103 -8
- package/lib/commonjs/services/claudeConversationService.js +158 -9
- package/lib/commonjs/services/connectedAccountsService.js +310 -10
- package/lib/commonjs/services/googleAuthService.js +252 -11
- package/lib/commonjs/services/hingeDataExtractor.js +105 -8
- package/lib/commonjs/services/hingeDataService.js +150 -9
- package/lib/commonjs/services/imageCompressionService.js +260 -7
- package/lib/commonjs/services/instagramDataExtractor.js +126 -8
- package/lib/commonjs/services/instagramDataService.js +163 -9
- package/lib/commonjs/services/jwtStorageService.js +276 -7
- package/lib/commonjs/services/linkedinDOMExtractor.js +245 -7
- package/lib/commonjs/services/linkedinProfileService.js +222 -9
- package/lib/commonjs/services/linkedinScrapingService.js +230 -8
- package/lib/commonjs/services/llmDataStorage.js +294 -8
- package/lib/commonjs/services/mobileTrainingService.js +186 -8
- package/lib/commonjs/services/netflixDataExtractor.js +120 -8
- package/lib/commonjs/services/netflixDataService.js +198 -9
- package/lib/commonjs/services/pinEncryptionService.js +84 -8
- package/lib/commonjs/services/pinStorageUtils.js +105 -7
- package/lib/commonjs/services/platformAuthService.js +1484 -12
- package/lib/commonjs/services/sephoraDataExtractor.js +140 -8
- package/lib/commonjs/services/sephoraDataService.js +200 -9
- package/lib/commonjs/services/spotifyDataExtractor.js +148 -8
- package/lib/commonjs/services/spotifyDataService.js +241 -9
- package/lib/commonjs/services/storageService.js +404 -8
- package/lib/commonjs/services/telegramDataExtractor.js +115 -8
- package/lib/commonjs/services/telegramDataService.js +499 -9
- package/lib/commonjs/services/trainingApiHelpers.js +73 -7
- package/lib/commonjs/services/userConnectionsService.js +340 -10
- package/lib/commonjs/services/youtubeMigrationService.js +416 -10
- package/lib/commonjs/theme/index.js +250 -7
- package/lib/commonjs/types/ambient.d.js +2 -1
- package/lib/commonjs/types/declarations.d.js +2 -1
- package/lib/commonjs/types/index.js +6 -1
- package/lib/commonjs/types/node-fix.d.js +2 -1
- package/lib/commonjs/types/node-override.d.js +2 -1
- package/lib/commonjs/types/opacity.d.js +2 -1
- package/lib/commonjs/types.js +14 -1
- package/lib/commonjs/utils/Portal.js +98 -8
- package/lib/commonjs/utils/api.js +130 -9
- package/lib/commonjs/utils/assetRegistry.js +210 -35
- package/lib/commonjs/utils/auth.js +112 -9
- package/lib/commonjs/utils/connectorTests.js +613 -29
- package/lib/commonjs/utils/crypto.js +62 -8
- package/lib/commonjs/utils/debugHelper.js +64 -1
- package/lib/commonjs/utils/encryption.js +76 -7
- package/lib/commonjs/utils/eventUtils.js +288 -1
- package/lib/commonjs/utils/haptics.js +66 -9
- package/lib/commonjs/utils/imagePreloader.js +6 -1
- package/lib/commonjs/utils/networkDiagnostics.js +226 -8
- package/lib/commonjs/utils/onairosApi.js +350 -9
- package/lib/commonjs/utils/programmaticFlow.js +117 -9
- package/lib/commonjs/utils/retryHelper.js +220 -1
- package/lib/commonjs/utils/secureStorage.js +349 -10
- package/lib/commonjs/utils/webviewScripts/chatgpt.js +551 -1
- package/lib/commonjs/utils/webviewScripts/claude.js +376 -1
- package/lib/commonjs/utils/webviewScripts/hinge.js +411 -1
- package/lib/commonjs/utils/webviewScripts/index.js +698 -15
- package/lib/commonjs/utils/webviewScripts/instagram.js +454 -1
- package/lib/commonjs/utils/webviewScripts/linkedin.js +880 -1
- package/lib/commonjs/utils/webviewScripts/netflix.js +382 -1
- package/lib/commonjs/utils/webviewScripts/sephora.js +516 -1
- package/lib/commonjs/utils/webviewScripts/spotify.js +419 -1
- package/lib/commonjs/utils/webviewScripts/telegram.js +678 -1
- package/lib/module/api/index.js +211 -1
- package/lib/module/assets/icons/spotify.png +0 -0
- package/lib/module/assets/images/spotify.png +0 -0
- package/lib/module/components/BodyText.js +20 -1
- package/lib/module/components/BrandMark.js +104 -1
- package/lib/module/components/CodeInput.js +109 -1
- package/lib/module/components/EmailInput.js +23 -1
- package/lib/module/components/GoogleButton.js +49 -1
- package/lib/module/components/HeadingGroup.js +36 -1
- package/lib/module/components/LLMDataInputModal.js +656 -7
- package/lib/module/components/ModalHeader.js +92 -1
- package/lib/module/components/ModalSheet.js +39 -1
- package/lib/module/components/Onairos.js +373 -1
- package/lib/module/components/OnairosButton.js +305 -1
- package/lib/module/components/OnairosSignInButton.js +121 -1
- package/lib/module/components/Overlay.js +456 -1
- package/lib/module/components/PersonaImage.js +129 -1
- package/lib/module/components/PersonaLoadingScreen.js +310 -1
- package/lib/module/components/PersonalizationConsentScreen.js +460 -1
- package/lib/module/components/PinCreationScreen.js +396 -1
- package/lib/module/components/PinInput.js +456 -1
- package/lib/module/components/PlatformConnectorsStep.js +1302 -6
- package/lib/module/components/PlatformList.js +129 -1
- package/lib/module/components/PlatformToggle.js +173 -1
- package/lib/module/components/PrimaryButton.js +172 -1
- package/lib/module/components/SignInMatchAnimation.js +189 -1
- package/lib/module/components/SignInStep.js +338 -1
- package/lib/module/components/UniversalOnboarding.js +2770 -1
- package/lib/module/components/VerificationStep.js +168 -1
- package/lib/module/components/WelcomeScreen.js +453 -1
- package/lib/module/components/icons/Basicproficon.js +30 -1
- package/lib/module/components/icons/Basicprofile.js +14 -1
- package/lib/module/components/icons/Checkbox.js +14 -1
- package/lib/module/components/icons/Checkmark.js +20 -1
- package/lib/module/components/icons/Contentanalysis.js +14 -1
- package/lib/module/components/icons/Contenticon.js +32 -1
- package/lib/module/components/icons/EnochE.js +34 -1
- package/lib/module/components/icons/Personalityicon.js +23 -1
- package/lib/module/components/icons/Personalityprofile.js +14 -1
- package/lib/module/components/icons/Personalitytraits.js +14 -1
- package/lib/module/components/icons/Userpreferences.js +14 -1
- package/lib/module/components/icons/index.js +13 -1
- package/lib/module/components/onboarding/OAuthWebView.js +1746 -1
- package/lib/module/components/onboarding/OnboardingHeader.js +66 -1
- package/lib/module/components/onboarding/PinInput.js +274 -1
- package/lib/module/components/onboarding/PlatformConnector.js +240 -1
- package/lib/module/config/PLATFORM_APIS.md +849 -0
- package/lib/module/config/api.js +47 -1
- package/lib/module/constants/index.js +114 -1
- package/lib/module/context/AuthContext.js +335 -1
- package/lib/module/hooks/useConnectedAccounts.js +106 -1
- package/lib/module/hooks/useConnections.js +95 -1
- package/lib/module/hooks/useCredentials.js +171 -6
- package/lib/module/hooks/useUserConnections.js +140 -1
- package/lib/module/index.js +172 -1
- package/lib/module/services/apiClient.js +295 -1
- package/lib/module/services/biometricPinService.js +169 -1
- package/lib/module/services/chatGPTConversationExtractor.js +149 -1
- package/lib/module/services/chatGPTConversationService.js +268 -1
- package/lib/module/services/claudeConversationExtractor.js +97 -1
- package/lib/module/services/claudeConversationService.js +151 -1
- package/lib/module/services/connectedAccountsService.js +293 -1
- package/lib/module/services/googleAuthService.js +241 -1
- package/lib/module/services/hingeDataExtractor.js +99 -1
- package/lib/module/services/hingeDataService.js +143 -1
- package/lib/module/services/imageCompressionService.js +250 -1
- package/lib/module/services/instagramDataExtractor.js +120 -1
- package/lib/module/services/instagramDataService.js +156 -1
- package/lib/module/services/jwtStorageService.js +257 -1
- package/lib/module/services/linkedinDOMExtractor.js +234 -1
- package/lib/module/services/linkedinProfileService.js +210 -1
- package/lib/module/services/linkedinScrapingService.js +219 -1
- package/lib/module/services/llmDataStorage.js +277 -1
- package/lib/module/services/mobileTrainingService.js +173 -1
- package/lib/module/services/netflixDataExtractor.js +114 -1
- package/lib/module/services/netflixDataService.js +191 -1
- package/lib/module/services/pinEncryptionService.js +74 -6
- package/lib/module/services/pinStorageUtils.js +93 -1
- package/lib/module/services/platformAuthService.js +1461 -1
- package/lib/module/services/sephoraDataExtractor.js +134 -1
- package/lib/module/services/sephoraDataService.js +193 -1
- package/lib/module/services/spotifyDataExtractor.js +142 -1
- package/lib/module/services/spotifyDataService.js +234 -1
- package/lib/module/services/storageService.js +383 -1
- package/lib/module/services/telegramDataExtractor.js +109 -1
- package/lib/module/services/telegramDataService.js +493 -1
- package/lib/module/services/trainingApiHelpers.js +67 -1
- package/lib/module/services/userConnectionsService.js +329 -1
- package/lib/module/services/youtubeMigrationService.js +405 -1
- package/lib/module/theme/index.js +245 -1
- package/lib/module/types.js +10 -1
- package/lib/module/utils/Portal.js +90 -1
- package/lib/module/utils/api.js +118 -1
- package/lib/module/utils/assetRegistry.js +200 -34
- package/lib/module/utils/auth.js +100 -1
- package/lib/module/utils/connectorTests.js +600 -27
- package/lib/module/utils/crypto.js +54 -1
- package/lib/module/utils/debugHelper.js +54 -1
- package/lib/module/utils/encryption.js +67 -1
- package/lib/module/utils/eventUtils.js +270 -1
- package/lib/module/utils/haptics.js +59 -8
- package/lib/module/utils/imagePreloader.js +3 -1
- package/lib/module/utils/networkDiagnostics.js +217 -1
- package/lib/module/utils/onairosApi.js +333 -1
- package/lib/module/utils/programmaticFlow.js +111 -1
- package/lib/module/utils/retryHelper.js +211 -1
- package/lib/module/utils/secureStorage.js +330 -6
- package/lib/module/utils/webviewScripts/chatgpt.js +545 -1
- package/lib/module/utils/webviewScripts/claude.js +370 -1
- package/lib/module/utils/webviewScripts/hinge.js +405 -1
- package/lib/module/utils/webviewScripts/index.js +434 -1
- package/lib/module/utils/webviewScripts/instagram.js +448 -1
- package/lib/module/utils/webviewScripts/linkedin.js +874 -1
- package/lib/module/utils/webviewScripts/netflix.js +376 -1
- package/lib/module/utils/webviewScripts/sephora.js +510 -1
- package/lib/module/utils/webviewScripts/spotify.js +413 -1
- package/lib/module/utils/webviewScripts/telegram.js +672 -1
- package/package.json +2 -2
|
@@ -1 +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';function _0x3dc8(){const _0x288e3b=['sdk_jwt_token','QXGFS','yDkcJ','length','includes','vIZwX','error','❌\x20[JWT\x20Storage]\x20Failed\x20to\x20clear\x20token:','split','❌\x20[JWT\x20Storage]\x20Failed\x20to\x20store\x20token:','warn','FANbf','⚠️\x20[JWT\x20Storage]\x20Invalid\x20JWT\x20format\x20-\x20token\x20should\x20have\x203\x20parts','setItem','log','YPPOG','ENOCH','enoch_token','ONAIROS','🔐\x20[JWT\x20Storage]\x20Token\x20retrieved\x20successfully','SwPry','getItem','📭\x20[JWT\x20Storage]\x20No\x20token\x20found\x20in\x20storage','⚠️\x20[JWT\x20Storage]\x20Invalid\x20JWT\x20format\x20found,\x20removing','xYjAJ','❌\x20[JWT\x20Storage]\x20Failed\x20to\x20retrieve\x20token:','LfOZq','AUTH','⚠️\x20[JWT\x20Storage]\x20replaceJWTAfterVerification\x20is\x20deprecated\x20-\x20use\x20replaceJWT()\x20instead','✅\x20[JWT\x20Storage]\x20Token\x20cleared\x20successfully','FYRlu','removeItem','zaRZF','prCsp','bZVNb','ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=','qBQZQ','xAedb','TZNcd','VRpBM','❌\x20[JWT\x20Storage]\x20Invalid\x20token\x20provided\x20for\x20replacement','charAt','aAPfd','indexOf','cZGKa','ksXZP','XZDnR','CNcwS','fromCharCode','KXory','JhAKr','⚠️\x20[JWT\x20Storage]\x20storeOnairosJWT\x20is\x20deprecated\x20-\x20use\x20storeJWT()\x20instead','📭\x20[JWT\x20Storage]\x20No\x20token\x20found\x20for\x20userId\x20extraction','⚠️\x20[JWT\x20Storage]\x20Invalid\x20JWT\x20format\x20for\x20userId\x20extraction','QikeB','⚠️\x20[JWT\x20Storage]\x20No\x20userId\x20field\x20found\x20in\x20JWT\x20payload','RDKCy','byNiB','Cdkvm','rPIgB','xJjiW','lJXOM','jPMBS','bpIQQ','FWFot','LQVsL','YVVSR','FmlAc','parse','userId','VgwEW','ZdAiP','KvBOB','aRabM','✅\x20[JWT\x20Storage]\x20Extracted\x20userId\x20from\x20JWT:','FNhSQ','❌\x20[JWT\x20Storage]\x20Failed\x20to\x20extract\x20userId\x20from\x20token:','✅\x20[JWT\x20Storage]\x20Token\x20successfully\x20replaced','qeHef','EIpty','bOLDk','pNDhI','QuUFR','Tkejy','Gzwjn','YPIlG','LEmlH','❌\x20[JWT\x20Storage]\x20Failed\x20to\x20replace\x20token:','auth_token','BBSYn','oeuNa','YVhXT','hAkUb','uGhdE','⚠️\x20[JWT\x20Storage]\x20getTokenTypeForRoute\x20is\x20deprecated\x20-\x20SDK\x20uses\x20single\x20token','QyVyz','iwnRA','flKVs','raAnR','⚠️\x20[JWT\x20Storage]\x20storeEnochJWT\x20is\x20deprecated\x20-\x20use\x20storeJWT()\x20instead','hyhZt','sTpfy','⚠️\x20[JWT\x20Storage]\x20storeAuthToken\x20is\x20deprecated\x20-\x20use\x20storeJWT()\x20instead','fxQeq','BpwMs','JqUPm'];_0x3dc8=function(){return _0x288e3b;};return _0x3dc8();}const SDK_TOKEN_KEY=_0x48ec(0x0),isValidJWTFormat=_0x2e2d6b=>{const _0x43d91c={'yDkcJ':function(_0x2fe961,_0x307dda){return _0x2fe961<_0x307dda;},'vIZwX':_0x48ec(0x1),'HIwUA':function(_0x5e0469,_0x3f5381){return _0x5e0469!==_0x3f5381;}};if(!_0x2e2d6b||_0x43d91c[_0x48ec(0x2)](_0x2e2d6b[_0x48ec(0x3)],0x14))return![];if(_0x2e2d6b[_0x48ec(0x4)]('@')&&_0x2e2d6b['includes']('.')&&!_0x2e2d6b[_0x48ec(0x4)]('Bearer')&&_0x2e2d6b[_0x48ec(0x3)]<0x64)return _0x43d91c[_0x48ec(0x5)]!==_0x48ec(0x1)?(_0x199893[_0x48ec(0x6)](_0x48ec(0x7),_0x1b3059),![]):![];const _0x30b4d3=_0x2e2d6b[_0x48ec(0x8)]('.');if(_0x43d91c['HIwUA'](_0x30b4d3[_0x48ec(0x3)],0x3))return![];if(_0x43d91c[_0x48ec(0x2)](_0x2e2d6b[_0x48ec(0x3)],0x32))return![];return!![];};export const storeJWT=async _0x12cf51=>{const _0x18c2b6={'FANbf':function(_0x216e39,_0x554219){return _0x216e39(_0x554219);},'UWLaz':'✅\x20[JWT\x20Storage]\x20Token\x20stored\x20successfully','YPPOG':_0x48ec(0x9)};try{if(!_0x12cf51||_0x12cf51['trim']()==='')return console[_0x48ec(0xa)]('⚠️\x20[JWT\x20Storage]\x20Attempted\x20to\x20store\x20empty/null\x20token'),![];if(!_0x18c2b6[_0x48ec(0xb)](isValidJWTFormat,_0x12cf51))return console[_0x48ec(0xa)](_0x48ec(0xc)),![];return await AsyncStorage[_0x48ec(0xd)](SDK_TOKEN_KEY,_0x12cf51),console[_0x48ec(0xe)](_0x18c2b6['UWLaz']),!![];}catch(_0xf3df96){return console[_0x48ec(0x6)](_0x18c2b6[_0x48ec(0xf)],_0xf3df96),![];}};export const getJWT=async()=>{const _0x438b02={'LfOZq':_0x48ec(0x10),'nTmtR':_0x48ec(0x11),'HXwDc':_0x48ec(0x12),'Dwoyy':'onairos_jwt_token','xDkpU':function(_0x1466e9,_0x2597d1){return _0x1466e9(_0x2597d1);},'xYjAJ':_0x48ec(0x13),'DWmTy':_0x48ec(0x14)};try{const _0x540fc0=await AsyncStorage[_0x48ec(0x15)](SDK_TOKEN_KEY);if(!_0x540fc0)return console['log'](_0x48ec(0x16)),null;if(!_0x438b02['xDkpU'](isValidJWTFormat,_0x540fc0))return console['warn'](_0x48ec(0x17)),await clearJWT(),null;return console[_0x48ec(0xe)](_0x438b02[_0x48ec(0x18)]),_0x540fc0;}catch(_0x4fb536){return _0x438b02['DWmTy']===_0x48ec(0x14)?(console[_0x48ec(0x6)](_0x48ec(0x19),_0x4fb536),null):(_0xfb5a59[_0x438b02[_0x48ec(0x1a)]]=_0x438b02['nTmtR'],_0x593b51[_0x438b02['HXwDc']]=_0x438b02['Dwoyy'],_0x50cd1a[_0x48ec(0x1b)]='auth_token',_0x2d6ffe);}};export const clearJWT=async()=>{const _0x346be7={'prCsp':_0x48ec(0x1c),'ZamRh':function(_0x2c8567,_0x4e0d10){return _0x2c8567(_0x4e0d10);},'FYRlu':'CJKEp','zaRZF':_0x48ec(0x1d)};try{return _0x346be7[_0x48ec(0x1e)]===_0x346be7[_0x48ec(0x1e)]?(await AsyncStorage[_0x48ec(0x1f)](SDK_TOKEN_KEY),console['log'](_0x346be7[_0x48ec(0x20)]),!![]):(_0x1de223['warn'](_0x346be7[_0x48ec(0x21)]),_0x346be7['ZamRh'](_0x5e3407,_0x4cd11c));}catch(_0x458e2a){return console[_0x48ec(0x6)](_0x48ec(0x7),_0x458e2a),![];}};function _0x48ec(_0x3dc815,_0x48ec8f){_0x3dc815=_0x3dc815-0x0;const _0x1b165f=_0x3dc8();let _0x10c6ce=_0x1b165f[_0x3dc815];return _0x10c6ce;}export const hasValidJWT=async()=>{const _0xa0bba={'bZVNb':function(_0x54ea0d,_0xa11b23){return _0x54ea0d!==_0xa11b23;}},_0x3fac65=await getJWT();return _0xa0bba[_0x48ec(0x22)](_0x3fac65,null);};const base64Decode=_0x2af607=>{const _0x36fe82={'xAedb':_0x48ec(0x23),'SOxpa':function(_0x1d552c,_0x12cab6){return _0x1d552c<_0x12cab6;},'TZNcd':function(_0x50d702,_0x2fb9a1){return _0x50d702!==_0x2fb9a1;},'VRpBM':_0x48ec(0x24),'aAPfd':function(_0x297820,_0xcc6db9){return _0x297820+_0xcc6db9;},'ToYaz':function(_0x162ecb,_0xeffdb9){return _0x162ecb+_0xeffdb9;},'ksXZP':function(_0x29531c,_0x303e2f){return _0x29531c|_0x303e2f;},'cZGKa':function(_0x272d86,_0x1637fc){return _0x272d86<<_0x1637fc;},'XZDnR':function(_0x105503,_0x40dca3){return _0x105503&_0x40dca3;},'NjHNT':function(_0x326b2f,_0x269e76){return _0x326b2f>>_0x269e76;},'CNcwS':function(_0x3767d7,_0x1f9221){return _0x3767d7<<_0x1f9221;},'KXory':function(_0x455e78,_0x494fce){return _0x455e78!==_0x494fce;},'JhAKr':function(_0x28c36f,_0x226a7c){return _0x28c36f(_0x226a7c);}},_0x4cb0f4=_0x36fe82[_0x48ec(0x25)];let _0x4bc77f='';_0x2af607=_0x2af607['replace'](/=+$/,'');for(let _0x392f55=0x0;_0x36fe82['SOxpa'](_0x392f55,_0x2af607[_0x48ec(0x3)]);_0x392f55+=0x4){if(_0x36fe82[_0x48ec(0x26)](_0x48ec(0x24),_0x36fe82[_0x48ec(0x27)]))return _0x3a5f46[_0x48ec(0x6)](_0x48ec(0x28)),![];else{const _0x3b4984=_0x4cb0f4['indexOf'](_0x2af607[_0x48ec(0x29)](_0x392f55)),_0x373d57=_0x4cb0f4['indexOf'](_0x2af607[_0x48ec(0x29)](_0x36fe82[_0x48ec(0x2a)](_0x392f55,0x1))),_0x4a3afd=_0x4cb0f4[_0x48ec(0x2b)](_0x2af607[_0x48ec(0x29)](_0x36fe82[_0x48ec(0x2a)](_0x392f55,0x2))),_0x28321a=_0x4cb0f4[_0x48ec(0x2b)](_0x2af607[_0x48ec(0x29)](_0x36fe82['ToYaz'](_0x392f55,0x3))),_0x95d074=_0x36fe82['ksXZP'](_0x36fe82[_0x48ec(0x2c)](_0x3b4984,0x2),_0x373d57>>0x4),_0x499524=_0x36fe82[_0x48ec(0x2d)](_0x36fe82[_0x48ec(0x2c)](_0x36fe82[_0x48ec(0x2e)](_0x373d57,0xf),0x4),_0x36fe82['NjHNT'](_0x4a3afd,0x2)),_0x24b03f=_0x36fe82[_0x48ec(0x2d)](_0x36fe82[_0x48ec(0x2f)](_0x36fe82[_0x48ec(0x2e)](_0x4a3afd,0x3),0x6),_0x28321a);_0x4bc77f+=String[_0x48ec(0x30)](_0x95d074);if(_0x36fe82[_0x48ec(0x26)](_0x4a3afd,0x40))_0x4bc77f+=String[_0x48ec(0x30)](_0x499524);if(_0x36fe82[_0x48ec(0x31)](_0x28321a,0x40))_0x4bc77f+=String[_0x48ec(0x30)](_0x24b03f);}}return _0x36fe82[_0x48ec(0x32)](decodeURIComponent,escape(_0x4bc77f));};export const getUserIdFromToken=async()=>{const _0x395fb7={'lJXOM':function(_0x86fd10,_0xceb0fe){return _0x86fd10+_0xceb0fe;},'jPMBS':function(_0x4a1f47,_0x54508e){return _0x4a1f47|_0x54508e;},'bpIQQ':function(_0x6f5da,_0xfec204){return _0x6f5da<<_0xfec204;},'FWFot':function(_0x41692f,_0xb0c3a6){return _0x41692f|_0xb0c3a6;},'LQVsL':function(_0x13bb9a,_0x28df67){return _0x13bb9a&_0x28df67;},'YVVSR':function(_0x55ae9c,_0x2656dd){return _0x55ae9c>>_0x2656dd;},'FmlAc':function(_0x292607,_0x16433e){return _0x292607!==_0x16433e;},'KvBOB':_0x48ec(0x33),'aRabM':function(_0x3c3a5f,_0x41dfaa){return _0x3c3a5f(_0x41dfaa);},'RDKCy':function(_0x305535){return _0x305535();},'byNiB':function(_0x12ce78,_0x15621c){return _0x12ce78===_0x15621c;},'rPIgB':'Cdkvm','xJjiW':_0x48ec(0x34),'VgwEW':function(_0xa1a596,_0x35a7df){return _0xa1a596!==_0x35a7df;},'eByBA':_0x48ec(0x35),'vWAvS':function(_0x30b14d,_0x3324dd){return _0x30b14d(_0x3324dd);},'ZdAiP':_0x48ec(0x36),'FNhSQ':_0x48ec(0x37)};try{const _0x55fee1=await _0x395fb7[_0x48ec(0x38)](getJWT);if(!_0x55fee1){if(_0x395fb7[_0x48ec(0x39)](_0x48ec(0x3a),_0x395fb7[_0x48ec(0x3b)]))return console[_0x48ec(0xe)](_0x395fb7[_0x48ec(0x3c)]),null;else{const _0x55b99b=_0x1157f9[_0x48ec(0x2b)](_0x1999ce[_0x48ec(0x29)](_0x16378a)),_0x1eff9c=_0x2eb455['indexOf'](_0x3b3746[_0x48ec(0x29)](_0xee9041+0x1)),_0x157fa4=_0x25b03a['indexOf'](_0x5bf87e[_0x48ec(0x29)](_0x395fb7[_0x48ec(0x3d)](_0x155de4,0x2))),_0xd78320=_0x4fd436[_0x48ec(0x2b)](_0x2b8b2e[_0x48ec(0x29)](_0x395fb7[_0x48ec(0x3d)](_0x37d0c5,0x3))),_0x541300=_0x395fb7[_0x48ec(0x3e)](_0x395fb7[_0x48ec(0x3f)](_0x55b99b,0x2),_0x1eff9c>>0x4),_0x51f8aa=_0x395fb7[_0x48ec(0x40)](_0x395fb7[_0x48ec(0x41)](_0x1eff9c,0xf)<<0x4,_0x395fb7[_0x48ec(0x42)](_0x157fa4,0x2)),_0x443142=_0x395fb7[_0x48ec(0x3e)](_0x395fb7[_0x48ec(0x3f)](_0x395fb7[_0x48ec(0x41)](_0x157fa4,0x3),0x6),_0xd78320);_0x58c484+=_0x535057['fromCharCode'](_0x541300);if(_0x395fb7[_0x48ec(0x43)](_0x157fa4,0x40))_0x5029bf+=_0x339c56[_0x48ec(0x30)](_0x51f8aa);if(_0x395fb7[_0x48ec(0x43)](_0xd78320,0x40))_0x3e8215+=_0x385ed2[_0x48ec(0x30)](_0x443142);}}const _0x21a390=_0x55fee1['split']('.');if(_0x395fb7['VgwEW'](_0x21a390[_0x48ec(0x3)],0x3))return console[_0x48ec(0xa)](_0x395fb7['eByBA']),null;const _0x565ed1=JSON[_0x48ec(0x44)](_0x395fb7['vWAvS'](base64Decode,_0x21a390[0x1]));if(_0x565ed1[_0x48ec(0x45)])return _0x395fb7[_0x48ec(0x46)](_0x395fb7[_0x48ec(0x47)],_0x395fb7[_0x48ec(0x47)])?(_0x15826a[_0x48ec(0xa)](_0x395fb7[_0x48ec(0x48)]),_0x395fb7[_0x48ec(0x49)](_0x2f8c06,_0x4ddcd6)):(console[_0x48ec(0xe)](_0x48ec(0x4a),_0x565ed1[_0x48ec(0x45)]),_0x565ed1[_0x48ec(0x45)]);return console[_0x48ec(0xa)](_0x395fb7[_0x48ec(0x4b)]),null;}catch(_0x4f8f02){return console[_0x48ec(0x6)](_0x48ec(0x4c),_0x4f8f02),null;}};export const replaceJWT=async _0x3bede4=>{const _0x367e36={'pNDhI':_0x48ec(0x35),'vdUYB':function(_0x24ad6e,_0x2e5a89){return _0x24ad6e===_0x2e5a89;},'EIpty':'iEMxd','bOLDk':'UJnZd','QuUFR':function(_0x277c5e,_0x2341e7){return _0x277c5e(_0x2341e7);},'Tkejy':'❌\x20[JWT\x20Storage]\x20Invalid\x20token\x20provided\x20for\x20replacement','bnReA':function(_0x59e603,_0x44d32a){return _0x59e603(_0x44d32a);},'Gzwjn':_0x48ec(0x4d),'YPIlG':'axWoL','LEmlH':_0x48ec(0x4e)};try{if(_0x367e36['vdUYB'](_0x367e36[_0x48ec(0x4f)],_0x367e36[_0x48ec(0x50)]))return _0x155003[_0x48ec(0xa)](_0x367e36[_0x48ec(0x51)]),null;else{if(!_0x3bede4||!_0x367e36[_0x48ec(0x52)](isValidJWTFormat,_0x3bede4))return console[_0x48ec(0x6)](_0x367e36[_0x48ec(0x53)]),![];await clearJWT();const _0x1e032d=await _0x367e36['bnReA'](storeJWT,_0x3bede4);return _0x1e032d&&console[_0x48ec(0xe)](_0x367e36[_0x48ec(0x54)]),_0x1e032d;}}catch(_0x448a40){return _0x367e36[_0x48ec(0x55)]!==_0x367e36[_0x48ec(0x56)]?(console[_0x48ec(0x6)](_0x48ec(0x57),_0x448a40),![]):(_0x4d650f[_0x48ec(0x6)]('❌\x20[JWT\x20Storage]\x20Failed\x20to\x20store\x20token:',_0x1178a2),![]);}};export let TokenType=function(_0x5e2fa8){const _0x2b122c={'BBSYn':_0x48ec(0x10),'oeuNa':_0x48ec(0x11),'YVhXT':'ONAIROS','hAkUb':_0x48ec(0x1b),'uGhdE':_0x48ec(0x58)};return _0x5e2fa8[_0x2b122c[_0x48ec(0x59)]]=_0x2b122c[_0x48ec(0x5a)],_0x5e2fa8[_0x2b122c[_0x48ec(0x5b)]]='onairos_jwt_token',_0x5e2fa8[_0x2b122c[_0x48ec(0x5c)]]=_0x2b122c[_0x48ec(0x5d)],_0x5e2fa8;}({});export const getTokenTypeForRoute=_0x1d32eb=>{const _0x55adbf={'QyVyz':_0x48ec(0x5e)};return console[_0x48ec(0xa)](_0x55adbf[_0x48ec(0x5f)]),TokenType[_0x48ec(0x1b)];};export const getJWTForRoute=async _0x2206b8=>{const _0x58165a={'iwnRA':'⚠️\x20[JWT\x20Storage]\x20getJWTForRoute\x20is\x20deprecated\x20-\x20use\x20getJWT()\x20instead'};return console[_0x48ec(0xa)](_0x58165a[_0x48ec(0x60)]),getJWT();};export const clearAllJWT=async()=>{const _0x234d25={'flKVs':'⚠️\x20[JWT\x20Storage]\x20clearAllJWT\x20is\x20deprecated\x20-\x20use\x20clearJWT()\x20instead','raAnR':function(_0xd20fec){return _0xd20fec();}};return console['warn'](_0x234d25[_0x48ec(0x61)]),_0x234d25[_0x48ec(0x62)](clearJWT);};export const storeEnochJWT=async _0x3d48f5=>{const _0x53ad53={'hyhZt':_0x48ec(0x63),'jboAR':function(_0xad3ea9,_0x406f9b){return _0xad3ea9(_0x406f9b);}};return console[_0x48ec(0xa)](_0x53ad53[_0x48ec(0x64)]),_0x53ad53['jboAR'](storeJWT,_0x3d48f5);};export const storeOnairosJWT=async _0x3b6fd6=>{const _0x4419c2={'sTpfy':_0x48ec(0x33)};return console[_0x48ec(0xa)](_0x4419c2[_0x48ec(0x65)]),storeJWT(_0x3b6fd6);};export const storeAuthToken=async _0x17c212=>{const _0x28b557={'fxQeq':_0x48ec(0x66)};return console[_0x48ec(0xa)](_0x28b557[_0x48ec(0x67)]),storeJWT(_0x17c212);};export const replaceJWTAfterVerification=async(_0x12b849,_0x37cb0a)=>{const _0x23697a={'BpwMs':_0x48ec(0x1c)};return console[_0x48ec(0xa)](_0x23697a[_0x48ec(0x68)]),replaceJWT(_0x37cb0a);};export const getAllTokens=async()=>{const _0x1e731f={'JqUPm':function(_0x56e16c){return _0x56e16c();}},_0x1a8a2a=await _0x1e731f[_0x48ec(0x69)](getJWT);return{'sdk_token':_0x1a8a2a,[TokenType[_0x48ec(0x10)]]:null,[TokenType[_0x48ec(0x12)]]:null,[TokenType['AUTH']]: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
|