@onairosofficial/onairos-capacitor 0.1.0 → 0.1.1
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/LICENSE +194 -10
- package/README.md +182 -25
- package/dist/onairos.capacitor.esm.js +1 -0
- package/dist/onairos.capacitor.esm.turbopack.js +1 -0
- package/onairos.d.ts +656 -0
- package/package.json +186 -38
- 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/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 +16 -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,229 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { getDeveloperAuthHeaders, getUserAuthHeaders, isUserAuthenticated } from '../../utils/authHeaders';
|
|
3
|
+
import { API_CONFIG } from '../../config/api-config';
|
|
4
|
+
|
|
5
|
+
class RedditConnector extends Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.state = {
|
|
9
|
+
connected: false,
|
|
10
|
+
open: false,
|
|
11
|
+
isConnecting: false,
|
|
12
|
+
};
|
|
13
|
+
this.handleClose = this.handleClose.bind(this);
|
|
14
|
+
this.handleOpen = this.handleOpen.bind(this);
|
|
15
|
+
this.redditConnect = this.redditConnect.bind(this);
|
|
16
|
+
this.setConnected = this.setConnected.bind(this);
|
|
17
|
+
this.setDisconnected = this.setDisconnected.bind(this);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setConnected() {
|
|
21
|
+
this.setState({ connected: true });
|
|
22
|
+
if (this.props.onConnectionChange) {
|
|
23
|
+
this.props.onConnectionChange('Reddit', true);
|
|
24
|
+
}
|
|
25
|
+
this.handleClose();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setDisconnected() {
|
|
29
|
+
this.updateConnections('Remove', 'Reddit').then(() => {
|
|
30
|
+
this.setState({ connected: false });
|
|
31
|
+
if (this.props.onConnectionChange) {
|
|
32
|
+
this.props.onConnectionChange('Reddit', false);
|
|
33
|
+
}
|
|
34
|
+
this.handleClose();
|
|
35
|
+
}).catch((error) => {
|
|
36
|
+
console.error('Error removing Reddit connection:', error);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async updateConnections(updateType, newConnection) {
|
|
41
|
+
// TIER 2: Require user JWT for connection updates
|
|
42
|
+
if (!isUserAuthenticated()) {
|
|
43
|
+
console.error('[Reddit] User not authenticated - cannot update connections');
|
|
44
|
+
throw new Error('User not authenticated');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(`${API_CONFIG.getBaseUrl()}/connections/update`, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: getUserAuthHeaders(),
|
|
51
|
+
body: JSON.stringify({ updateType, newConnection }), // Username extracted from JWT
|
|
52
|
+
});
|
|
53
|
+
return await response.json();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('UpdateConnections error:', error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
handleOpen() {
|
|
61
|
+
this.setState({ open: true });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
handleClose() {
|
|
65
|
+
this.setState({ open: false });
|
|
66
|
+
if (this.props.onClose) {
|
|
67
|
+
this.props.onClose();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async redditConnect() {
|
|
72
|
+
this.setState({ isConnecting: true });
|
|
73
|
+
|
|
74
|
+
// TIER 2: Require user JWT for OAuth connections
|
|
75
|
+
if (!isUserAuthenticated()) {
|
|
76
|
+
console.error('[Reddit] User not authenticated - cannot connect');
|
|
77
|
+
this.setState({ isConnecting: false });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const resolvedUsername =
|
|
83
|
+
(typeof this.props.username === 'string' && this.props.username.trim().length > 0 ? this.props.username.trim() : '') ||
|
|
84
|
+
(typeof localStorage !== 'undefined' ? (localStorage.getItem('username') || '') : '') ||
|
|
85
|
+
(() => {
|
|
86
|
+
try {
|
|
87
|
+
const user = JSON.parse(localStorage.getItem('onairosUser') || '{}');
|
|
88
|
+
return user?.email || user?.username || '';
|
|
89
|
+
} catch {
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
})();
|
|
93
|
+
|
|
94
|
+
if (!resolvedUsername) {
|
|
95
|
+
throw new Error('Missing username/email for Reddit OAuth');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const isMobile =
|
|
99
|
+
typeof navigator !== 'undefined' &&
|
|
100
|
+
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
101
|
+
|
|
102
|
+
const returnUrl = isMobile && typeof window !== 'undefined'
|
|
103
|
+
? window.location.href
|
|
104
|
+
: '';
|
|
105
|
+
|
|
106
|
+
const bodyPayload = {
|
|
107
|
+
session: {
|
|
108
|
+
username: resolvedUsername,
|
|
109
|
+
...(isMobile ? { sdkType: 'web', returnUrl } : {}),
|
|
110
|
+
},
|
|
111
|
+
Info: { username: resolvedUsername },
|
|
112
|
+
OnairosUsername: resolvedUsername,
|
|
113
|
+
username: resolvedUsername,
|
|
114
|
+
...(isMobile ? { returnUrl } : {}),
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const userHeaders = getUserAuthHeaders();
|
|
118
|
+
const developerHeaders = getDeveloperAuthHeaders();
|
|
119
|
+
const headers = {
|
|
120
|
+
...userHeaders,
|
|
121
|
+
...(developerHeaders?.Authorization ? { 'x-api-key': developerHeaders.Authorization.replace(/^Bearer\s+/i, '') } : {}),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const response = await fetch(`${API_CONFIG.getBaseUrl()}/reddit/authorize`, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
headers,
|
|
127
|
+
body: JSON.stringify(bodyPayload),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (!response.ok) {
|
|
131
|
+
let errorText = '';
|
|
132
|
+
try {
|
|
133
|
+
const json = await response.json();
|
|
134
|
+
errorText = json?.error || json?.message || '';
|
|
135
|
+
} catch {
|
|
136
|
+
try {
|
|
137
|
+
errorText = await response.text();
|
|
138
|
+
} catch {
|
|
139
|
+
errorText = '';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
throw new Error(errorText || `Reddit authorize failed (${response.status})`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const result = await response.json();
|
|
146
|
+
|
|
147
|
+
const redditUrl =
|
|
148
|
+
result.redditURL ||
|
|
149
|
+
result.redditUrl ||
|
|
150
|
+
result.reddit_url ||
|
|
151
|
+
result.authUrl ||
|
|
152
|
+
result.url;
|
|
153
|
+
|
|
154
|
+
if (redditUrl) {
|
|
155
|
+
window.location.href = redditUrl;
|
|
156
|
+
} else {
|
|
157
|
+
console.error('No Reddit URL received');
|
|
158
|
+
this.setState({ isConnecting: false });
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error('Reddit connection error:', error);
|
|
162
|
+
this.setState({ isConnecting: false });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
render() {
|
|
167
|
+
const { open = this.props.open || this.state.open } = this.props;
|
|
168
|
+
|
|
169
|
+
if (!open) return null;
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[2147483647]">
|
|
173
|
+
<div className="bg-white rounded-lg shadow-xl max-w-md w-full mx-4 max-h-full md:max-h-[90vh] overflow-hidden">
|
|
174
|
+
<div className="p-6">
|
|
175
|
+
<h2 className="text-xl font-bold text-gray-900 mb-4">
|
|
176
|
+
Grant Onairos Access to your Reddit Account?
|
|
177
|
+
</h2>
|
|
178
|
+
|
|
179
|
+
<div className="space-y-4 text-gray-700">
|
|
180
|
+
<p>
|
|
181
|
+
Grant Permission to your Reddit Account, so we can build your Data Models.
|
|
182
|
+
</p>
|
|
183
|
+
|
|
184
|
+
<div>
|
|
185
|
+
<p className="font-medium mb-2">We will access your Reddit:</p>
|
|
186
|
+
<ul className="list-disc ml-6 space-y-1">
|
|
187
|
+
<li>Basic Profile Information</li>
|
|
188
|
+
<li>Posts and Comments</li>
|
|
189
|
+
<li>Upvoted and Saved Content</li>
|
|
190
|
+
<li>Subscribed Subreddits</li>
|
|
191
|
+
</ul>
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<p>
|
|
195
|
+
We will delete all the data used once your Model is Created
|
|
196
|
+
</p>
|
|
197
|
+
|
|
198
|
+
<p className="text-sm">
|
|
199
|
+
<a href="https://onairos.uk/privacy-policy" className="text-blue-600 hover:underline">
|
|
200
|
+
Onairos Privacy Policy
|
|
201
|
+
</a>{' '}
|
|
202
|
+
- Your Reddit activity helps us understand your interests and preferences.
|
|
203
|
+
</p>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<div className="flex space-x-3 mt-6">
|
|
207
|
+
<button
|
|
208
|
+
onClick={this.handleClose}
|
|
209
|
+
disabled={this.state.isConnecting}
|
|
210
|
+
className="flex-1 px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 disabled:opacity-50"
|
|
211
|
+
>
|
|
212
|
+
Disagree
|
|
213
|
+
</button>
|
|
214
|
+
<button
|
|
215
|
+
onClick={this.redditConnect}
|
|
216
|
+
disabled={this.state.isConnecting}
|
|
217
|
+
className="flex-1 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50"
|
|
218
|
+
>
|
|
219
|
+
{this.state.isConnecting ? 'Connecting...' : 'Agree'}
|
|
220
|
+
</button>
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export default RedditConnector;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { getDeveloperAuthHeaders, getUserAuthHeaders, isUserAuthenticated } from '../../utils/authHeaders';
|
|
3
|
+
import { API_CONFIG } from '../../config/api-config';
|
|
4
|
+
|
|
5
|
+
class RedditConnector extends Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.state = {
|
|
9
|
+
connected: false,
|
|
10
|
+
open: false,
|
|
11
|
+
isConnecting: false,
|
|
12
|
+
};
|
|
13
|
+
this.handleClose = this.handleClose.bind(this);
|
|
14
|
+
this.handleOpen = this.handleOpen.bind(this);
|
|
15
|
+
this.redditConnect = this.redditConnect.bind(this);
|
|
16
|
+
this.setConnected = this.setConnected.bind(this);
|
|
17
|
+
this.setDisconnected = this.setDisconnected.bind(this);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setConnected() {
|
|
21
|
+
this.setState({ connected: true });
|
|
22
|
+
if (this.props.onConnectionChange) {
|
|
23
|
+
this.props.onConnectionChange('Reddit', true);
|
|
24
|
+
}
|
|
25
|
+
this.handleClose();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setDisconnected() {
|
|
29
|
+
this.updateConnections('Remove', 'Reddit').then(() => {
|
|
30
|
+
this.setState({ connected: false });
|
|
31
|
+
if (this.props.onConnectionChange) {
|
|
32
|
+
this.props.onConnectionChange('Reddit', false);
|
|
33
|
+
}
|
|
34
|
+
this.handleClose();
|
|
35
|
+
}).catch((error) => {
|
|
36
|
+
console.error('Error removing Reddit connection:', error);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async updateConnections(updateType, newConnection) {
|
|
41
|
+
// TIER 2: Require user JWT for connection updates
|
|
42
|
+
if (!isUserAuthenticated()) {
|
|
43
|
+
console.error('[Reddit] User not authenticated - cannot update connections');
|
|
44
|
+
throw new Error('User not authenticated');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(`${API_CONFIG.getBaseUrl()}/connections/update`, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: getUserAuthHeaders(),
|
|
51
|
+
body: JSON.stringify({ updateType, newConnection }), // Username extracted from JWT
|
|
52
|
+
});
|
|
53
|
+
return await response.json();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('UpdateConnections error:', error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
handleOpen() {
|
|
61
|
+
this.setState({ open: true });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
handleClose() {
|
|
65
|
+
this.setState({ open: false });
|
|
66
|
+
if (this.props.onClose) {
|
|
67
|
+
this.props.onClose();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async redditConnect() {
|
|
72
|
+
this.setState({ isConnecting: true });
|
|
73
|
+
|
|
74
|
+
// TIER 2: Require user JWT for OAuth connections
|
|
75
|
+
if (!isUserAuthenticated()) {
|
|
76
|
+
console.error('[Reddit] User not authenticated - cannot connect');
|
|
77
|
+
this.setState({ isConnecting: false });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const resolvedUsername =
|
|
83
|
+
(typeof this.props.username === 'string' && this.props.username.trim().length > 0 ? this.props.username.trim() : '') ||
|
|
84
|
+
(typeof localStorage !== 'undefined' ? (localStorage.getItem('username') || '') : '') ||
|
|
85
|
+
(() => {
|
|
86
|
+
try {
|
|
87
|
+
const user = JSON.parse(localStorage.getItem('onairosUser') || '{}');
|
|
88
|
+
return user?.email || user?.username || '';
|
|
89
|
+
} catch {
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
})();
|
|
93
|
+
|
|
94
|
+
if (!resolvedUsername) {
|
|
95
|
+
throw new Error('Missing username/email for Reddit OAuth');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const isMobile =
|
|
99
|
+
typeof navigator !== 'undefined' &&
|
|
100
|
+
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
101
|
+
|
|
102
|
+
const returnUrl = isMobile && typeof window !== 'undefined'
|
|
103
|
+
? window.location.href
|
|
104
|
+
: '';
|
|
105
|
+
|
|
106
|
+
const bodyPayload = {
|
|
107
|
+
session: {
|
|
108
|
+
username: resolvedUsername,
|
|
109
|
+
...(isMobile ? { sdkType: 'web', returnUrl } : {}),
|
|
110
|
+
},
|
|
111
|
+
Info: { username: resolvedUsername },
|
|
112
|
+
OnairosUsername: resolvedUsername,
|
|
113
|
+
username: resolvedUsername,
|
|
114
|
+
...(isMobile ? { returnUrl } : {}),
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const userHeaders = getUserAuthHeaders();
|
|
118
|
+
const developerHeaders = getDeveloperAuthHeaders();
|
|
119
|
+
const headers = {
|
|
120
|
+
...userHeaders,
|
|
121
|
+
...(developerHeaders?.Authorization ? { 'x-api-key': developerHeaders.Authorization.replace(/^Bearer\s+/i, '') } : {}),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const response = await fetch(`${API_CONFIG.getBaseUrl()}/reddit/authorize`, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
headers,
|
|
127
|
+
body: JSON.stringify(bodyPayload),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (!response.ok) {
|
|
131
|
+
let errorText = '';
|
|
132
|
+
try {
|
|
133
|
+
const json = await response.json();
|
|
134
|
+
errorText = json?.error || json?.message || '';
|
|
135
|
+
} catch {
|
|
136
|
+
try {
|
|
137
|
+
errorText = await response.text();
|
|
138
|
+
} catch {
|
|
139
|
+
errorText = '';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
throw new Error(errorText || `Reddit authorize failed (${response.status})`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const result = await response.json();
|
|
146
|
+
|
|
147
|
+
const redditUrl =
|
|
148
|
+
result.redditURL ||
|
|
149
|
+
result.redditUrl ||
|
|
150
|
+
result.reddit_url ||
|
|
151
|
+
result.authUrl ||
|
|
152
|
+
result.url;
|
|
153
|
+
|
|
154
|
+
if (redditUrl) {
|
|
155
|
+
window.location.href = redditUrl;
|
|
156
|
+
} else {
|
|
157
|
+
console.error('No Reddit URL received');
|
|
158
|
+
this.setState({ isConnecting: false });
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error('Reddit connection error:', error);
|
|
162
|
+
this.setState({ isConnecting: false });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
render() {
|
|
167
|
+
const { open = this.props.open || this.state.open } = this.props;
|
|
168
|
+
|
|
169
|
+
if (!open) return null;
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[2147483647]">
|
|
173
|
+
<div className="bg-white rounded-lg shadow-xl max-w-md w-full mx-4 max-h-full md:max-h-[90vh] overflow-hidden">
|
|
174
|
+
<div className="p-6">
|
|
175
|
+
<h2 className="text-xl font-bold text-gray-900 mb-4">
|
|
176
|
+
Grant Onairos Access to your Reddit Account?
|
|
177
|
+
</h2>
|
|
178
|
+
|
|
179
|
+
<div className="space-y-4 text-gray-700">
|
|
180
|
+
<p>
|
|
181
|
+
Grant Permission to your Reddit Account, so we can build your Data Models.
|
|
182
|
+
</p>
|
|
183
|
+
|
|
184
|
+
<div>
|
|
185
|
+
<p className="font-medium mb-2">We will access your Reddit:</p>
|
|
186
|
+
<ul className="list-disc ml-6 space-y-1">
|
|
187
|
+
<li>Basic Profile Information</li>
|
|
188
|
+
<li>Posts and Comments</li>
|
|
189
|
+
<li>Upvoted and Saved Content</li>
|
|
190
|
+
<li>Subscribed Subreddits</li>
|
|
191
|
+
</ul>
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<p>
|
|
195
|
+
We will delete all the data used once your Model is Created
|
|
196
|
+
</p>
|
|
197
|
+
|
|
198
|
+
<p className="text-sm">
|
|
199
|
+
<a href="https://onairos.uk/privacy-policy" className="text-blue-600 hover:underline">
|
|
200
|
+
Onairos Privacy Policy
|
|
201
|
+
</a>{' '}
|
|
202
|
+
- Your Reddit activity helps us understand your interests and preferences.
|
|
203
|
+
</p>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<div className="flex space-x-3 mt-6">
|
|
207
|
+
<button
|
|
208
|
+
onClick={this.handleClose}
|
|
209
|
+
disabled={this.state.isConnecting}
|
|
210
|
+
className="flex-1 px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 disabled:opacity-50"
|
|
211
|
+
>
|
|
212
|
+
Disagree
|
|
213
|
+
</button>
|
|
214
|
+
<button
|
|
215
|
+
onClick={this.redditConnect}
|
|
216
|
+
disabled={this.state.isConnecting}
|
|
217
|
+
className="flex-1 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50"
|
|
218
|
+
>
|
|
219
|
+
{this.state.isConnecting ? 'Connecting...' : 'Agree'}
|
|
220
|
+
</button>
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export default RedditConnector;
|