@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,52 @@
|
|
|
1
|
+
const pick = (value) => {
|
|
2
|
+
const s = typeof value === 'string' ? value.trim() : '';
|
|
3
|
+
return s && s !== 'undefined' && s !== 'null' ? s : null;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
let googleClientIds = {
|
|
7
|
+
webClientId: null,
|
|
8
|
+
iosClientId: null,
|
|
9
|
+
androidClientId: null,
|
|
10
|
+
serverClientId: null,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let youtubeClientId = null;
|
|
14
|
+
|
|
15
|
+
export const updateGoogleClientIds = (clientIds = {}) => {
|
|
16
|
+
const webClientId = pick(clientIds.webClientId);
|
|
17
|
+
const iosClientId = pick(clientIds.iosClientId);
|
|
18
|
+
const androidClientId = pick(clientIds.androidClientId);
|
|
19
|
+
const serverClientId = pick(clientIds.serverClientId);
|
|
20
|
+
|
|
21
|
+
googleClientIds = {
|
|
22
|
+
...googleClientIds,
|
|
23
|
+
...(webClientId ? { webClientId } : {}),
|
|
24
|
+
...(iosClientId ? { iosClientId } : {}),
|
|
25
|
+
...(androidClientId ? { androidClientId } : {}),
|
|
26
|
+
...(serverClientId ? { serverClientId } : {}),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (typeof window !== 'undefined') {
|
|
30
|
+
if (webClientId) {
|
|
31
|
+
window.onairosGoogleClientId = webClientId;
|
|
32
|
+
window.onairosGoogleWebClientId = webClientId;
|
|
33
|
+
}
|
|
34
|
+
if (iosClientId) window.onairosGoogleIosClientId = iosClientId;
|
|
35
|
+
if (androidClientId) window.onairosGoogleAndroidClientId = androidClientId;
|
|
36
|
+
if (serverClientId) window.onairosGoogleServerClientId = serverClientId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return googleClientIds;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const getGoogleClientIds = () => ({ ...googleClientIds });
|
|
43
|
+
|
|
44
|
+
export const updateYoutubeClientId = (clientId) => {
|
|
45
|
+
const next = pick(clientId);
|
|
46
|
+
if (!next) return youtubeClientId;
|
|
47
|
+
youtubeClientId = next;
|
|
48
|
+
if (typeof window !== 'undefined') window.onairosYoutubeClientId = next;
|
|
49
|
+
return youtubeClientId;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const getYoutubeClientId = () => youtubeClientId;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatGPT Hosted Temporary Browser Import (SDK module)
|
|
3
|
+
* ====================================================
|
|
4
|
+
*
|
|
5
|
+
* Public SDK entry for the "hosted temporary browser import" flow: a one-time,
|
|
6
|
+
* user-directed historical import for ChatGPT. The SDK creates a disposable
|
|
7
|
+
* server-side browser session on the Onairos backend, opens a viewer popup that
|
|
8
|
+
* streams that temporary browser, and polls for status/preview until the user
|
|
9
|
+
* approves, cancels, or the session expires.
|
|
10
|
+
*
|
|
11
|
+
* This is NOT official OpenAI OAuth and NOT ongoing sync. Nothing about the
|
|
12
|
+
* user's login is stored — the backend destroys the disposable browser context
|
|
13
|
+
* on approve/cancel/expire/failure.
|
|
14
|
+
*
|
|
15
|
+
* Backwards compatibility: this is an additive module. It does not change the
|
|
16
|
+
* existing `ChatGPTConnector` bookmarklet/extension flow or any other exports.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { getApiBaseUrl } from '../config/api-config.js';
|
|
20
|
+
import { getUserToken } from '../utils/authHeaders.js';
|
|
21
|
+
|
|
22
|
+
const POLL_INTERVAL_MS = 2000;
|
|
23
|
+
const TERMINAL_STATUSES = ['complete', 'cancelled', 'failed', 'expired'];
|
|
24
|
+
|
|
25
|
+
/** Providers with a hosted browser import on the backend. */
|
|
26
|
+
const SUPPORTED_PROVIDERS = [
|
|
27
|
+
'chatgpt',
|
|
28
|
+
'claude',
|
|
29
|
+
'gemini',
|
|
30
|
+
'grok',
|
|
31
|
+
'instagram',
|
|
32
|
+
'spotify',
|
|
33
|
+
'sephora',
|
|
34
|
+
'netflix',
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
/** Backend path for a provider's hosted-import API. */
|
|
38
|
+
function apiBasePath(provider) {
|
|
39
|
+
return `/api/connectors/${provider}/hosted-import`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function normalizeBaseUrl(url) {
|
|
43
|
+
if (!url || typeof url !== 'string') return null;
|
|
44
|
+
const trimmed = url.trim();
|
|
45
|
+
if (!trimmed) return null;
|
|
46
|
+
return trimmed.replace(/\/$/, '');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function buildHeaders(controlToken) {
|
|
50
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
51
|
+
// Best-effort user auth so the backend can tie the session to a known user.
|
|
52
|
+
const userToken = (() => {
|
|
53
|
+
try {
|
|
54
|
+
return getUserToken();
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
})();
|
|
59
|
+
if (userToken) headers.Authorization = `Bearer ${userToken}`;
|
|
60
|
+
// Per-session control token gates status/approve/cancel on the backend.
|
|
61
|
+
if (controlToken) headers['x-hosted-import-token'] = controlToken;
|
|
62
|
+
return headers;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* fetch with retries for TRANSIENT failures — `fetch()` throwing "Failed to
|
|
69
|
+
* fetch" (network blip, CORS preflight race, backend cold moment) or a 5xx.
|
|
70
|
+
* Retries a few times with backoff so opening the connector "always works"
|
|
71
|
+
* instead of failing on the first flake. Does NOT retry real 4xx errors.
|
|
72
|
+
*/
|
|
73
|
+
async function fetchWithRetry(url, options, attempts = 4) {
|
|
74
|
+
let lastErr;
|
|
75
|
+
for (let i = 0; i < attempts; i++) {
|
|
76
|
+
try {
|
|
77
|
+
const res = await fetch(url, options);
|
|
78
|
+
// Retry transient server errors; return everything else to the caller.
|
|
79
|
+
if (res.status >= 500 && res.status < 600 && i < attempts - 1) {
|
|
80
|
+
await sleep(400 * (i + 1));
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
return res;
|
|
84
|
+
} catch (err) {
|
|
85
|
+
// "Failed to fetch" / network error — retry with backoff.
|
|
86
|
+
lastErr = err;
|
|
87
|
+
if (i < attempts - 1) await sleep(400 * (i + 1));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
throw lastErr || new Error('Failed to fetch');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function postJson(url, controlToken, body) {
|
|
94
|
+
const res = await fetchWithRetry(url, {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
headers: buildHeaders(controlToken),
|
|
97
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
98
|
+
});
|
|
99
|
+
const data = await res.json().catch(() => ({}));
|
|
100
|
+
if (!res.ok) {
|
|
101
|
+
throw new Error(data?.error || `Request failed (${res.status})`);
|
|
102
|
+
}
|
|
103
|
+
return data;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function getJson(url, controlToken) {
|
|
107
|
+
const res = await fetchWithRetry(url, { method: 'GET', headers: buildHeaders(controlToken) });
|
|
108
|
+
const data = await res.json().catch(() => ({}));
|
|
109
|
+
if (!res.ok) {
|
|
110
|
+
throw new Error(data?.error || `Request failed (${res.status})`);
|
|
111
|
+
}
|
|
112
|
+
return data;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Open the hosted import viewer popup. Falls back gracefully if popups are
|
|
117
|
+
* blocked (the caller can still drive the flow via callbacks).
|
|
118
|
+
*/
|
|
119
|
+
function openViewer(viewerUrl) {
|
|
120
|
+
if (typeof window === 'undefined') return null;
|
|
121
|
+
try {
|
|
122
|
+
const width = 1180;
|
|
123
|
+
const height = 860;
|
|
124
|
+
const left = Math.max(0, (window.screen?.width || 1280) / 2 - width / 2);
|
|
125
|
+
const top = Math.max(0, (window.screen?.height || 900) / 2 - height / 2);
|
|
126
|
+
return window.open(
|
|
127
|
+
viewerUrl,
|
|
128
|
+
'onairos-chatgpt-hosted-import',
|
|
129
|
+
`width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`
|
|
130
|
+
);
|
|
131
|
+
} catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Start a hosted temporary browser import for a supported provider. Opens a
|
|
138
|
+
* viewer popup streaming a disposable server browser; the user logs in and the
|
|
139
|
+
* provider adapter imports the relevant data automatically.
|
|
140
|
+
*
|
|
141
|
+
* @param {object} [options]
|
|
142
|
+
* @param {'chatgpt'|'claude'|'gemini'|'grok'|'instagram'|'spotify'|'sephora'|'netflix'} [options.provider='chatgpt']
|
|
143
|
+
* @param {string} [options.backendBaseUrl] Override the Onairos API base URL.
|
|
144
|
+
* @param {(status: any) => void} [options.onStatus] Called whenever status changes.
|
|
145
|
+
* @param {(preview: any) => void} [options.onPreview] Called once preview is ready.
|
|
146
|
+
* @returns {Promise<{ provider: string, status: 'complete'|'cancelled'|'failed'|'expired', sessionId: string, preview?: any }>}
|
|
147
|
+
*
|
|
148
|
+
* The returned promise also carries `.approve(approvedItemIds?)` and `.cancel()`
|
|
149
|
+
* helpers for hosts that want to drive approval programmatically instead of
|
|
150
|
+
* using the viewer popup's built-in buttons.
|
|
151
|
+
*/
|
|
152
|
+
export function connectHostedImport(options = {}) {
|
|
153
|
+
const { onStatus, onPreview } = options;
|
|
154
|
+
const provider = SUPPORTED_PROVIDERS.includes(String(options.provider || '').toLowerCase())
|
|
155
|
+
? String(options.provider).toLowerCase()
|
|
156
|
+
: 'chatgpt';
|
|
157
|
+
const API_BASE_PATH = apiBasePath(provider);
|
|
158
|
+
const baseUrl = normalizeBaseUrl(options.backendBaseUrl) || getApiBaseUrl();
|
|
159
|
+
|
|
160
|
+
let controlToken = null;
|
|
161
|
+
let sessionId = null;
|
|
162
|
+
let viewerWindow = null;
|
|
163
|
+
let pollTimer = null;
|
|
164
|
+
let settled = false;
|
|
165
|
+
let lastStatus = null;
|
|
166
|
+
let previewFired = false;
|
|
167
|
+
|
|
168
|
+
const sessionUrl = () => `${baseUrl}${API_BASE_PATH}/session/${sessionId}`;
|
|
169
|
+
|
|
170
|
+
// Helper actions exposed on the returned promise.
|
|
171
|
+
const approve = async (approvedItemIds) => {
|
|
172
|
+
if (!sessionId) throw new Error('Session not started');
|
|
173
|
+
return postJson(`${sessionUrl()}/approve`, controlToken, { approvedItemIds });
|
|
174
|
+
};
|
|
175
|
+
const cancel = async () => {
|
|
176
|
+
if (!sessionId) throw new Error('Session not started');
|
|
177
|
+
return postJson(`${sessionUrl()}/cancel`, controlToken, {});
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const promise = new Promise((resolve, reject) => {
|
|
181
|
+
const cleanup = () => {
|
|
182
|
+
if (pollTimer) {
|
|
183
|
+
clearInterval(pollTimer);
|
|
184
|
+
pollTimer = null;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const finish = (session) => {
|
|
189
|
+
if (settled) return;
|
|
190
|
+
settled = true;
|
|
191
|
+
cleanup();
|
|
192
|
+
// NOTE: we intentionally do NOT close the viewer window here. The viewer
|
|
193
|
+
// shows its own terminal UI ("All done! Imported N conversations" with a
|
|
194
|
+
// Close button, or a stopped/expired state) and notifies this opener via
|
|
195
|
+
// postMessage. Auto-closing it slammed that success screen shut the instant
|
|
196
|
+
// the import completed, so the user never saw it. Let them see it and close
|
|
197
|
+
// it themselves (or the host can, using the popup handle if it wants).
|
|
198
|
+
resolve({
|
|
199
|
+
provider,
|
|
200
|
+
status: session?.status,
|
|
201
|
+
sessionId,
|
|
202
|
+
preview: session?.preview,
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const fail = (err) => {
|
|
207
|
+
if (settled) return;
|
|
208
|
+
settled = true;
|
|
209
|
+
cleanup();
|
|
210
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const handleSession = (session) => {
|
|
214
|
+
if (!session) return;
|
|
215
|
+
// Fire status change callback.
|
|
216
|
+
if (session.status !== lastStatus) {
|
|
217
|
+
lastStatus = session.status;
|
|
218
|
+
if (typeof onStatus === 'function') {
|
|
219
|
+
try { onStatus(session); } catch { /* host callback error */ }
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Fire preview callback once.
|
|
223
|
+
if (session.status === 'preview_ready' && !previewFired) {
|
|
224
|
+
previewFired = true;
|
|
225
|
+
if (typeof onPreview === 'function') {
|
|
226
|
+
try { onPreview(session.preview); } catch { /* host callback error */ }
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// Resolve on terminal status.
|
|
230
|
+
if (TERMINAL_STATUSES.includes(session.status)) {
|
|
231
|
+
finish(session);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const poll = async () => {
|
|
236
|
+
if (settled) return;
|
|
237
|
+
try {
|
|
238
|
+
const data = await getJson(`${sessionUrl()}?t=${encodeURIComponent(controlToken)}`, controlToken);
|
|
239
|
+
handleSession(data.session);
|
|
240
|
+
} catch (err) {
|
|
241
|
+
// Transient network errors shouldn't kill the flow; keep polling until
|
|
242
|
+
// TTL. Only surface hard failures if the session is unrecoverable.
|
|
243
|
+
if (String(err?.message || '').includes('not found')) {
|
|
244
|
+
fail(err);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// If the user closed the popup before completing, cancel + resolve.
|
|
248
|
+
if (!settled && viewerWindow && viewerWindow.closed && !TERMINAL_STATUSES.includes(lastStatus)) {
|
|
249
|
+
try { await cancel(); } catch { /* best effort */ }
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// Kick off: create the session, open the viewer, then poll.
|
|
254
|
+
(async () => {
|
|
255
|
+
try {
|
|
256
|
+
const created = await postJson(`${baseUrl}${API_BASE_PATH}/session`, null, {});
|
|
257
|
+
sessionId = created.sessionId;
|
|
258
|
+
controlToken = created.controlToken;
|
|
259
|
+
if (!sessionId || !controlToken) {
|
|
260
|
+
throw new Error('Backend did not return a session');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (created.session) handleSession(created.session);
|
|
264
|
+
|
|
265
|
+
const viewerUrl = `${baseUrl}${created.viewerPath}?t=${encodeURIComponent(controlToken)}`;
|
|
266
|
+
viewerWindow = openViewer(viewerUrl);
|
|
267
|
+
|
|
268
|
+
pollTimer = setInterval(poll, POLL_INTERVAL_MS);
|
|
269
|
+
poll();
|
|
270
|
+
} catch (err) {
|
|
271
|
+
fail(err);
|
|
272
|
+
}
|
|
273
|
+
})();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Attach programmatic control helpers (non-enumerable to keep the promise clean).
|
|
277
|
+
Object.defineProperties(promise, {
|
|
278
|
+
approve: { value: approve },
|
|
279
|
+
cancel: { value: cancel },
|
|
280
|
+
getSessionId: { value: () => sessionId },
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
return promise;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Convenience wrappers per provider (all delegate to connectHostedImport). */
|
|
287
|
+
export function connectChatGPTHostedImport(options = {}) {
|
|
288
|
+
return connectHostedImport({ ...options, provider: 'chatgpt' });
|
|
289
|
+
}
|
|
290
|
+
export function connectClaudeHostedImport(options = {}) {
|
|
291
|
+
return connectHostedImport({ ...options, provider: 'claude' });
|
|
292
|
+
}
|
|
293
|
+
export function connectGeminiHostedImport(options = {}) {
|
|
294
|
+
return connectHostedImport({ ...options, provider: 'gemini' });
|
|
295
|
+
}
|
|
296
|
+
export function connectGrokHostedImport(options = {}) {
|
|
297
|
+
return connectHostedImport({ ...options, provider: 'grok' });
|
|
298
|
+
}
|
|
299
|
+
export function connectInstagramHostedImport(options = {}) {
|
|
300
|
+
return connectHostedImport({ ...options, provider: 'instagram' });
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export default connectHostedImport;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import OnairosAppButton from './OnairosAppButton.jsx';
|
|
3
|
+
// import GoogleButton from './GoogleButton';
|
|
4
|
+
import TestTelegramButton from './TestTelegramButton.js';
|
|
5
|
+
|
|
6
|
+
export default function AuthButtons({
|
|
7
|
+
onLoginSuccess,
|
|
8
|
+
setOthent,
|
|
9
|
+
setHashedOthentSub,
|
|
10
|
+
setEncryptedPin
|
|
11
|
+
}) {
|
|
12
|
+
const [hasSavedCredentials, setHasSavedCredentials] = useState(false);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
checkSavedCredentials();
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
const checkSavedCredentials = async () => {
|
|
19
|
+
const credentials = localStorage.getItem('onairosCredentials');
|
|
20
|
+
setHasSavedCredentials(!!credentials);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const handleOthentSuccess = async (othentData) => {
|
|
24
|
+
// Set Othent-specific state
|
|
25
|
+
setOthent(true);
|
|
26
|
+
setHashedOthentSub(othentData.hashedOthentSub);
|
|
27
|
+
setEncryptedPin(othentData.encryptedPin);
|
|
28
|
+
|
|
29
|
+
// Call general login success handler
|
|
30
|
+
await onLoginSuccess(othentData.userDetails);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const othentLogin = async (data) =>{
|
|
34
|
+
onLoginSuccess(data,true);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div className="flex flex-row justify-center items-center space-x-4">
|
|
39
|
+
{/* <OthentButton onSuccess={handleOthentSuccess} onLoginSuccess={othentLogin}/> */}
|
|
40
|
+
{/* <GoogleButton onLoginSuccess={othentLogin}/> */}
|
|
41
|
+
<TestTelegramButton />
|
|
42
|
+
<OnairosAppButton
|
|
43
|
+
hasSavedCredentials={hasSavedCredentials}
|
|
44
|
+
onSuccess={onLoginSuccess}
|
|
45
|
+
/>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|