@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,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Header Utilities
|
|
3
|
+
* Provides consistent auth headers across the SDK
|
|
4
|
+
*
|
|
5
|
+
* TWO-TIER AUTHENTICATION:
|
|
6
|
+
* - TIER 1: Developer API Key (for registration/login routes)
|
|
7
|
+
* - TIER 2: User JWT Token (for post-login user actions)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the current user's JWT token
|
|
12
|
+
* @returns {string|null} The JWT token or null if not found
|
|
13
|
+
*/
|
|
14
|
+
export const getUserToken = () => {
|
|
15
|
+
try {
|
|
16
|
+
// Try direct token storage first
|
|
17
|
+
const directToken = localStorage.getItem('onairos_user_token');
|
|
18
|
+
if (directToken) return directToken;
|
|
19
|
+
const jwtToken = localStorage.getItem('onairos_jwt_token');
|
|
20
|
+
if (jwtToken) return jwtToken;
|
|
21
|
+
|
|
22
|
+
// Try onairosUser object
|
|
23
|
+
const userData = JSON.parse(localStorage.getItem('onairosUser') || '{}');
|
|
24
|
+
if (userData.token) return userData.token;
|
|
25
|
+
if (userData.jwt) return userData.jwt;
|
|
26
|
+
if (userData.jwtToken) return userData.jwtToken;
|
|
27
|
+
|
|
28
|
+
return null;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.error('[Onairos] Error getting user token:', e);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get the developer API key
|
|
37
|
+
* @returns {string|null} The API key or null if not found
|
|
38
|
+
*/
|
|
39
|
+
export const getApiKey = () => {
|
|
40
|
+
const pickValid = (value) => {
|
|
41
|
+
const normalized = String(value || '').trim();
|
|
42
|
+
if (!normalized || normalized === 'undefined' || normalized === 'null') return null;
|
|
43
|
+
return normalized;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const envKey = (() => {
|
|
47
|
+
try {
|
|
48
|
+
if (typeof process === 'undefined' || !process?.env) return null;
|
|
49
|
+
return (
|
|
50
|
+
pickValid(process.env.REACT_APP_ONAIROS_API_KEY) ||
|
|
51
|
+
pickValid(process.env.VITE_ONAIROS_API_KEY) ||
|
|
52
|
+
pickValid(process.env.ONAIROS_API_KEY) ||
|
|
53
|
+
null
|
|
54
|
+
);
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
})();
|
|
59
|
+
|
|
60
|
+
const windowKey = (() => {
|
|
61
|
+
try {
|
|
62
|
+
if (typeof window === 'undefined') return null;
|
|
63
|
+
return (
|
|
64
|
+
pickValid(window.onairosApiKey) ||
|
|
65
|
+
pickValid(window.ONAIROS_API_KEY) ||
|
|
66
|
+
pickValid(window.VITE_ONAIROS_API_KEY) ||
|
|
67
|
+
pickValid(window.__ONAIROS_API_KEY__) ||
|
|
68
|
+
null
|
|
69
|
+
);
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
|
|
75
|
+
const storageKey = (() => {
|
|
76
|
+
try {
|
|
77
|
+
if (typeof localStorage === 'undefined') return null;
|
|
78
|
+
return (
|
|
79
|
+
pickValid(localStorage.getItem('onairos_api_key')) ||
|
|
80
|
+
pickValid(localStorage.getItem('onairosApiKey')) ||
|
|
81
|
+
pickValid(localStorage.getItem('ONAIROS_API_KEY')) ||
|
|
82
|
+
null
|
|
83
|
+
);
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
})();
|
|
88
|
+
|
|
89
|
+
const chosen = windowKey || storageKey || envKey || null;
|
|
90
|
+
|
|
91
|
+
// Keep all common locations in sync to reduce auth flakiness across host apps.
|
|
92
|
+
if (chosen) {
|
|
93
|
+
try {
|
|
94
|
+
if (typeof window !== 'undefined') {
|
|
95
|
+
window.onairosApiKey = chosen;
|
|
96
|
+
}
|
|
97
|
+
} catch (_) {}
|
|
98
|
+
try {
|
|
99
|
+
if (typeof localStorage !== 'undefined') {
|
|
100
|
+
localStorage.setItem('onairos_api_key', chosen);
|
|
101
|
+
}
|
|
102
|
+
} catch (_) {}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return chosen;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get headers for TIER 1 requests (registration/login)
|
|
110
|
+
* Uses Developer API Key
|
|
111
|
+
* @returns {Object} Headers object with Content-Type and Authorization
|
|
112
|
+
*/
|
|
113
|
+
export const getDeveloperAuthHeaders = () => {
|
|
114
|
+
const apiKey = getApiKey();
|
|
115
|
+
if (!apiKey) {
|
|
116
|
+
console.warn('[Onairos] No API key configured');
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
'Content-Type': 'application/json',
|
|
120
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` }),
|
|
121
|
+
...(apiKey && { 'x-api-key': apiKey }),
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get headers for TIER 2 requests (post-login user actions)
|
|
127
|
+
* Uses User JWT Token
|
|
128
|
+
* @returns {Object} Headers object with Content-Type and Authorization
|
|
129
|
+
*/
|
|
130
|
+
export const getUserAuthHeaders = () => {
|
|
131
|
+
const userToken = getUserToken();
|
|
132
|
+
const apiKey = getApiKey();
|
|
133
|
+
if (!userToken) {
|
|
134
|
+
console.warn('[Onairos] No user token found - user may not be logged in');
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
'Content-Type': 'application/json',
|
|
138
|
+
...(userToken && { 'Authorization': `Bearer ${userToken}` }),
|
|
139
|
+
// Many post-login "connector" endpoints also require the developer API key.
|
|
140
|
+
...(apiKey && { 'x-api-key': apiKey }),
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Endpoints that now require a user JWT token.
|
|
146
|
+
* These are evaluated by path substring matching.
|
|
147
|
+
*/
|
|
148
|
+
const JWT_REQUIRED_ENDPOINTS = [
|
|
149
|
+
'/sendModel',
|
|
150
|
+
'/updateAccountInfo',
|
|
151
|
+
'/api/signed-url',
|
|
152
|
+
'/inferenceUsername',
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Check whether an endpoint requires JWT authentication.
|
|
157
|
+
* @param {string} endpoint
|
|
158
|
+
* @returns {boolean}
|
|
159
|
+
*/
|
|
160
|
+
export const isJwtRequiredEndpoint = (endpoint = '') => {
|
|
161
|
+
const path = String(endpoint || '');
|
|
162
|
+
return JWT_REQUIRED_ENDPOINTS.some((requiredPath) => path.includes(requiredPath));
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Build user auth headers with optional strict token enforcement.
|
|
167
|
+
* @param {Object} options
|
|
168
|
+
* @param {boolean} [options.requireToken=false] - throw if token is missing
|
|
169
|
+
* @param {boolean} [options.includeApiKey=true] - include x-api-key for compatibility endpoints
|
|
170
|
+
* @param {boolean} [options.includeContentType=true] - include JSON content type
|
|
171
|
+
* @returns {Object}
|
|
172
|
+
*/
|
|
173
|
+
export const getRequiredUserAuthHeaders = (options = {}) => {
|
|
174
|
+
const {
|
|
175
|
+
requireToken = false,
|
|
176
|
+
includeApiKey = true,
|
|
177
|
+
includeContentType = true,
|
|
178
|
+
} = options;
|
|
179
|
+
|
|
180
|
+
const userToken = getUserToken();
|
|
181
|
+
const apiKey = includeApiKey ? getApiKey() : null;
|
|
182
|
+
|
|
183
|
+
if (requireToken && !userToken) {
|
|
184
|
+
const error = new Error('Authentication required. User JWT token is missing.');
|
|
185
|
+
error.code = 'AUTHENTICATION_REQUIRED';
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const headers = {
|
|
190
|
+
...(includeContentType ? { 'Content-Type': 'application/json' } : {}),
|
|
191
|
+
...(userToken ? { 'Authorization': `Bearer ${userToken}` } : {}),
|
|
192
|
+
...(apiKey ? { 'x-api-key': apiKey } : {}),
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
return headers;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Handle unauthorized responses consistently across SDK surfaces.
|
|
200
|
+
* @param {Response|{status:number}} response
|
|
201
|
+
* @param {Object} options
|
|
202
|
+
* @param {boolean} [options.clearToken=true]
|
|
203
|
+
* @param {Function|null} [options.onTokenExpired=null]
|
|
204
|
+
* @returns {boolean} true when unauthorized was handled
|
|
205
|
+
*/
|
|
206
|
+
export const handleUnauthorizedResponse = (response, options = {}) => {
|
|
207
|
+
const { clearToken = true, onTokenExpired = null } = options;
|
|
208
|
+
if (!response || response.status !== 401) return false;
|
|
209
|
+
|
|
210
|
+
if (clearToken) {
|
|
211
|
+
try { clearUserToken(); } catch (_) {}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
if (typeof window !== 'undefined') {
|
|
216
|
+
window.dispatchEvent(new CustomEvent('onairos-auth-expired', {
|
|
217
|
+
detail: { status: 401, code: 'AUTHENTICATION_REQUIRED' }
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
} catch (_) {}
|
|
221
|
+
|
|
222
|
+
try { onTokenExpired?.(); } catch (_) {}
|
|
223
|
+
return true;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Check if user is authenticated (has a valid token)
|
|
228
|
+
* @returns {boolean} True if user has a token
|
|
229
|
+
*/
|
|
230
|
+
export const isUserAuthenticated = () => {
|
|
231
|
+
return !!getUserToken();
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Store the user token after successful authentication
|
|
236
|
+
* @param {string} token - The JWT token to store
|
|
237
|
+
*/
|
|
238
|
+
export const setUserToken = (token) => {
|
|
239
|
+
if (token) {
|
|
240
|
+
localStorage.setItem('onairos_user_token', token);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* SDK-facing alias that matches migration guide naming.
|
|
246
|
+
* @param {string} token
|
|
247
|
+
*/
|
|
248
|
+
export const setToken = (token) => setUserToken(token);
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Clear the user token (logout)
|
|
252
|
+
*/
|
|
253
|
+
export const clearUserToken = () => {
|
|
254
|
+
localStorage.removeItem('onairos_user_token');
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* SDK-facing alias that matches migration guide naming.
|
|
259
|
+
*/
|
|
260
|
+
export const clearToken = () => clearUserToken();
|
|
261
|
+
|
|
262
|
+
export default {
|
|
263
|
+
getUserToken,
|
|
264
|
+
getApiKey,
|
|
265
|
+
getDeveloperAuthHeaders,
|
|
266
|
+
getUserAuthHeaders,
|
|
267
|
+
getRequiredUserAuthHeaders,
|
|
268
|
+
isJwtRequiredEndpoint,
|
|
269
|
+
handleUnauthorizedResponse,
|
|
270
|
+
isUserAuthenticated,
|
|
271
|
+
setUserToken,
|
|
272
|
+
setToken,
|
|
273
|
+
clearUserToken,
|
|
274
|
+
clearToken,
|
|
275
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const authenticateWithBiometrics = async () => {
|
|
2
|
+
if (!window.PublicKeyCredential) {
|
|
3
|
+
throw new Error('WebAuthn not supported');
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const supported = await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
|
|
8
|
+
if (!supported) {
|
|
9
|
+
throw new Error('Biometric authentication not available');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Trigger FaceID/TouchID
|
|
13
|
+
const credential = await navigator.credentials.get({
|
|
14
|
+
publicKey: {
|
|
15
|
+
challenge: new Uint8Array(32),
|
|
16
|
+
rpId: window.location.hostname,
|
|
17
|
+
userVerification: 'required',
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return !!credential;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error('Biometric authentication failed:', error);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bookmarklet utilities
|
|
3
|
+
*
|
|
4
|
+
* Some browsers/bookmark managers truncate or corrupt `javascript:` URLs when they contain
|
|
5
|
+
* literal newlines/indentation. This helper collapses whitespace so the bookmarklet is a
|
|
6
|
+
* single line, which avoids `Unexpected end of input` failures.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Build a safe `javascript:` href for use in an <a href="..."> bookmarklet link.
|
|
11
|
+
* - Ensures a single `javascript:` prefix
|
|
12
|
+
* - Collapses ALL whitespace (including newlines) into single spaces
|
|
13
|
+
*/
|
|
14
|
+
export function buildBookmarkletHref(rawCode) {
|
|
15
|
+
if (!rawCode) return '';
|
|
16
|
+
|
|
17
|
+
let code = String(rawCode).trim();
|
|
18
|
+
|
|
19
|
+
// Avoid duplicate prefixes and tolerate accidental whitespace after the scheme.
|
|
20
|
+
code = code.replace(/^javascript:\s*/i, '');
|
|
21
|
+
|
|
22
|
+
// Collapse newlines/tabs/indentation. (We only embed `\\n` inside JS strings, not real newlines.)
|
|
23
|
+
code = code.replace(/\s+/g, ' ');
|
|
24
|
+
|
|
25
|
+
return `javascript:${code}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capacitor/Mobile Environment Detection Utility
|
|
3
|
+
*
|
|
4
|
+
* Detects if the app is running in a Capacitor environment
|
|
5
|
+
* and provides mobile-specific functionality
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Detect if running in Capacitor environment
|
|
10
|
+
* @returns {boolean} True if running in Capacitor
|
|
11
|
+
*/
|
|
12
|
+
export const isCapacitor = () => {
|
|
13
|
+
// Check for Capacitor global object
|
|
14
|
+
if (typeof window !== 'undefined' && window.Capacitor) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Check for Capacitor plugins
|
|
19
|
+
if (typeof window !== 'undefined' && window.Capacitor?.Plugins) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Check for Capacitor native bridge
|
|
24
|
+
if (typeof window !== 'undefined' && window.webkit?.messageHandlers?.bridge) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Detect if running in React Native environment
|
|
33
|
+
* @returns {boolean} True if running in React Native
|
|
34
|
+
*/
|
|
35
|
+
export const isReactNative = () => {
|
|
36
|
+
return typeof navigator !== 'undefined' && navigator.product === 'ReactNative' ||
|
|
37
|
+
typeof global !== 'undefined' && global.nativeModuleProxy !== undefined;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Detect if running in any mobile app environment (Capacitor or React Native)
|
|
42
|
+
* @returns {boolean} True if running in a mobile app
|
|
43
|
+
*/
|
|
44
|
+
export const isMobileApp = () => {
|
|
45
|
+
return isCapacitor() || isReactNative();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Detect if running on iOS
|
|
50
|
+
* @returns {boolean} True if running on iOS
|
|
51
|
+
*/
|
|
52
|
+
export const isIOS = () => {
|
|
53
|
+
if (typeof window !== 'undefined' && window.Capacitor) {
|
|
54
|
+
return window.Capacitor.getPlatform() === 'ios';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Fallback to user agent detection
|
|
58
|
+
return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Detect if running on Android
|
|
63
|
+
* @returns {boolean} True if running on Android
|
|
64
|
+
*/
|
|
65
|
+
export const isAndroid = () => {
|
|
66
|
+
if (typeof window !== 'undefined' && window.Capacitor) {
|
|
67
|
+
return window.Capacitor.getPlatform() === 'android';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Fallback to user agent detection
|
|
71
|
+
return /Android/.test(navigator.userAgent);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get platform information
|
|
76
|
+
* @returns {Object} Platform details
|
|
77
|
+
*/
|
|
78
|
+
export const getPlatformInfo = () => {
|
|
79
|
+
return {
|
|
80
|
+
isCapacitor: isCapacitor(),
|
|
81
|
+
isReactNative: isReactNative(),
|
|
82
|
+
isMobileApp: isMobileApp(),
|
|
83
|
+
isIOS: isIOS(),
|
|
84
|
+
isAndroid: isAndroid(),
|
|
85
|
+
platform: window.Capacitor ? window.Capacitor.getPlatform() : 'web',
|
|
86
|
+
userAgent: navigator.userAgent
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Detect if mobile browser (not Capacitor, just mobile web browser)
|
|
92
|
+
* @returns {boolean} True if mobile browser
|
|
93
|
+
*/
|
|
94
|
+
export const isMobileBrowser = () => {
|
|
95
|
+
if (isMobileApp()) {
|
|
96
|
+
return false; // Capacitor/RN apps are not browsers
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ||
|
|
100
|
+
(window.innerWidth <= 768);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Get environment type
|
|
105
|
+
* @returns {string} Environment type: 'capacitor', 'react-native', 'mobile-browser', 'desktop-browser'
|
|
106
|
+
*/
|
|
107
|
+
export const getEnvironmentType = () => {
|
|
108
|
+
if (isCapacitor()) return 'capacitor';
|
|
109
|
+
if (isReactNative()) return 'react-native';
|
|
110
|
+
if (isMobileBrowser()) return 'mobile-browser';
|
|
111
|
+
return 'desktop-browser';
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Check if browser extension support is available
|
|
116
|
+
* Browser extensions don't work in Capacitor/React Native
|
|
117
|
+
* @returns {boolean} True if browser extensions are supported
|
|
118
|
+
*/
|
|
119
|
+
export const supportsBrowserExtensions = () => {
|
|
120
|
+
return !isMobileApp();
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Log platform information for debugging
|
|
125
|
+
*/
|
|
126
|
+
export const logPlatformInfo = () => {
|
|
127
|
+
const info = getPlatformInfo();
|
|
128
|
+
console.log('🔍 Platform Detection:', info);
|
|
129
|
+
console.log('📱 Environment Type:', getEnvironmentType());
|
|
130
|
+
console.log('🧩 Browser Extensions Supported:', supportsBrowserExtensions());
|
|
131
|
+
return info;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Detect if running in an in-app browser (WebView within another app)
|
|
136
|
+
* These have isolated storage from the main browser
|
|
137
|
+
* @returns {Object} { isInAppBrowser: boolean, app: string | null }
|
|
138
|
+
*/
|
|
139
|
+
export const detectInAppBrowser = () => {
|
|
140
|
+
if (typeof navigator === 'undefined') {
|
|
141
|
+
return { isInAppBrowser: false, app: null };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const ua = navigator.userAgent || '';
|
|
145
|
+
|
|
146
|
+
// Facebook in-app browser
|
|
147
|
+
if (/FBAN|FBAV|FB_IAB|FBIOS|FBLC/i.test(ua)) {
|
|
148
|
+
return { isInAppBrowser: true, app: 'facebook' };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Instagram in-app browser
|
|
152
|
+
if (/Instagram/i.test(ua)) {
|
|
153
|
+
return { isInAppBrowser: true, app: 'instagram' };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Twitter/X in-app browser
|
|
157
|
+
if (/Twitter/i.test(ua)) {
|
|
158
|
+
return { isInAppBrowser: true, app: 'twitter' };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// LinkedIn in-app browser
|
|
162
|
+
if (/LinkedIn/i.test(ua)) {
|
|
163
|
+
return { isInAppBrowser: true, app: 'linkedin' };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// TikTok in-app browser
|
|
167
|
+
if (/TikTok|BytedanceWebview|ByteLocale/i.test(ua)) {
|
|
168
|
+
return { isInAppBrowser: true, app: 'tiktok' };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Snapchat in-app browser
|
|
172
|
+
if (/Snapchat/i.test(ua)) {
|
|
173
|
+
return { isInAppBrowser: true, app: 'snapchat' };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Pinterest in-app browser
|
|
177
|
+
if (/Pinterest/i.test(ua)) {
|
|
178
|
+
return { isInAppBrowser: true, app: 'pinterest' };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// WeChat in-app browser
|
|
182
|
+
if (/MicroMessenger/i.test(ua)) {
|
|
183
|
+
return { isInAppBrowser: true, app: 'wechat' };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// LINE in-app browser
|
|
187
|
+
if (/Line\//i.test(ua)) {
|
|
188
|
+
return { isInAppBrowser: true, app: 'line' };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Generic WebView detection (iOS and Android)
|
|
192
|
+
// These are less reliable but catch some edge cases
|
|
193
|
+
const isGenericWebView =
|
|
194
|
+
// iOS WKWebView without Safari
|
|
195
|
+
(/iPhone|iPad|iPod/.test(ua) && !/Safari/i.test(ua)) ||
|
|
196
|
+
// Android WebView
|
|
197
|
+
(/Android/.test(ua) && /wv/.test(ua)) ||
|
|
198
|
+
// Android Chrome in-app (without Chrome version indicates WebView)
|
|
199
|
+
(/Android/.test(ua) && /Chrome/.test(ua) && !/SamsungBrowser|Brave|Firefox|Edge|Opera|Vivaldi/.test(ua) && /Version\//.test(ua));
|
|
200
|
+
|
|
201
|
+
if (isGenericWebView) {
|
|
202
|
+
return { isInAppBrowser: true, app: 'unknown' };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return { isInAppBrowser: false, app: null };
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Check if current browser is Safari on iOS
|
|
210
|
+
* Safari has strict ITP (Intelligent Tracking Prevention) that affects storage
|
|
211
|
+
* @returns {boolean} True if iOS Safari
|
|
212
|
+
*/
|
|
213
|
+
export const isIOSSafari = () => {
|
|
214
|
+
if (typeof navigator === 'undefined') return false;
|
|
215
|
+
|
|
216
|
+
const ua = navigator.userAgent || '';
|
|
217
|
+
const isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream;
|
|
218
|
+
const isSafari = /Safari/i.test(ua) && !/Chrome|CriOS|FxiOS|EdgiOS|OPiOS/i.test(ua);
|
|
219
|
+
|
|
220
|
+
return isIOS && isSafari;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Check if localStorage is fully functional
|
|
225
|
+
* Some browsers/modes restrict localStorage access
|
|
226
|
+
* @returns {boolean} True if localStorage is available and writable
|
|
227
|
+
*/
|
|
228
|
+
export const isLocalStorageAvailable = () => {
|
|
229
|
+
try {
|
|
230
|
+
const testKey = '__onairos_storage_test__';
|
|
231
|
+
localStorage.setItem(testKey, 'test');
|
|
232
|
+
const result = localStorage.getItem(testKey);
|
|
233
|
+
localStorage.removeItem(testKey);
|
|
234
|
+
return result === 'test';
|
|
235
|
+
} catch (e) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Check if cookies are available
|
|
242
|
+
* @returns {boolean} True if cookies are enabled
|
|
243
|
+
*/
|
|
244
|
+
export const areCookiesEnabled = () => {
|
|
245
|
+
try {
|
|
246
|
+
// Try to set a test cookie
|
|
247
|
+
document.cookie = '__onairos_cookie_test__=1; SameSite=Lax; path=/';
|
|
248
|
+
const cookieEnabled = document.cookie.indexOf('__onairos_cookie_test__') !== -1;
|
|
249
|
+
// Clean up
|
|
250
|
+
document.cookie = '__onairos_cookie_test__=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/';
|
|
251
|
+
return cookieEnabled;
|
|
252
|
+
} catch (e) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Get comprehensive mobile storage capability info
|
|
259
|
+
* @returns {Object} Storage capabilities
|
|
260
|
+
*/
|
|
261
|
+
export const getMobileStorageInfo = () => {
|
|
262
|
+
const inAppBrowser = detectInAppBrowser();
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
isMobileBrowser: isMobileBrowser(),
|
|
266
|
+
isIOSSafari: isIOSSafari(),
|
|
267
|
+
isInAppBrowser: inAppBrowser.isInAppBrowser,
|
|
268
|
+
inAppBrowserApp: inAppBrowser.app,
|
|
269
|
+
localStorageAvailable: isLocalStorageAvailable(),
|
|
270
|
+
cookiesEnabled: areCookiesEnabled(),
|
|
271
|
+
// Warn if storage is likely to be unreliable
|
|
272
|
+
storageWarning: inAppBrowser.isInAppBrowser
|
|
273
|
+
? `You're using an in-app browser (${inAppBrowser.app || 'unknown'}). For the best experience, open this page in Safari or Chrome.`
|
|
274
|
+
: null
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
|