@onairosofficial/onairos-capacitor 0.1.0 → 0.1.2
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/CAPACITOR_QUICK_START.md +379 -0
- package/CONNECTORS.md +122 -0
- package/LICENSE +194 -10
- package/OnairosofficialOnairosCapacitor.podspec +13 -0
- package/Package.swift +26 -0
- package/README.md +176 -25
- package/dist/onairos.capacitor.esm.js +1 -0
- package/dist/onairos.capacitor.esm.turbopack.js +1 -0
- package/docs/CAPACITOR_INTEGRATION_GUIDE.md +159 -0
- package/docs/CAPACITOR_MOCK_APP_TESTING.md +213 -0
- package/docs/CAPACITOR_SDK_FIXES_SUMMARY.md +65 -0
- package/docs/CROSS_SDK_PARITY.md +239 -0
- package/docs/DATA_FREQUENCY.md +57 -0
- package/docs/DEVELOPER_SDK_CHANGES.md +532 -0
- package/docs/INCIDENT_ENABLETRAINING_PIN_WEB_8.1.9.md +82 -0
- package/docs/ONAIROS_BUTTON_PROPS.md +152 -0
- package/docs/PLATFORM_APIS.md +559 -0
- package/docs/RAW_MEMORIES_API.md +305 -0
- package/docs/RAW_MEMORIES_SDK_UPDATE.md +54 -0
- package/docs/SDK_PARITY_ROLLUP_2026_04_24_to_05_02.md +96 -0
- package/docs/oldFixes.md +216 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosChatGPTNativePlugin.swift +993 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosNetflixNativePlugin.swift +33 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosSpotifyNativePlugin.swift +1082 -0
- package/onairos.d.ts +656 -0
- package/package.json +188 -37
- package/src/OnairosReconnectButton.jsx +272 -0
- package/src/RSA.jsx +57 -0
- package/src/assets/NewLogo.png +0 -0
- package/src/assets/OnairosNewLogo.png +0 -0
- package/src/assets/chatgpt-icon.png +0 -0
- package/src/assets/fire-horse.png +0 -0
- package/src/assets/fire-horse.transparent.png +0 -0
- package/src/assets/latest-firehorse.png +0 -0
- package/src/assets/perplexity.png +0 -0
- package/src/assets/persona.png +0 -0
- package/src/assets/persona1.png +0 -0
- package/src/assets/persona2.png +0 -0
- package/src/assets/persona3.png +0 -0
- package/src/assets/persona4.png +0 -0
- package/src/assets/persona5.png +0 -0
- package/src/capacitorConnectorCatalog.js +38 -0
- package/src/capacitorOAuthConfig.js +52 -0
- package/src/chatgptHostedImport/index.js +303 -0
- package/src/components/AuthButtons.jsx +48 -0
- package/src/components/ConnectChatGPTModal.jsx +666 -0
- package/src/components/ConnectClaudeModal.jsx +610 -0
- package/src/components/ConnectGeminiModal.jsx +639 -0
- package/src/components/ConnectGrokModal.jsx +701 -0
- package/src/components/ConnectPerplexityModal.jsx +726 -0
- package/src/components/DataExplainerScreen.jsx +349 -0
- package/src/components/DataRequest.js +885 -0
- package/src/components/DataRequest.jsx +1055 -0
- package/src/components/EmailAuth.js +1871 -0
- package/src/components/EmailAuth.jsx +2062 -0
- package/src/components/ExtensionInstallPrompt.jsx +142 -0
- package/src/components/GoogleButton.js +133 -0
- package/src/components/LLMConnectorManager.jsx +201 -0
- package/src/components/LoadingPage.jsx +19 -0
- package/src/components/LoadingScreen.jsx +81 -0
- package/src/components/LunarBirthdate.jsx +96 -0
- package/src/components/LunarLoadingPage.jsx +251 -0
- package/src/components/Notification.jsx +21 -0
- package/src/components/OnairosAppButton.jsx +85 -0
- package/src/components/OnairosSSO.jsx +645 -0
- package/src/components/OnairosTrigger.jsx +61 -0
- package/src/components/PerplexityLogo.jsx +43 -0
- package/src/components/PinSetup.js +200 -0
- package/src/components/PinSetup.jsx +228 -0
- package/src/components/SDK_PIN_INTEGRATION_REQUIRED_CHANGES.md +526 -0
- package/src/components/SdkErrorBoundary.jsx +36 -0
- package/src/components/SecuritySetup.js +81 -0
- package/src/components/SessionUserBar.jsx +83 -0
- package/src/components/SignUp.js +123 -0
- package/src/components/TestTelegramButton.js +53 -0
- package/src/components/TrainingComponent.jsx +200 -0
- package/src/components/TrainingScreen.jsx +897 -0
- package/src/components/UniversalOnboarding.js +306 -0
- package/src/components/UniversalOnboarding.jsx +4837 -0
- package/src/components/ValentineLoadingPage.jsx +502 -0
- package/src/components/ValentineModeSelector.jsx +162 -0
- package/src/components/WelcomeScreen.jsx +435 -0
- package/src/components/WrappedLoadingPage.jsx +205 -0
- package/src/components/connectors/ChatGPTConnector.js +348 -0
- package/src/components/connectors/ChatGPTConnector.jsx +348 -0
- package/src/components/connectors/ClaudeConnector.js +44 -0
- package/src/components/connectors/ClaudeConnector.jsx +44 -0
- package/src/components/connectors/GeminiConnector.js +170 -0
- package/src/components/connectors/GeminiConnector.jsx +170 -0
- package/src/components/connectors/GmailConnector.js +148 -0
- package/src/components/connectors/GmailConnector.jsx +148 -0
- package/src/components/connectors/GrokConnector.js +16 -0
- package/src/components/connectors/GrokConnector.jsx +16 -0
- package/src/components/connectors/HingeConnector.js +419 -0
- package/src/components/connectors/HingeConnector.jsx +419 -0
- package/src/components/connectors/InstagramDataConnector.js +726 -0
- package/src/components/connectors/InstagramDataConnector.jsx +726 -0
- package/src/components/connectors/LinkedInConnector.js +4 -0
- package/src/components/connectors/LinkedInConnector.jsx +296 -0
- package/src/components/connectors/PerplexityConnector.jsx +16 -0
- package/src/components/connectors/PinterestConnector.js +208 -0
- package/src/components/connectors/PinterestConnector.jsx +208 -0
- package/src/components/connectors/README.md +292 -0
- package/src/components/connectors/RedditConnector.js +229 -0
- package/src/components/connectors/RedditConnector.jsx +229 -0
- package/src/components/connectors/SephoraConnector.js +482 -0
- package/src/components/connectors/SephoraConnector.jsx +482 -0
- package/src/components/connectors/TikTokConnector.jsx +430 -0
- package/src/components/connectors/YoutubeConnector.js +361 -0
- package/src/components/connectors/YoutubeConnector.jsx +361 -0
- package/src/components/connectors/index.js +50 -0
- package/src/components/icons.jsx +46 -0
- package/src/components/icons.tsx +21 -0
- package/src/components/ui/PageLayout.jsx +1255 -0
- package/src/components/ui/PrimaryButton.jsx +162 -0
- package/src/components/ui/button.jsx +49 -0
- package/src/components/ui/card.jsx +61 -0
- package/src/components/ui/checkbox.jsx +33 -0
- package/src/components/ui/label.jsx +29 -0
- package/src/components/utils/UpdateConnections.js +45 -0
- package/src/components/utils/oauthHelper.js +97 -0
- package/src/config/api-config.js +138 -0
- package/src/deepLink.jsx +38 -0
- package/src/getPin.js +26 -0
- package/src/icons/Avatar.png +0 -0
- package/src/icons/Sentiment.png +0 -0
- package/src/icons/Trait.png +0 -0
- package/src/iframe/DataRequestPage.jsx +285 -0
- package/src/iframe/OnairosButtonIntegration.md +148 -0
- package/src/iframe/components/Box.jsx +56 -0
- package/src/iframe/components/IndividualConnection.jsx +88 -0
- package/src/iframe/dataRequestHandler.js +714 -0
- package/src/iframe/data_request_iframe.html +27 -0
- package/src/iframe/data_request_page.js +47 -0
- package/src/iframe/icons/Avatar.png +1 -0
- package/src/iframe/icons/Avatar2.png +1 -0
- package/src/iframe/icons/Sentiment.png +1 -0
- package/src/iframe/icons/Trait.png +1 -0
- package/src/iframe/icons/onairos_logo.png +0 -0
- package/src/iframe/utils/api.js +57 -0
- package/src/index.js +274 -0
- package/src/laravel/OnairosVue.vue +410 -0
- package/src/laravel/blade-helpers.js +320 -0
- package/src/laravel/vite-plugin.js +179 -0
- package/src/mobile/MobileDataRequestPage.jsx +233 -0
- package/src/mobile/components/MobileBox.jsx +71 -0
- package/src/mobile/components/MobileIndividualConnection.jsx +51 -0
- package/src/mobile/shims/browser-apis.js +78 -0
- package/src/mobile/shims/lucide-shim.js +85 -0
- package/src/nativeConnectors.js +5 -0
- package/src/newUI/EMAIL_VERIFICATION_API_SCHEMA.md +268 -0
- package/src/newUI/PlatformConnectorsStep.tsx +435 -0
- package/src/newUI/PrimaryButton.tsx +213 -0
- package/src/newUI/SignInStep.tsx +194 -0
- package/src/newUI/VerificationStep.tsx +133 -0
- package/src/newUI/WelcomeScreen.tsx +311 -0
- package/src/newUI/services/connectedAccountsService.js +129 -0
- package/src/onairos.capacitor.jsx +15 -0
- package/src/onairos.core.jsx +133 -0
- package/src/onairos.jsx +14 -0
- package/src/onairos.native.jsx +15 -0
- package/src/onairosButton.jsx +9000 -0
- package/src/overlay/CheckBox.jsx +114 -0
- package/src/overlay/IndividualConnection copy.js +86 -0
- package/src/overlay/IndividualConnection.js +191 -0
- package/src/overlay/IndividualConnectionNew.jsx +157 -0
- package/src/overlay/box.js +84 -0
- package/src/overlay/overlay.js +437 -0
- package/src/styles/onairos-scoped-preflight.css +97 -0
- package/src/styles/sdkCssRegistry.js +20 -0
- package/src/styles/styleLoaderInsertShadow.js +69 -0
- package/src/styles/tailwind.capacitor.css +395 -0
- package/src/styles/tailwind.css +395 -0
- package/src/theme/colors.js +40 -0
- package/src/utils/apiKeyValidation.js +341 -0
- package/src/utils/apiResponseLogger.js +316 -0
- package/src/utils/authHeaders.js +275 -0
- package/src/utils/biometrics.js +26 -0
- package/src/utils/bookmarkletUtils.js +28 -0
- package/src/utils/capacitorDetection.js +278 -0
- package/src/utils/capacitorLLMHelper.js +352 -0
- package/src/utils/capacitorPlugins.js +366 -0
- package/src/utils/crossDomainSSO.js +587 -0
- package/src/utils/deepLinking.js +27 -0
- package/src/utils/devLogger.js +46 -0
- package/src/utils/extensionDetection.js +418 -0
- package/src/utils/extractMemory.js +277 -0
- package/src/utils/framerBrandingOverrides.js +40 -0
- package/src/utils/googleWebClientId.js +55 -0
- package/src/utils/overlayHandler.js +224 -0
- package/src/utils/platformDisconnect.js +309 -0
- package/src/utils/pollTrainingStatus.js +200 -0
- package/src/utils/rawMemoriesAccess.js +211 -0
- package/src/utils/resolveBackendAppId.js +47 -0
- package/src/utils/responseFormatter.js +140 -0
- package/src/utils/sdkDebugStorage.js +113 -0
- package/src/utils/sdkInitialization.js +645 -0
- package/src/utils/sessionManager.js +1258 -0
- package/src/utils/startBackgroundTraining.js +100 -0
- package/src/utils/userDataFormatter.js +222 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data Request Popup Handler
|
|
3
|
+
* This module manages the creation and display of the data request popup window
|
|
4
|
+
* that properly displays without being cut off.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getApiBaseUrl } from '../config/api-config.js';
|
|
8
|
+
import { getRequiredUserAuthHeaders, handleUnauthorizedResponse, getUserToken } from '../utils/authHeaders.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Gets the URL for the popup HTML file
|
|
12
|
+
* Works in both extension and web contexts
|
|
13
|
+
*/
|
|
14
|
+
function getPopupUrl() {
|
|
15
|
+
if (typeof chrome !== 'undefined' && chrome.runtime) {
|
|
16
|
+
return chrome.runtime.getURL('data_request_popup.html');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// For web context, try multiple possible paths
|
|
20
|
+
const baseUrl = window.location.origin;
|
|
21
|
+
const isNextJs = typeof window !== 'undefined' && window.__NEXT_DATA__;
|
|
22
|
+
|
|
23
|
+
if (isNextJs) {
|
|
24
|
+
// In Next.js, use the _next/static path
|
|
25
|
+
return `${baseUrl}/_next/static/data_request_popup.html`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// For npm package usage, try to find the popup file in common locations
|
|
29
|
+
const possiblePaths = [
|
|
30
|
+
`${baseUrl}/node_modules/onairos/dist/data_request_popup.html`,
|
|
31
|
+
`${baseUrl}/static/data_request_popup.html`,
|
|
32
|
+
`${baseUrl}/public/data_request_popup.html`,
|
|
33
|
+
`${baseUrl}/data_request_popup.html`
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
// Return the first path (most likely for npm package usage)
|
|
37
|
+
return possiblePaths[0];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates popup content dynamically as fallback
|
|
42
|
+
*/
|
|
43
|
+
function createDynamicPopupContent(data) {
|
|
44
|
+
const { requestData = [], webpageName = 'App', userData = {}, autoFetch = false, testMode = false, appIcon = null } = data;
|
|
45
|
+
|
|
46
|
+
const defaultDataTypes = [
|
|
47
|
+
{ id: 'basic', name: 'Basic Info', description: 'Essential profile information and account details', icon: '👤' },
|
|
48
|
+
{ id: 'personality', name: 'Personality', description: 'Personality traits, behavioral patterns and insights', icon: '🧠' },
|
|
49
|
+
{ id: 'preferences', name: 'Preferences', description: 'User preferences, settings and choices', icon: '⚙️' }
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
const dataTypes = Array.isArray(requestData) && requestData.length > 0
|
|
53
|
+
? requestData.map(id => defaultDataTypes.find(dt => dt.id === id) || { id, name: id, description: `${id} data`, icon: '📋' })
|
|
54
|
+
: defaultDataTypes;
|
|
55
|
+
|
|
56
|
+
return `
|
|
57
|
+
<!DOCTYPE html>
|
|
58
|
+
<html lang="en">
|
|
59
|
+
<head>
|
|
60
|
+
<meta charset="UTF-8">
|
|
61
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
62
|
+
<title>Onairos Data Request</title>
|
|
63
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
64
|
+
<style>
|
|
65
|
+
body {
|
|
66
|
+
margin: 0;
|
|
67
|
+
padding: 0;
|
|
68
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
|
69
|
+
background-color: #f9fafb;
|
|
70
|
+
height: 100vh;
|
|
71
|
+
overflow: hidden;
|
|
72
|
+
}
|
|
73
|
+
.min-h-screen {
|
|
74
|
+
min-height: 100vh;
|
|
75
|
+
max-height: 100vh;
|
|
76
|
+
}
|
|
77
|
+
.flex-1 {
|
|
78
|
+
flex: 1;
|
|
79
|
+
}
|
|
80
|
+
.mt-auto {
|
|
81
|
+
margin-top: auto;
|
|
82
|
+
}
|
|
83
|
+
.flex-shrink-0 {
|
|
84
|
+
flex-shrink: 0;
|
|
85
|
+
}
|
|
86
|
+
</style>
|
|
87
|
+
</head>
|
|
88
|
+
<body>
|
|
89
|
+
<div class="min-h-screen bg-gray-50 py-4 px-4 flex flex-col">
|
|
90
|
+
<div class="max-w-md mx-auto bg-white rounded-lg shadow-lg flex flex-col flex-1">
|
|
91
|
+
<div class="p-4 flex-1 flex flex-col">
|
|
92
|
+
<div class="text-center mb-6">
|
|
93
|
+
<div class="flex items-center justify-center space-x-2 mb-4">
|
|
94
|
+
<img src="https://onairos.sirv.com/Images/OnairosBlack.png" alt="Onairos Logo" class="w-8 h-8">
|
|
95
|
+
<div class="text-gray-400 mx-2">→</div>
|
|
96
|
+
${appIcon ? `<img src="${appIcon}" alt="${webpageName} Logo" class="w-8 h-8 rounded-full">` :
|
|
97
|
+
`<div class="w-8 h-8 bg-gray-200 rounded-full flex items-center justify-center"><span class="text-gray-600 text-xs font-bold">${webpageName.charAt(0)}</span></div>`}
|
|
98
|
+
</div>
|
|
99
|
+
<h2 class="text-2xl font-bold text-gray-900 mb-2">Data Request</h2>
|
|
100
|
+
<p class="text-gray-600">${webpageName} is requesting access to your data</p>
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<div class="space-y-3 mb-4 flex-1" id="dataTypes">
|
|
104
|
+
${dataTypes.map(type => `
|
|
105
|
+
<label class="group relative flex items-start p-4 border-2 border-gray-200 rounded-xl cursor-pointer hover:border-blue-300 hover:bg-blue-50 transition-all duration-200 shadow-sm hover:shadow-md data-option">
|
|
106
|
+
<div class="flex items-center h-5">
|
|
107
|
+
<input type="checkbox" class="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500 focus:ring-2" data-id="${type.id}">
|
|
108
|
+
</div>
|
|
109
|
+
<div class="ml-4 flex-1">
|
|
110
|
+
<div class="flex items-center mb-2">
|
|
111
|
+
<span class="text-2xl mr-3 group-hover:scale-110 transition-transform duration-200">${type.icon}</span>
|
|
112
|
+
<span class="font-semibold text-gray-900 text-lg">${type.name}</span>
|
|
113
|
+
</div>
|
|
114
|
+
<p class="text-sm text-gray-600 leading-relaxed">${type.description}</p>
|
|
115
|
+
</div>
|
|
116
|
+
<div class="absolute top-4 right-4 w-6 h-6 border-2 rounded-md transition-all duration-200 bg-white checkbox-visual" data-for="${type.id}">
|
|
117
|
+
<svg class="w-4 h-4 text-white checkmark-icon" fill="currentColor" viewBox="0 0 20 20">
|
|
118
|
+
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"></path>
|
|
119
|
+
</svg>
|
|
120
|
+
</div>
|
|
121
|
+
</label>
|
|
122
|
+
`).join('')}
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div class="flex space-x-3 justify-center mt-auto pt-4">
|
|
126
|
+
<button id="rejectBtn" class="px-3 py-2 border-2 border-gray-300 rounded-xl text-gray-700 font-medium hover:bg-gray-50 hover:border-gray-400 transition-all duration-200 focus:ring-2 focus:ring-gray-300 text-sm flex-shrink-0">
|
|
127
|
+
<span class="flex items-center justify-center">
|
|
128
|
+
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
129
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
|
130
|
+
</svg>
|
|
131
|
+
Decline
|
|
132
|
+
</span>
|
|
133
|
+
</button>
|
|
134
|
+
<button id="approveBtn" class="px-3 py-2 bg-gradient-to-r from-blue-600 to-blue-700 text-white rounded-xl font-medium hover:from-blue-700 hover:to-blue-800 transition-all duration-200 shadow-lg hover:shadow-xl focus:ring-2 focus:ring-blue-500 text-sm flex-shrink-0">
|
|
135
|
+
<span class="flex items-center justify-center">
|
|
136
|
+
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
137
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
|
|
138
|
+
</svg>
|
|
139
|
+
Allow Access
|
|
140
|
+
</span>
|
|
141
|
+
</button>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<div id="status" class="mt-4 text-center text-sm text-gray-600"></div>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
<style>
|
|
150
|
+
/* Enhanced checkbox styling */
|
|
151
|
+
.checkbox-visual {
|
|
152
|
+
border-color: #d1d5db;
|
|
153
|
+
}
|
|
154
|
+
.checkbox-visual.checked {
|
|
155
|
+
background-color: #2563eb;
|
|
156
|
+
border-color: #2563eb;
|
|
157
|
+
}
|
|
158
|
+
.checkbox-visual.checked .checkmark-icon {
|
|
159
|
+
opacity: 1;
|
|
160
|
+
}
|
|
161
|
+
.checkbox-visual:not(.checked) .checkmark-icon {
|
|
162
|
+
opacity: 0;
|
|
163
|
+
}
|
|
164
|
+
.data-option {
|
|
165
|
+
transition: all 0.2s ease;
|
|
166
|
+
}
|
|
167
|
+
.data-option.selected {
|
|
168
|
+
border-color: #3b82f6;
|
|
169
|
+
background-color: #eff6ff;
|
|
170
|
+
transform: translateY(-1px);
|
|
171
|
+
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
|
|
172
|
+
}
|
|
173
|
+
</style>
|
|
174
|
+
|
|
175
|
+
<script>
|
|
176
|
+
const approveBtn = document.getElementById('approveBtn');
|
|
177
|
+
const rejectBtn = document.getElementById('rejectBtn');
|
|
178
|
+
const status = document.getElementById('status');
|
|
179
|
+
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
|
|
180
|
+
|
|
181
|
+
// Update visual feedback for checkboxes
|
|
182
|
+
function updateCheckboxVisual(checkbox) {
|
|
183
|
+
const checkboxId = checkbox.dataset.id;
|
|
184
|
+
const visualCheckbox = document.querySelector('[data-for="' + checkboxId + '"]');
|
|
185
|
+
const parentLabel = checkbox.closest('label');
|
|
186
|
+
|
|
187
|
+
if (checkbox.checked) {
|
|
188
|
+
visualCheckbox?.classList.add('checked');
|
|
189
|
+
parentLabel?.classList.add('selected');
|
|
190
|
+
} else {
|
|
191
|
+
visualCheckbox?.classList.remove('checked');
|
|
192
|
+
parentLabel?.classList.remove('selected');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Add event listeners to checkboxes
|
|
197
|
+
checkboxes.forEach(checkbox => {
|
|
198
|
+
checkbox.addEventListener('change', () => updateCheckboxVisual(checkbox));
|
|
199
|
+
// Initialize visual state
|
|
200
|
+
updateCheckboxVisual(checkbox);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const autoFetch = ${autoFetch};
|
|
204
|
+
const testMode = ${testMode};
|
|
205
|
+
const userEmail = '${userData.email || ''}';
|
|
206
|
+
const appName = '${webpageName}';
|
|
207
|
+
|
|
208
|
+
// Map frontend data types to backend confirmation types
|
|
209
|
+
function mapDataTypesToConfirmations(approvedData) {
|
|
210
|
+
const confirmations = [];
|
|
211
|
+
const currentDate = new Date().toISOString();
|
|
212
|
+
|
|
213
|
+
// Map frontend types to backend types
|
|
214
|
+
const dataTypeMapping = {
|
|
215
|
+
'basic': 'Medium', // Basic info -> Medium data
|
|
216
|
+
'personality': 'Large', // Personality -> Large analysis
|
|
217
|
+
'preferences': 'Traits', // Preferences -> Traits data
|
|
218
|
+
'rawMemories': 'LLMData' // Raw memories -> LLM data
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
approvedData.forEach(dataType => {
|
|
222
|
+
if (dataTypeMapping[dataType]) {
|
|
223
|
+
confirmations.push({
|
|
224
|
+
data: dataTypeMapping[dataType],
|
|
225
|
+
date: currentDate
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
return confirmations;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Determine API endpoint based on test mode (uses env-aware base URL)
|
|
234
|
+
// Inline domain detection for popup script context
|
|
235
|
+
function getApiBaseUrlInline() {
|
|
236
|
+
if (window.onairosBaseUrl && /^https?:\/\//.test(window.onairosBaseUrl)) {
|
|
237
|
+
return window.onairosBaseUrl.replace(/\/$/, '');
|
|
238
|
+
}
|
|
239
|
+
const hostname = window.location.hostname;
|
|
240
|
+
// internship.onairos.uk -> api2.onairos.uk
|
|
241
|
+
if (hostname === 'internship.onairos.uk') {
|
|
242
|
+
return 'https://api2.onairos.uk';
|
|
243
|
+
}
|
|
244
|
+
// Default to production
|
|
245
|
+
return 'https://api2.onairos.uk';
|
|
246
|
+
}
|
|
247
|
+
const apiBase = getApiBaseUrlInline();
|
|
248
|
+
const apiEndpoint = testMode
|
|
249
|
+
? apiBase + '/inferenceTest'
|
|
250
|
+
: apiBase + '/getAPIurlMobile';
|
|
251
|
+
|
|
252
|
+
function resolveUserToken() {
|
|
253
|
+
try {
|
|
254
|
+
const direct = localStorage.getItem('onairos_user_token');
|
|
255
|
+
if (direct) return direct;
|
|
256
|
+
const rawUser = localStorage.getItem('onairosUser');
|
|
257
|
+
if (!rawUser) return null;
|
|
258
|
+
const parsed = JSON.parse(rawUser);
|
|
259
|
+
return parsed?.token || parsed?.jwtToken || null;
|
|
260
|
+
} catch (_) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function makeApiCall(approvedData) {
|
|
266
|
+
const confirmations = mapDataTypesToConfirmations(approvedData);
|
|
267
|
+
|
|
268
|
+
// Format request according to backend expectations
|
|
269
|
+
// PIN is stored on backend via /store-pin/mobile - no need to send placeholder
|
|
270
|
+
const requestBody = testMode ? {
|
|
271
|
+
// Test mode: simple format for testing
|
|
272
|
+
approvedData,
|
|
273
|
+
userEmail,
|
|
274
|
+
appName,
|
|
275
|
+
timestamp: new Date().toISOString(),
|
|
276
|
+
testMode: testMode
|
|
277
|
+
} : {
|
|
278
|
+
// Live mode: proper Info format for backend
|
|
279
|
+
Info: {
|
|
280
|
+
storage: "local",
|
|
281
|
+
appId: appName,
|
|
282
|
+
confirmations: confirmations,
|
|
283
|
+
account: userEmail,
|
|
284
|
+
proofMode: false,
|
|
285
|
+
Domain: window.location.hostname,
|
|
286
|
+
web3Type: "standard",
|
|
287
|
+
OthentSub: null
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const userToken = resolveUserToken();
|
|
292
|
+
if (!userToken) {
|
|
293
|
+
throw new Error('Authentication required. Please log in again before requesting data.');
|
|
294
|
+
}
|
|
295
|
+
const response = await fetch(apiEndpoint, {
|
|
296
|
+
method: 'POST',
|
|
297
|
+
headers: {
|
|
298
|
+
'Content-Type': 'application/json',
|
|
299
|
+
'Authorization': 'Bearer ' + userToken
|
|
300
|
+
},
|
|
301
|
+
body: JSON.stringify(requestBody)
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
if (response.status === 401) {
|
|
305
|
+
try { localStorage.removeItem('onairos_user_token'); } catch (_) {}
|
|
306
|
+
throw new Error('Authentication expired. Please log in again.');
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (!response.ok) {
|
|
310
|
+
throw new Error('API call failed with status: ' + response.status);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const data = await response.json();
|
|
314
|
+
|
|
315
|
+
// Format response according to test mode requirements
|
|
316
|
+
if (testMode && data) {
|
|
317
|
+
return {
|
|
318
|
+
InferenceResult: {
|
|
319
|
+
output: data.croppedInference || data.output || data.inference,
|
|
320
|
+
traits: data.traitResult || data.traits || data.personalityData
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return data;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
approveBtn.addEventListener('click', async () => {
|
|
329
|
+
const approved = Array.from(checkboxes)
|
|
330
|
+
.filter(cb => cb.checked)
|
|
331
|
+
.map(cb => cb.dataset.id);
|
|
332
|
+
|
|
333
|
+
if (approved.length === 0) {
|
|
334
|
+
alert('Please select at least one data type to continue.');
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
approveBtn.disabled = true;
|
|
339
|
+
status.textContent = 'Processing...';
|
|
340
|
+
|
|
341
|
+
const baseResult = {
|
|
342
|
+
type: 'dataRequestComplete',
|
|
343
|
+
source: 'onairosPopup',
|
|
344
|
+
approved: approved,
|
|
345
|
+
timestamp: new Date().toISOString(),
|
|
346
|
+
userEmail: userEmail,
|
|
347
|
+
appName: appName,
|
|
348
|
+
testMode: testMode
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
let finalResult = baseResult;
|
|
352
|
+
|
|
353
|
+
if (autoFetch) {
|
|
354
|
+
// Auto mode true: make API request and return results
|
|
355
|
+
try {
|
|
356
|
+
status.textContent = 'Making API call...';
|
|
357
|
+
const apiData = await makeApiCall(approved);
|
|
358
|
+
finalResult = {
|
|
359
|
+
...baseResult,
|
|
360
|
+
apiResponse: apiData,
|
|
361
|
+
apiUrl: apiEndpoint,
|
|
362
|
+
success: true
|
|
363
|
+
};
|
|
364
|
+
} catch (error) {
|
|
365
|
+
finalResult = {
|
|
366
|
+
...baseResult,
|
|
367
|
+
apiError: error.message,
|
|
368
|
+
apiUrl: apiEndpoint,
|
|
369
|
+
success: false
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
// Auto mode false (default): return API endpoint URL for manual calling
|
|
374
|
+
finalResult = {
|
|
375
|
+
...baseResult,
|
|
376
|
+
apiUrl: apiEndpoint,
|
|
377
|
+
success: true,
|
|
378
|
+
message: 'Data request approved. Use the provided API URL to fetch user data.'
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
window.opener.postMessage(finalResult, '*');
|
|
383
|
+
setTimeout(() => window.close(), 1000);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
rejectBtn.addEventListener('click', () => {
|
|
387
|
+
window.opener.postMessage({
|
|
388
|
+
type: 'dataRequestComplete',
|
|
389
|
+
source: 'onairosPopup',
|
|
390
|
+
approved: false,
|
|
391
|
+
dataTypes: [],
|
|
392
|
+
timestamp: new Date().toISOString(),
|
|
393
|
+
userEmail: userEmail,
|
|
394
|
+
appName: appName
|
|
395
|
+
}, '*');
|
|
396
|
+
window.close();
|
|
397
|
+
});
|
|
398
|
+
</script>
|
|
399
|
+
</body>
|
|
400
|
+
</html>`;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Opens a data request popup window positioned optimally on screen
|
|
405
|
+
* @param {Object} data - Initial data to send to the popup
|
|
406
|
+
* @returns {Window|null} The opened window or null if failed
|
|
407
|
+
*/
|
|
408
|
+
export function openDataRequestPopup(data = {}) {
|
|
409
|
+
try {
|
|
410
|
+
const popupUrl = getPopupUrl();
|
|
411
|
+
console.log('🔥 Opening popup with URL:', popupUrl);
|
|
412
|
+
|
|
413
|
+
// Calculate optimal position - center but avoid being cut off
|
|
414
|
+
const width = 450;
|
|
415
|
+
const height = 700;
|
|
416
|
+
const screenWidth = window.screen.availWidth;
|
|
417
|
+
const screenHeight = window.screen.availHeight;
|
|
418
|
+
|
|
419
|
+
// Ensure popup fits within screen bounds
|
|
420
|
+
const left = Math.max(0, (screenWidth - width) / 2);
|
|
421
|
+
const top = Math.max(0, (screenHeight - height) / 2);
|
|
422
|
+
|
|
423
|
+
// Try to open popup with HTML file first
|
|
424
|
+
let popupWindow = window.open(
|
|
425
|
+
popupUrl,
|
|
426
|
+
'OnairosDataRequest',
|
|
427
|
+
`width=${width},height=${height},top=${top},left=${left},resizable=yes,scrollbars=yes,status=no,location=no,toolbar=no,menubar=no`
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
if (!popupWindow) {
|
|
431
|
+
throw new Error('Failed to open popup - popup blocked');
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// Check if popup loaded successfully, if not use fallback
|
|
435
|
+
const checkPopupLoaded = () => {
|
|
436
|
+
try {
|
|
437
|
+
// Try to access popup document
|
|
438
|
+
if (popupWindow.document && popupWindow.document.readyState === 'complete') {
|
|
439
|
+
// Popup loaded successfully, send data
|
|
440
|
+
if (data && Object.keys(data).length > 0) {
|
|
441
|
+
console.log('🔥 Sending data to popup:', data);
|
|
442
|
+
sendDataToPopup(popupWindow, data);
|
|
443
|
+
}
|
|
444
|
+
} else {
|
|
445
|
+
setTimeout(checkPopupLoaded, 100);
|
|
446
|
+
}
|
|
447
|
+
} catch (error) {
|
|
448
|
+
// Cross-origin or loading error, use fallback
|
|
449
|
+
console.log('🔥 Popup loading failed, using dynamic content fallback');
|
|
450
|
+
useDynamicPopupFallback(popupWindow, data);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
// Start checking if popup loaded
|
|
455
|
+
setTimeout(checkPopupLoaded, 500);
|
|
456
|
+
|
|
457
|
+
// Ensure popup is brought to focus
|
|
458
|
+
popupWindow.focus();
|
|
459
|
+
|
|
460
|
+
return popupWindow;
|
|
461
|
+
} catch (error) {
|
|
462
|
+
console.error('Error opening popup:', error);
|
|
463
|
+
// Show user-friendly error message
|
|
464
|
+
alert('Unable to open Onairos popup. Please ensure popups are allowed for this site.');
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Fallback method to create popup content dynamically
|
|
471
|
+
*/
|
|
472
|
+
function useDynamicPopupFallback(popupWindow, data) {
|
|
473
|
+
try {
|
|
474
|
+
const dynamicContent = createDynamicPopupContent(data);
|
|
475
|
+
popupWindow.document.open();
|
|
476
|
+
popupWindow.document.write(dynamicContent);
|
|
477
|
+
popupWindow.document.close();
|
|
478
|
+
console.log('🔥 Dynamic popup content created successfully');
|
|
479
|
+
} catch (error) {
|
|
480
|
+
console.error('🔥 Failed to create dynamic popup content:', error);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Closes the data request popup window if it's open
|
|
486
|
+
* @param {Window} windowRef - Reference to the window object returned by openDataRequestPopup
|
|
487
|
+
*/
|
|
488
|
+
export function closeDataRequestPopup(windowRef) {
|
|
489
|
+
if (windowRef && !windowRef.closed) {
|
|
490
|
+
try {
|
|
491
|
+
windowRef.close();
|
|
492
|
+
window.postMessage({ action: 'popupClosed' }, '*');
|
|
493
|
+
} catch (error) {
|
|
494
|
+
console.error('Error closing popup:', error);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Send data to the popup window with timeout and retry logic
|
|
501
|
+
* @param {Window} windowRef - Reference to the window object
|
|
502
|
+
* @param {Object} data - Data to send to the popup
|
|
503
|
+
* @returns {Promise} Promise that resolves when data is sent or rejects on timeout
|
|
504
|
+
*/
|
|
505
|
+
export function sendDataToPopup(windowRef, data) {
|
|
506
|
+
return new Promise((resolve, reject) => {
|
|
507
|
+
if (!windowRef || windowRef.closed) {
|
|
508
|
+
reject(new Error('Popup window is not available'));
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
let retries = 0;
|
|
513
|
+
const maxRetries = 3;
|
|
514
|
+
|
|
515
|
+
const sendWithRetry = () => {
|
|
516
|
+
try {
|
|
517
|
+
console.log('🔥 Sending message to popup:', { type: 'dataRequest', ...data });
|
|
518
|
+
windowRef.postMessage({
|
|
519
|
+
type: 'dataRequest',
|
|
520
|
+
...data,
|
|
521
|
+
timestamp: Date.now()
|
|
522
|
+
}, '*');
|
|
523
|
+
|
|
524
|
+
// Set timeout for response
|
|
525
|
+
const timeout = setTimeout(() => {
|
|
526
|
+
if (retries < maxRetries) {
|
|
527
|
+
retries++;
|
|
528
|
+
console.log(`🔥 Retrying send (attempt ${retries})`);
|
|
529
|
+
sendWithRetry();
|
|
530
|
+
} else {
|
|
531
|
+
console.log('🔥 Timeout waiting for popup response');
|
|
532
|
+
reject(new Error('Timeout waiting for popup response'));
|
|
533
|
+
}
|
|
534
|
+
}, 2000);
|
|
535
|
+
|
|
536
|
+
// Listen for acknowledgment
|
|
537
|
+
const messageHandler = (event) => {
|
|
538
|
+
if (event.data && event.data.action === 'dataReceived') {
|
|
539
|
+
console.log('🔥 Received acknowledgment from popup');
|
|
540
|
+
clearTimeout(timeout);
|
|
541
|
+
window.removeEventListener('message', messageHandler);
|
|
542
|
+
resolve();
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
window.addEventListener('message', messageHandler);
|
|
547
|
+
} catch (error) {
|
|
548
|
+
reject(error);
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
sendWithRetry();
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Set up a listener for messages from the popup with autoFetch support
|
|
558
|
+
* @param {Function} callback - Function to handle messages from the popup
|
|
559
|
+
* @param {Object} options - Configuration options
|
|
560
|
+
* @param {boolean} options.autoFetch - Whether to automatically make API calls
|
|
561
|
+
* @param {Function} options.onApiResponse - Callback for API responses
|
|
562
|
+
* @returns {Function} Cleanup function to remove the listener
|
|
563
|
+
*/
|
|
564
|
+
export function listenForPopupMessages(callback, options = {}) {
|
|
565
|
+
const { autoFetch = true, onApiResponse } = options;
|
|
566
|
+
|
|
567
|
+
const messageHandler = async (event) => {
|
|
568
|
+
console.log('🔥 Received message from popup:', event.data);
|
|
569
|
+
|
|
570
|
+
if (event.data && event.data.source === 'onairosPopup') {
|
|
571
|
+
// Handle data request completion
|
|
572
|
+
if (event.data.type === 'dataRequestComplete') {
|
|
573
|
+
console.log('🔥 Data request completed:', event.data);
|
|
574
|
+
|
|
575
|
+
// Note: API call is already made in the popup when autoFetch is true
|
|
576
|
+
// The popup sends the result with apiResponse or apiError already included
|
|
577
|
+
callback(event.data);
|
|
578
|
+
} else {
|
|
579
|
+
callback(event.data);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
console.log('🔥 Setting up popup message listener');
|
|
585
|
+
window.addEventListener('message', messageHandler);
|
|
586
|
+
|
|
587
|
+
// Return cleanup function
|
|
588
|
+
return () => {
|
|
589
|
+
console.log('🔥 Cleaning up popup message listener');
|
|
590
|
+
window.removeEventListener('message', messageHandler);
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Make API call with user's approved data
|
|
596
|
+
* @param {Array} approvedData - Array of approved data types
|
|
597
|
+
* @param {Object} options - API call options
|
|
598
|
+
* @param {string} options.apiUrl - API endpoint URL
|
|
599
|
+
* @param {boolean} options.testMode - Whether to use test mode
|
|
600
|
+
* @param {string} options.userEmail - User email
|
|
601
|
+
* @param {string} options.appName - App name
|
|
602
|
+
* @returns {Promise} Promise resolving to API response
|
|
603
|
+
*/
|
|
604
|
+
async function makeApiCall(approvedData, options = {}) {
|
|
605
|
+
// Use env-aware default API URL
|
|
606
|
+
const defaultApiUrl = `${getApiBaseUrl()}/getAPIurlMobile`;
|
|
607
|
+
const {
|
|
608
|
+
apiUrl = defaultApiUrl,
|
|
609
|
+
testMode = false,
|
|
610
|
+
userEmail = '',
|
|
611
|
+
appName = 'App'
|
|
612
|
+
} = options;
|
|
613
|
+
|
|
614
|
+
try {
|
|
615
|
+
// Map frontend data types to backend confirmation types
|
|
616
|
+
const mapDataTypesToConfirmations = (approvedData) => {
|
|
617
|
+
const confirmations = [];
|
|
618
|
+
const currentDate = new Date().toISOString();
|
|
619
|
+
|
|
620
|
+
// Map frontend types to backend types according to API expectations
|
|
621
|
+
const dataTypeMapping = {
|
|
622
|
+
'basic': 'Medium', // Basic info -> Medium data
|
|
623
|
+
'personality': 'Large', // Personality -> Large analysis
|
|
624
|
+
'preferences': 'Traits', // Preferences -> Traits data
|
|
625
|
+
'rawMemories': 'LLMData' // Raw memories -> LLM data
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
approvedData.forEach(dataType => {
|
|
629
|
+
if (dataTypeMapping[dataType]) {
|
|
630
|
+
confirmations.push({
|
|
631
|
+
data: dataTypeMapping[dataType],
|
|
632
|
+
date: currentDate
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
return confirmations;
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
const endpoint = testMode
|
|
641
|
+
? `${getApiBaseUrl()}/inferenceTest`
|
|
642
|
+
: apiUrl;
|
|
643
|
+
|
|
644
|
+
const confirmations = mapDataTypesToConfirmations(approvedData);
|
|
645
|
+
|
|
646
|
+
// Format request according to backend expectations
|
|
647
|
+
// PIN is stored on backend via /store-pin/mobile - no need to send placeholder
|
|
648
|
+
const requestBody = testMode ? {
|
|
649
|
+
// Test mode: simple format for testing
|
|
650
|
+
approvedData,
|
|
651
|
+
userEmail,
|
|
652
|
+
appName,
|
|
653
|
+
testMode,
|
|
654
|
+
timestamp: new Date().toISOString()
|
|
655
|
+
} : {
|
|
656
|
+
// Live mode: proper Info format for backend
|
|
657
|
+
Info: {
|
|
658
|
+
storage: "local",
|
|
659
|
+
appId: appName,
|
|
660
|
+
confirmations: confirmations,
|
|
661
|
+
account: userEmail,
|
|
662
|
+
proofMode: false,
|
|
663
|
+
Domain: window.location.hostname,
|
|
664
|
+
web3Type: "standard",
|
|
665
|
+
OthentSub: null
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
const userToken = getUserToken();
|
|
670
|
+
if (!userToken) {
|
|
671
|
+
const missingAuthError = new Error('Authentication required. Please log in again before requesting data.');
|
|
672
|
+
missingAuthError.code = 'AUTHENTICATION_REQUIRED';
|
|
673
|
+
throw missingAuthError;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const response = await fetch(endpoint, {
|
|
677
|
+
method: 'POST',
|
|
678
|
+
headers: {
|
|
679
|
+
...getRequiredUserAuthHeaders({
|
|
680
|
+
requireToken: true,
|
|
681
|
+
includeApiKey: false,
|
|
682
|
+
}),
|
|
683
|
+
},
|
|
684
|
+
body: JSON.stringify(requestBody)
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
if (handleUnauthorizedResponse(response)) {
|
|
688
|
+
const authExpiredError = new Error('Authentication expired. Please log in again.');
|
|
689
|
+
authExpiredError.code = 'AUTHENTICATION_REQUIRED';
|
|
690
|
+
throw authExpiredError;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
if (!response.ok) {
|
|
694
|
+
throw new Error(`API call failed with status: ${response.status}`);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
const data = await response.json();
|
|
698
|
+
|
|
699
|
+
// Format response according to test mode requirements
|
|
700
|
+
if (testMode && data) {
|
|
701
|
+
return {
|
|
702
|
+
InferenceResult: {
|
|
703
|
+
output: data.croppedInference || data.output || data.inference,
|
|
704
|
+
traits: data.traitResult || data.traits || data.personalityData
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
return data;
|
|
710
|
+
} catch (error) {
|
|
711
|
+
console.error('API call error:', error);
|
|
712
|
+
throw error;
|
|
713
|
+
}
|
|
714
|
+
}
|