@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,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hostname-based branding overrides for embedded partner apps.
|
|
3
|
+
*
|
|
4
|
+
* NOTE: Keep these checks extremely defensive: this code runs in many environments
|
|
5
|
+
* (iframes, SSR-like toolchains, WKWebView) where `window` may be missing or restricted.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function getRuntimeHostname() {
|
|
9
|
+
try {
|
|
10
|
+
if (typeof window === 'undefined') return '';
|
|
11
|
+
return String(window.location?.hostname || '').toLowerCase();
|
|
12
|
+
} catch {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* For certain Framer partner apps we hide Onairos logo on the first two onboarding screens
|
|
19
|
+
* (welcome + email) to better match the host app’s branding expectations.
|
|
20
|
+
*/
|
|
21
|
+
export function shouldHideOnairosLogoOnWelcomeAndEmail(hostname = getRuntimeHostname()) {
|
|
22
|
+
const host = String(hostname || '').toLowerCase();
|
|
23
|
+
if (!host) return false;
|
|
24
|
+
|
|
25
|
+
// aiplus.dev (and any subdomain like www.aiplus.dev)
|
|
26
|
+
if (host === 'aiplus.dev' || host.endsWith('.aiplus.dev')) return true;
|
|
27
|
+
|
|
28
|
+
// Framer test site for verification
|
|
29
|
+
if (host === 'onairos-framer-test.framer.website') return true;
|
|
30
|
+
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getAiPlusPartnerWelcomeCopy(hostname = getRuntimeHostname()) {
|
|
35
|
+
// For now, this is the same condition set as our “hide logo” override:
|
|
36
|
+
// these are the partner Framer-hosted sites that want a single-line message.
|
|
37
|
+
if (!shouldHideOnairosLogoOnWelcomeAndEmail(hostname)) return '';
|
|
38
|
+
return 'ai plus dev uses Onairos to understand you.';
|
|
39
|
+
}
|
|
40
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the Onairos **web** Google OAuth client used by
|
|
3
|
+
* Google Sign-In / @react-oauth/google. YouTube and other connectors may use
|
|
4
|
+
* different OAuth clients elsewhere.
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_ONAIROS_GOOGLE_WEB_CLIENT_ID =
|
|
7
|
+
'1030678346906-4npem7vckp0e56p17c81sv2pee2hhule.apps.googleusercontent.com';
|
|
8
|
+
|
|
9
|
+
const pick = (value) => {
|
|
10
|
+
const s = typeof value === 'string' ? value.trim() : '';
|
|
11
|
+
return s && s !== 'undefined' && s !== 'null' ? s : null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Resolve the Google **web application** OAuth client ID for browser Sign-In.
|
|
16
|
+
* @param {string|null|undefined} explicit - Usually `props.googleClientId` from `<Onairos />` or `OnairosButton`.
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/
|
|
19
|
+
export function resolveGoogleWebClientId(explicit) {
|
|
20
|
+
if (pick(explicit)) return pick(explicit);
|
|
21
|
+
|
|
22
|
+
if (typeof window !== 'undefined') {
|
|
23
|
+
const fromWindow =
|
|
24
|
+
pick(window.onairosGoogleClientId) ||
|
|
25
|
+
pick(window.onairosGoogleServerClientId) ||
|
|
26
|
+
pick(window.REACT_APP_GOOGLE_CLIENT_ID) ||
|
|
27
|
+
pick(window.ONAIROS_GOOGLE_CLIENT_ID) ||
|
|
28
|
+
pick(window.VITE_GOOGLE_CLIENT_ID) ||
|
|
29
|
+
pick(window.VITE_ONAIROS_GOOGLE_CLIENT_ID);
|
|
30
|
+
if (fromWindow) return fromWindow;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
if (typeof localStorage !== 'undefined') {
|
|
34
|
+
const fromStorage =
|
|
35
|
+
pick(localStorage.getItem('onairos_google_client_id')) ||
|
|
36
|
+
pick(localStorage.getItem('ONAIROS_GOOGLE_CLIENT_ID')) ||
|
|
37
|
+
pick(localStorage.getItem('VITE_GOOGLE_CLIENT_ID'));
|
|
38
|
+
if (fromStorage) return fromStorage;
|
|
39
|
+
}
|
|
40
|
+
} catch (_) {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
45
|
+
const fromEnv =
|
|
46
|
+
pick(process.env.REACT_APP_GOOGLE_CLIENT_ID) ||
|
|
47
|
+
pick(process.env.VITE_GOOGLE_CLIENT_ID) ||
|
|
48
|
+
pick(process.env.VITE_ONAIROS_GOOGLE_CLIENT_ID) ||
|
|
49
|
+
pick(process.env.ONAIROS_GOOGLE_CLIENT_ID);
|
|
50
|
+
if (fromEnv) return fromEnv;
|
|
51
|
+
}
|
|
52
|
+
} catch (_) {}
|
|
53
|
+
|
|
54
|
+
return DEFAULT_ONAIROS_GOOGLE_WEB_CLIENT_ID;
|
|
55
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone Onairos Overlay Handler
|
|
3
|
+
* Allows developers to trigger the Onairos flow programmatically without the button component
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import ReactDOM from 'react-dom';
|
|
8
|
+
import { OnairosButton } from '../onairosButton.jsx';
|
|
9
|
+
import { formatOnairosResponse } from './responseFormatter.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Opens the Onairos overlay flow programmatically
|
|
13
|
+
* @param {Object} config - Configuration options
|
|
14
|
+
* @param {Array} config.requestData - Data types to request ['basic', 'personality', 'preferences']
|
|
15
|
+
* @param {string} config.webpageName - Name of your application
|
|
16
|
+
* @param {Function} config.onComplete - Callback function when flow completes
|
|
17
|
+
* @param {boolean} config.autoFetch - Whether to auto-fetch data (default: false)
|
|
18
|
+
* @param {boolean} config.testMode - Whether to use test mode (default: false)
|
|
19
|
+
* @param {string} config.appIcon - URL to your app icon (optional)
|
|
20
|
+
* @param {boolean} config.formatResponse - Whether to format response with dictionary (default: true)
|
|
21
|
+
* @param {Object} config.responseFormat - Response formatting options
|
|
22
|
+
* @returns {Promise<Function>} Promise that resolves to a cleanup function
|
|
23
|
+
*/
|
|
24
|
+
export async function openOnairosOverlay(config = {}) {
|
|
25
|
+
const {
|
|
26
|
+
requestData = ['basic', 'personality'],
|
|
27
|
+
webpageName = 'My App',
|
|
28
|
+
onComplete = null,
|
|
29
|
+
autoFetch = false,
|
|
30
|
+
testMode = false,
|
|
31
|
+
appIcon = null,
|
|
32
|
+
formatResponse = true,
|
|
33
|
+
responseFormat = { includeDictionary: true, includeArray: true },
|
|
34
|
+
...otherProps
|
|
35
|
+
} = config;
|
|
36
|
+
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
try {
|
|
39
|
+
// Create a container for the overlay
|
|
40
|
+
const containerId = `onairos-overlay-${Math.random().toString(36).substr(2, 9)}`;
|
|
41
|
+
const container = document.createElement('div');
|
|
42
|
+
container.id = containerId;
|
|
43
|
+
container.style.position = 'fixed';
|
|
44
|
+
container.style.top = '0';
|
|
45
|
+
container.style.left = '0';
|
|
46
|
+
container.style.width = '100%';
|
|
47
|
+
container.style.height = '100%';
|
|
48
|
+
container.style.zIndex = '9999';
|
|
49
|
+
container.style.pointerEvents = 'none'; // Allow clicks to pass through to the button
|
|
50
|
+
|
|
51
|
+
document.body.appendChild(container);
|
|
52
|
+
|
|
53
|
+
// Cleanup function
|
|
54
|
+
const cleanup = () => {
|
|
55
|
+
if (container && container.parentNode) {
|
|
56
|
+
try {
|
|
57
|
+
ReactDOM.unmountComponentAtNode(container);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.warn('Error unmounting React component:', error);
|
|
60
|
+
}
|
|
61
|
+
container.parentNode.removeChild(container);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Enhanced onComplete handler
|
|
66
|
+
const handleComplete = (result) => {
|
|
67
|
+
let formattedResult = result;
|
|
68
|
+
|
|
69
|
+
// Format response if requested
|
|
70
|
+
if (formatResponse && result?.apiResponse) {
|
|
71
|
+
try {
|
|
72
|
+
formattedResult = {
|
|
73
|
+
...result,
|
|
74
|
+
apiResponse: formatOnairosResponse(result.apiResponse, responseFormat)
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.warn('Error formatting response:', error);
|
|
78
|
+
// Continue with original result if formatting fails
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Call the original onComplete callback
|
|
83
|
+
if (onComplete && typeof onComplete === 'function') {
|
|
84
|
+
try {
|
|
85
|
+
onComplete(formattedResult);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('Error in onComplete callback:', error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Cleanup after a short delay to allow animations
|
|
92
|
+
setTimeout(cleanup, 100);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Create the Onairos button component with auto-open
|
|
96
|
+
const OnairosElement = React.createElement(OnairosButton, {
|
|
97
|
+
requestData,
|
|
98
|
+
webpageName,
|
|
99
|
+
onComplete: handleComplete,
|
|
100
|
+
autoFetch,
|
|
101
|
+
testMode,
|
|
102
|
+
appIcon,
|
|
103
|
+
visualType: 'icon', // Use icon-only to minimize visual footprint
|
|
104
|
+
buttonType: 'pill',
|
|
105
|
+
textColor: 'white',
|
|
106
|
+
style: { opacity: 0, position: 'absolute', top: '-9999px' }, // Hide the button
|
|
107
|
+
...otherProps
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Render the component
|
|
111
|
+
ReactDOM.render(OnairosElement, container);
|
|
112
|
+
|
|
113
|
+
// Auto-click the button to open overlay after render
|
|
114
|
+
setTimeout(() => {
|
|
115
|
+
const button = container.querySelector('button');
|
|
116
|
+
if (button) {
|
|
117
|
+
button.click();
|
|
118
|
+
resolve(cleanup); // Resolve with cleanup function
|
|
119
|
+
} else {
|
|
120
|
+
cleanup();
|
|
121
|
+
reject(new Error('Failed to render Onairos button'));
|
|
122
|
+
}
|
|
123
|
+
}, 100);
|
|
124
|
+
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error('Error opening Onairos overlay:', error);
|
|
127
|
+
reject(error);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Alternative method using React hooks for React applications
|
|
134
|
+
* @param {Object} config - Same configuration as openOnairosOverlay
|
|
135
|
+
* @returns {Object} Hook object with open function and state
|
|
136
|
+
*/
|
|
137
|
+
export function useOnairosOverlay(config = {}) {
|
|
138
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
139
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
140
|
+
const cleanupRef = React.useRef(null);
|
|
141
|
+
|
|
142
|
+
const open = React.useCallback(async (overrideConfig = {}) => {
|
|
143
|
+
if (isOpen || isLoading) return;
|
|
144
|
+
|
|
145
|
+
setIsLoading(true);
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const finalConfig = {
|
|
149
|
+
...config,
|
|
150
|
+
...overrideConfig,
|
|
151
|
+
onComplete: (result) => {
|
|
152
|
+
setIsOpen(false);
|
|
153
|
+
setIsLoading(false);
|
|
154
|
+
|
|
155
|
+
// Call original onComplete if provided
|
|
156
|
+
if (config.onComplete) {
|
|
157
|
+
config.onComplete(result);
|
|
158
|
+
}
|
|
159
|
+
if (overrideConfig.onComplete) {
|
|
160
|
+
overrideConfig.onComplete(result);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const cleanup = await openOnairosOverlay(finalConfig);
|
|
166
|
+
cleanupRef.current = cleanup;
|
|
167
|
+
setIsOpen(true);
|
|
168
|
+
setIsLoading(false);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
setIsLoading(false);
|
|
171
|
+
console.error('Error opening overlay:', error);
|
|
172
|
+
}
|
|
173
|
+
}, [config, isOpen, isLoading]);
|
|
174
|
+
|
|
175
|
+
const close = React.useCallback(() => {
|
|
176
|
+
if (cleanupRef.current) {
|
|
177
|
+
cleanupRef.current();
|
|
178
|
+
cleanupRef.current = null;
|
|
179
|
+
}
|
|
180
|
+
setIsOpen(false);
|
|
181
|
+
setIsLoading(false);
|
|
182
|
+
}, []);
|
|
183
|
+
|
|
184
|
+
// Cleanup on unmount
|
|
185
|
+
React.useEffect(() => {
|
|
186
|
+
return () => {
|
|
187
|
+
if (cleanupRef.current) {
|
|
188
|
+
cleanupRef.current();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}, []);
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
open,
|
|
195
|
+
close,
|
|
196
|
+
isOpen,
|
|
197
|
+
isLoading
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Simple function to get user data without UI (for existing authenticated users)
|
|
203
|
+
* @param {Object} config - Configuration options
|
|
204
|
+
* @param {Array} config.requestData - Data types to request
|
|
205
|
+
* @param {string} config.userEmail - User email (if known)
|
|
206
|
+
* @param {string} config.appName - App name
|
|
207
|
+
* @param {boolean} config.testMode - Whether to use test mode
|
|
208
|
+
* @param {boolean} config.formatResponse - Whether to format response
|
|
209
|
+
* @returns {Promise<Object>} Promise that resolves to user data
|
|
210
|
+
*/
|
|
211
|
+
export async function getOnairosData(config = {}) {
|
|
212
|
+
const {
|
|
213
|
+
requestData = ['basic', 'personality'],
|
|
214
|
+
userEmail = '',
|
|
215
|
+
appName = 'My App',
|
|
216
|
+
testMode = false,
|
|
217
|
+
formatResponse = true,
|
|
218
|
+
responseFormat = { includeDictionary: true, includeArray: true }
|
|
219
|
+
} = config;
|
|
220
|
+
|
|
221
|
+
// This would need to be implemented based on your existing API logic
|
|
222
|
+
// For now, it's a placeholder that developers can use as a reference
|
|
223
|
+
throw new Error('getOnairosData requires authenticated user session. Use openOnairosOverlay for the full authentication flow.');
|
|
224
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform Disconnect & Destruct Utilities
|
|
3
|
+
* Handles disconnection of platforms and deletion of wrapped data
|
|
4
|
+
* Base URL: api2.onairos.uk
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { API_CONFIG } from '../config/api-config.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get authentication token from localStorage
|
|
11
|
+
* @returns {string|null} JWT token
|
|
12
|
+
*/
|
|
13
|
+
const getAuthToken = () => {
|
|
14
|
+
try {
|
|
15
|
+
// Try to get token from multiple sources
|
|
16
|
+
const token = localStorage.getItem('onairos_user_token');
|
|
17
|
+
if (token) return token;
|
|
18
|
+
|
|
19
|
+
// Fallback: extract from user data
|
|
20
|
+
const userData = localStorage.getItem('onairosUser');
|
|
21
|
+
if (userData) {
|
|
22
|
+
const parsed = JSON.parse(userData);
|
|
23
|
+
return parsed.token || null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return null;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error('❌ Error getting auth token:', error);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Platform disconnect endpoint configuration
|
|
35
|
+
*/
|
|
36
|
+
const DISCONNECT_ENDPOINTS = {
|
|
37
|
+
youtube: {
|
|
38
|
+
url: '/youtube/revoke',
|
|
39
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
40
|
+
},
|
|
41
|
+
reddit: {
|
|
42
|
+
url: '/reddit/revoke',
|
|
43
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
44
|
+
},
|
|
45
|
+
gmail: {
|
|
46
|
+
url: '/gmail/revoke',
|
|
47
|
+
bodyFormat: (username) => ({ username })
|
|
48
|
+
},
|
|
49
|
+
pinterest: {
|
|
50
|
+
url: '/pinterest/revoke',
|
|
51
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
52
|
+
},
|
|
53
|
+
linkedin: {
|
|
54
|
+
// /linkedin/revoke does not yet exist in production; use the generic connections updater instead.
|
|
55
|
+
url: '/connections/update',
|
|
56
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'LinkedIn' })
|
|
57
|
+
},
|
|
58
|
+
// Instagram is bookmarklet-only now; there is no OAuth revoke.
|
|
59
|
+
// Best-effort: treat disconnect as a generic "Remove Instagram" connection update.
|
|
60
|
+
instagram: {
|
|
61
|
+
url: '/connections/update',
|
|
62
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'Instagram' })
|
|
63
|
+
},
|
|
64
|
+
github: {
|
|
65
|
+
url: '/github/revoke/github',
|
|
66
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
67
|
+
},
|
|
68
|
+
facebook: {
|
|
69
|
+
url: '/facebook/revoke',
|
|
70
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
71
|
+
},
|
|
72
|
+
x: {
|
|
73
|
+
url: '/x/revoke',
|
|
74
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
75
|
+
},
|
|
76
|
+
twitter: {
|
|
77
|
+
url: '/x/revoke',
|
|
78
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
79
|
+
},
|
|
80
|
+
notion: {
|
|
81
|
+
url: '/notion/revoke',
|
|
82
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
83
|
+
},
|
|
84
|
+
farcaster: {
|
|
85
|
+
url: '/farcaster/revoke',
|
|
86
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
87
|
+
},
|
|
88
|
+
// LLM platforms (ChatGPT, Claude, Gemini, Grok) - to be implemented
|
|
89
|
+
chatgpt: {
|
|
90
|
+
// ChatGPT connections are managed via the generic connections updater (same as other platforms).
|
|
91
|
+
// The dedicated /chatgpt/revoke route is not reliably available across environments.
|
|
92
|
+
url: '/connections/update',
|
|
93
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'ChatGPT' })
|
|
94
|
+
},
|
|
95
|
+
claude: {
|
|
96
|
+
url: '/connections/update',
|
|
97
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'Claude' })
|
|
98
|
+
},
|
|
99
|
+
gemini: {
|
|
100
|
+
url: '/connections/update',
|
|
101
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'Gemini' })
|
|
102
|
+
},
|
|
103
|
+
grok: {
|
|
104
|
+
url: '/connections/update',
|
|
105
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'Grok' })
|
|
106
|
+
},
|
|
107
|
+
perplexity: {
|
|
108
|
+
url: '/connections/update',
|
|
109
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'Perplexity' })
|
|
110
|
+
},
|
|
111
|
+
// Internal data platforms (best-effort: some environments reflect these as connections)
|
|
112
|
+
sephora: {
|
|
113
|
+
url: '/connections/update',
|
|
114
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'Sephora' })
|
|
115
|
+
},
|
|
116
|
+
spotify: {
|
|
117
|
+
url: '/connections/update',
|
|
118
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'Spotify' })
|
|
119
|
+
},
|
|
120
|
+
netflix: {
|
|
121
|
+
url: '/connections/update',
|
|
122
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'Netflix' })
|
|
123
|
+
},
|
|
124
|
+
'instagram-data': {
|
|
125
|
+
url: '/connections/update',
|
|
126
|
+
bodyFormat: (_username) => ({ updateType: 'Remove', newConnection: 'Instagram' })
|
|
127
|
+
},
|
|
128
|
+
tiktok: {
|
|
129
|
+
url: '/tiktok/revoke',
|
|
130
|
+
bodyFormat: (username) => ({ Info: { username } })
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Disconnect a platform from user's account
|
|
136
|
+
* @param {string} platform - Platform name (e.g., 'youtube', 'reddit')
|
|
137
|
+
* @param {string} username - User's email/username
|
|
138
|
+
* @returns {Promise<Object>} Response object
|
|
139
|
+
*/
|
|
140
|
+
export async function disconnectPlatform(platform, username) {
|
|
141
|
+
try {
|
|
142
|
+
const platformKey = platform.toLowerCase();
|
|
143
|
+
const config = DISCONNECT_ENDPOINTS[platformKey];
|
|
144
|
+
|
|
145
|
+
if (!config) {
|
|
146
|
+
throw new Error(`Unknown platform: ${platform}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const baseUrl = API_CONFIG.getBaseUrl();
|
|
150
|
+
const url = `${baseUrl}${config.url}`;
|
|
151
|
+
const body = config.bodyFormat(username);
|
|
152
|
+
const token = getAuthToken();
|
|
153
|
+
|
|
154
|
+
console.log(`🔌 Disconnecting ${platform} for user ${username}...`);
|
|
155
|
+
console.log('📡 URL:', url);
|
|
156
|
+
console.log('📦 Body:', body);
|
|
157
|
+
|
|
158
|
+
const response = await fetch(url, {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
headers: {
|
|
161
|
+
'Content-Type': 'application/json',
|
|
162
|
+
...(token ? { 'Authorization': `Bearer ${token}` } : {})
|
|
163
|
+
},
|
|
164
|
+
body: JSON.stringify(body)
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const raw = await response.text();
|
|
168
|
+
let data = null;
|
|
169
|
+
try {
|
|
170
|
+
data = raw ? JSON.parse(raw) : null;
|
|
171
|
+
} catch (_) {
|
|
172
|
+
data = { raw };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!response.ok) {
|
|
176
|
+
throw new Error(data?.error || data?.message || `HTTP ${response.status}`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
console.log(`✅ ${platform} disconnected successfully`);
|
|
180
|
+
return {
|
|
181
|
+
success: true,
|
|
182
|
+
platform: platform,
|
|
183
|
+
message: data?.message || `${platform} disconnected successfully`,
|
|
184
|
+
data: data
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error(`❌ Error disconnecting ${platform}:`, error);
|
|
189
|
+
return {
|
|
190
|
+
success: false,
|
|
191
|
+
platform: platform,
|
|
192
|
+
error: error.message,
|
|
193
|
+
message: `Failed to disconnect ${platform}: ${error.message}`
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Disconnect multiple platforms at once
|
|
200
|
+
* @param {Array<string>} platforms - Array of platform names
|
|
201
|
+
* @param {string} username - User's email/username
|
|
202
|
+
* @returns {Promise<Object>} Results object with success/failure for each platform
|
|
203
|
+
*/
|
|
204
|
+
export async function disconnectMultiplePlatforms(platforms, username) {
|
|
205
|
+
console.log(`🔌 Disconnecting ${platforms.length} platforms...`);
|
|
206
|
+
|
|
207
|
+
const results = {
|
|
208
|
+
successful: [],
|
|
209
|
+
failed: [],
|
|
210
|
+
total: platforms.length
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// Process disconnections in parallel
|
|
214
|
+
const promises = platforms.map(platform =>
|
|
215
|
+
disconnectPlatform(platform, username)
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const responses = await Promise.allSettled(promises);
|
|
219
|
+
|
|
220
|
+
responses.forEach((result, index) => {
|
|
221
|
+
const platform = platforms[index];
|
|
222
|
+
if (result.status === 'fulfilled' && result.value.success) {
|
|
223
|
+
results.successful.push(platform);
|
|
224
|
+
} else {
|
|
225
|
+
results.failed.push({
|
|
226
|
+
platform: platform,
|
|
227
|
+
error: result.value?.error || result.reason?.message || 'Unknown error'
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
console.log(`✅ Disconnection complete: ${results.successful.length} successful, ${results.failed.length} failed`);
|
|
233
|
+
|
|
234
|
+
return results;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// NOTE: Wrapped dashboard destruct functionality removed
|
|
238
|
+
// Wrapped features are app-level, not SDK-level
|
|
239
|
+
// Apps should implement their own destruct endpoints as needed
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Update local storage after disconnecting a platform
|
|
243
|
+
* Removes the platform from connectedAccounts array
|
|
244
|
+
* @param {string} platform - Platform name that was disconnected
|
|
245
|
+
*/
|
|
246
|
+
export function updateLocalStorageAfterDisconnect(platform) {
|
|
247
|
+
try {
|
|
248
|
+
const userData = localStorage.getItem('onairosUser');
|
|
249
|
+
if (!userData) return;
|
|
250
|
+
|
|
251
|
+
const user = JSON.parse(userData);
|
|
252
|
+
const p = String(platform || '').toLowerCase();
|
|
253
|
+
const aliasSet =
|
|
254
|
+
p === 'x' || p === 'twitter'
|
|
255
|
+
? new Set(['x', 'twitter'])
|
|
256
|
+
: new Set([p]);
|
|
257
|
+
|
|
258
|
+
if (Array.isArray(user.connectedAccounts)) {
|
|
259
|
+
// Remove the platform from connectedAccounts (case-insensitive)
|
|
260
|
+
user.connectedAccounts = user.connectedAccounts.filter(
|
|
261
|
+
(account) => !aliasSet.has(String(account || '').toLowerCase())
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
console.log(`🔄 Updated local storage - removed ${platform}`);
|
|
265
|
+
console.log('📋 Remaining accounts:', user.connectedAccounts);
|
|
266
|
+
|
|
267
|
+
localStorage.setItem('onairosUser', JSON.stringify(user));
|
|
268
|
+
}
|
|
269
|
+
} catch (error) {
|
|
270
|
+
console.error('❌ Error updating local storage:', error);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// NOTE: updateLocalStorageAfterDestruct removed
|
|
275
|
+
// Wrapped data management is app-level, not SDK-level
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Check if user has authentication token
|
|
279
|
+
* @returns {boolean} True if token exists
|
|
280
|
+
*/
|
|
281
|
+
export function hasAuthToken() {
|
|
282
|
+
return !!getAuthToken();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Get list of all supported platforms for disconnection
|
|
287
|
+
* @returns {Array<string>} Array of platform names
|
|
288
|
+
*/
|
|
289
|
+
export function getSupportedPlatforms() {
|
|
290
|
+
return Object.keys(DISCONNECT_ENDPOINTS).filter(key => key !== 'twitter'); // Exclude twitter alias
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Check if a platform is supported for disconnection
|
|
295
|
+
* @param {string} platform - Platform name
|
|
296
|
+
* @returns {boolean} True if platform is supported
|
|
297
|
+
*/
|
|
298
|
+
export function isPlatformSupported(platform) {
|
|
299
|
+
return platform.toLowerCase() in DISCONNECT_ENDPOINTS;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export default {
|
|
303
|
+
disconnectPlatform,
|
|
304
|
+
disconnectMultiplePlatforms,
|
|
305
|
+
updateLocalStorageAfterDisconnect,
|
|
306
|
+
hasAuthToken,
|
|
307
|
+
getSupportedPlatforms,
|
|
308
|
+
isPlatformSupported
|
|
309
|
+
};
|