@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.
Files changed (181) hide show
  1. package/LICENSE +194 -10
  2. package/README.md +182 -25
  3. package/dist/onairos.capacitor.esm.js +1 -0
  4. package/dist/onairos.capacitor.esm.turbopack.js +1 -0
  5. package/onairos.d.ts +656 -0
  6. package/package.json +186 -38
  7. package/src/OnairosReconnectButton.jsx +272 -0
  8. package/src/RSA.jsx +57 -0
  9. package/src/assets/NewLogo.png +0 -0
  10. package/src/assets/OnairosNewLogo.png +0 -0
  11. package/src/assets/chatgpt-icon.png +0 -0
  12. package/src/assets/fire-horse.png +0 -0
  13. package/src/assets/fire-horse.transparent.png +0 -0
  14. package/src/assets/latest-firehorse.png +0 -0
  15. package/src/assets/perplexity.png +0 -0
  16. package/src/assets/persona.png +0 -0
  17. package/src/assets/persona1.png +0 -0
  18. package/src/assets/persona2.png +0 -0
  19. package/src/assets/persona3.png +0 -0
  20. package/src/assets/persona4.png +0 -0
  21. package/src/assets/persona5.png +0 -0
  22. package/src/capacitorConnectorCatalog.js +38 -0
  23. package/src/capacitorOAuthConfig.js +52 -0
  24. package/src/chatgptHostedImport/index.js +303 -0
  25. package/src/components/AuthButtons.jsx +48 -0
  26. package/src/components/ConnectChatGPTModal.jsx +666 -0
  27. package/src/components/ConnectClaudeModal.jsx +610 -0
  28. package/src/components/ConnectGeminiModal.jsx +639 -0
  29. package/src/components/ConnectGrokModal.jsx +701 -0
  30. package/src/components/ConnectPerplexityModal.jsx +726 -0
  31. package/src/components/DataExplainerScreen.jsx +349 -0
  32. package/src/components/DataRequest.js +885 -0
  33. package/src/components/DataRequest.jsx +1055 -0
  34. package/src/components/EmailAuth.js +1871 -0
  35. package/src/components/EmailAuth.jsx +2062 -0
  36. package/src/components/ExtensionInstallPrompt.jsx +142 -0
  37. package/src/components/GoogleButton.js +133 -0
  38. package/src/components/LLMConnectorManager.jsx +201 -0
  39. package/src/components/LoadingPage.jsx +19 -0
  40. package/src/components/LoadingScreen.jsx +81 -0
  41. package/src/components/LunarBirthdate.jsx +96 -0
  42. package/src/components/LunarLoadingPage.jsx +251 -0
  43. package/src/components/Notification.jsx +21 -0
  44. package/src/components/OnairosAppButton.jsx +85 -0
  45. package/src/components/OnairosSSO.jsx +645 -0
  46. package/src/components/OnairosTrigger.jsx +61 -0
  47. package/src/components/PerplexityLogo.jsx +43 -0
  48. package/src/components/PinSetup.js +200 -0
  49. package/src/components/PinSetup.jsx +228 -0
  50. package/src/components/SDK_PIN_INTEGRATION_REQUIRED_CHANGES.md +526 -0
  51. package/src/components/SdkErrorBoundary.jsx +36 -0
  52. package/src/components/SecuritySetup.js +81 -0
  53. package/src/components/SessionUserBar.jsx +83 -0
  54. package/src/components/SignUp.js +123 -0
  55. package/src/components/TestTelegramButton.js +53 -0
  56. package/src/components/TrainingComponent.jsx +200 -0
  57. package/src/components/TrainingScreen.jsx +897 -0
  58. package/src/components/UniversalOnboarding.js +306 -0
  59. package/src/components/UniversalOnboarding.jsx +4837 -0
  60. package/src/components/ValentineLoadingPage.jsx +502 -0
  61. package/src/components/ValentineModeSelector.jsx +162 -0
  62. package/src/components/WelcomeScreen.jsx +435 -0
  63. package/src/components/WrappedLoadingPage.jsx +205 -0
  64. package/src/components/connectors/ChatGPTConnector.js +348 -0
  65. package/src/components/connectors/ChatGPTConnector.jsx +348 -0
  66. package/src/components/connectors/ClaudeConnector.js +44 -0
  67. package/src/components/connectors/ClaudeConnector.jsx +44 -0
  68. package/src/components/connectors/GeminiConnector.js +170 -0
  69. package/src/components/connectors/GeminiConnector.jsx +170 -0
  70. package/src/components/connectors/GmailConnector.js +148 -0
  71. package/src/components/connectors/GmailConnector.jsx +148 -0
  72. package/src/components/connectors/GrokConnector.js +16 -0
  73. package/src/components/connectors/GrokConnector.jsx +16 -0
  74. package/src/components/connectors/HingeConnector.js +419 -0
  75. package/src/components/connectors/HingeConnector.jsx +419 -0
  76. package/src/components/connectors/InstagramDataConnector.js +726 -0
  77. package/src/components/connectors/InstagramDataConnector.jsx +726 -0
  78. package/src/components/connectors/LinkedInConnector.js +4 -0
  79. package/src/components/connectors/LinkedInConnector.jsx +296 -0
  80. package/src/components/connectors/PerplexityConnector.jsx +16 -0
  81. package/src/components/connectors/PinterestConnector.js +208 -0
  82. package/src/components/connectors/PinterestConnector.jsx +208 -0
  83. package/src/components/connectors/README.md +292 -0
  84. package/src/components/connectors/RedditConnector.js +229 -0
  85. package/src/components/connectors/RedditConnector.jsx +229 -0
  86. package/src/components/connectors/SephoraConnector.js +482 -0
  87. package/src/components/connectors/SephoraConnector.jsx +482 -0
  88. package/src/components/connectors/TikTokConnector.jsx +430 -0
  89. package/src/components/connectors/YoutubeConnector.js +361 -0
  90. package/src/components/connectors/YoutubeConnector.jsx +361 -0
  91. package/src/components/connectors/index.js +50 -0
  92. package/src/components/icons.jsx +46 -0
  93. package/src/components/icons.tsx +21 -0
  94. package/src/components/ui/PageLayout.jsx +1255 -0
  95. package/src/components/ui/PrimaryButton.jsx +162 -0
  96. package/src/components/ui/button.jsx +49 -0
  97. package/src/components/ui/card.jsx +61 -0
  98. package/src/components/ui/checkbox.jsx +33 -0
  99. package/src/components/ui/label.jsx +29 -0
  100. package/src/components/utils/UpdateConnections.js +45 -0
  101. package/src/components/utils/oauthHelper.js +97 -0
  102. package/src/config/api-config.js +138 -0
  103. package/src/deepLink.jsx +38 -0
  104. package/src/getPin.js +26 -0
  105. package/src/icons/Avatar.png +0 -0
  106. package/src/icons/Sentiment.png +0 -0
  107. package/src/icons/Trait.png +0 -0
  108. package/src/iframe/DataRequestPage.jsx +285 -0
  109. package/src/iframe/OnairosButtonIntegration.md +148 -0
  110. package/src/iframe/components/Box.jsx +56 -0
  111. package/src/iframe/components/IndividualConnection.jsx +88 -0
  112. package/src/iframe/dataRequestHandler.js +714 -0
  113. package/src/iframe/data_request_iframe.html +27 -0
  114. package/src/iframe/data_request_page.js +47 -0
  115. package/src/iframe/icons/Avatar.png +1 -0
  116. package/src/iframe/icons/Avatar2.png +1 -0
  117. package/src/iframe/icons/Sentiment.png +1 -0
  118. package/src/iframe/icons/Trait.png +1 -0
  119. package/src/iframe/icons/onairos_logo.png +0 -0
  120. package/src/iframe/utils/api.js +57 -0
  121. package/src/index.js +274 -0
  122. package/src/laravel/OnairosVue.vue +410 -0
  123. package/src/laravel/blade-helpers.js +320 -0
  124. package/src/laravel/vite-plugin.js +179 -0
  125. package/src/mobile/MobileDataRequestPage.jsx +233 -0
  126. package/src/mobile/components/MobileBox.jsx +71 -0
  127. package/src/mobile/components/MobileIndividualConnection.jsx +51 -0
  128. package/src/mobile/shims/browser-apis.js +78 -0
  129. package/src/mobile/shims/lucide-shim.js +85 -0
  130. package/src/newUI/EMAIL_VERIFICATION_API_SCHEMA.md +268 -0
  131. package/src/newUI/PlatformConnectorsStep.tsx +435 -0
  132. package/src/newUI/PrimaryButton.tsx +213 -0
  133. package/src/newUI/SignInStep.tsx +194 -0
  134. package/src/newUI/VerificationStep.tsx +133 -0
  135. package/src/newUI/WelcomeScreen.tsx +311 -0
  136. package/src/newUI/services/connectedAccountsService.js +129 -0
  137. package/src/onairos.capacitor.jsx +16 -0
  138. package/src/onairos.core.jsx +133 -0
  139. package/src/onairos.jsx +14 -0
  140. package/src/onairos.native.jsx +15 -0
  141. package/src/onairosButton.jsx +9000 -0
  142. package/src/overlay/CheckBox.jsx +114 -0
  143. package/src/overlay/IndividualConnection copy.js +86 -0
  144. package/src/overlay/IndividualConnection.js +191 -0
  145. package/src/overlay/IndividualConnectionNew.jsx +157 -0
  146. package/src/overlay/box.js +84 -0
  147. package/src/overlay/overlay.js +437 -0
  148. package/src/styles/onairos-scoped-preflight.css +97 -0
  149. package/src/styles/sdkCssRegistry.js +20 -0
  150. package/src/styles/styleLoaderInsertShadow.js +69 -0
  151. package/src/styles/tailwind.capacitor.css +395 -0
  152. package/src/styles/tailwind.css +395 -0
  153. package/src/theme/colors.js +40 -0
  154. package/src/utils/apiKeyValidation.js +341 -0
  155. package/src/utils/apiResponseLogger.js +316 -0
  156. package/src/utils/authHeaders.js +275 -0
  157. package/src/utils/biometrics.js +26 -0
  158. package/src/utils/bookmarkletUtils.js +28 -0
  159. package/src/utils/capacitorDetection.js +278 -0
  160. package/src/utils/capacitorLLMHelper.js +352 -0
  161. package/src/utils/capacitorPlugins.js +366 -0
  162. package/src/utils/crossDomainSSO.js +587 -0
  163. package/src/utils/deepLinking.js +27 -0
  164. package/src/utils/devLogger.js +46 -0
  165. package/src/utils/extensionDetection.js +418 -0
  166. package/src/utils/extractMemory.js +277 -0
  167. package/src/utils/framerBrandingOverrides.js +40 -0
  168. package/src/utils/googleWebClientId.js +55 -0
  169. package/src/utils/overlayHandler.js +224 -0
  170. package/src/utils/platformDisconnect.js +309 -0
  171. package/src/utils/pollTrainingStatus.js +200 -0
  172. package/src/utils/rawMemoriesAccess.js +211 -0
  173. package/src/utils/resolveBackendAppId.js +47 -0
  174. package/src/utils/responseFormatter.js +140 -0
  175. package/src/utils/sdkDebugStorage.js +113 -0
  176. package/src/utils/sdkInitialization.js +645 -0
  177. package/src/utils/sessionManager.js +1258 -0
  178. package/src/utils/startBackgroundTraining.js +100 -0
  179. package/src/utils/userDataFormatter.js +222 -0
  180. package/index.d.ts +0 -1
  181. package/index.js +0 -1
@@ -0,0 +1,162 @@
1
+ import React, { useState } from 'react';
2
+ import { COLORS } from '../../theme/colors.js';
3
+
4
+ // Icon Circle component matching the React Native version
5
+ const IconCircle = ({
6
+ size = 40,
7
+ children,
8
+ className = ''
9
+ }) => {
10
+ return (
11
+ <div
12
+ className={`relative flex items-center justify-center border border-black border-opacity-25 ${className}`}
13
+ style={{
14
+ width: size,
15
+ height: size,
16
+ borderRadius: size / 2,
17
+ background: `linear-gradient(to bottom, ${COLORS.iconCircleGradientStart}, ${COLORS.iconCircleGradientEnd})`
18
+ }}
19
+ >
20
+ {children || (
21
+ <span
22
+ className="font-semibold opacity-95"
23
+ style={{
24
+ fontSize: '20px',
25
+ color: COLORS.btnLabel,
26
+ backgroundColor: 'transparent',
27
+ fontFamily: 'Inter, system-ui, sans-serif'
28
+ }}
29
+ >
30
+ →
31
+ </span>
32
+ )}
33
+ </div>
34
+ );
35
+ };
36
+
37
+ // Primary Button component matching the React Native design
38
+ const PrimaryButton = ({
39
+ label = "Get Started",
40
+ onClick,
41
+ iconRight,
42
+ loading = false,
43
+ disabled = false,
44
+ testId,
45
+ className = '',
46
+ style = {},
47
+ textStyle = {},
48
+ centered = false,
49
+ ...props
50
+ }) => {
51
+ const [pressed, setPressed] = useState(false);
52
+
53
+ const handleMouseDown = () => setPressed(true);
54
+ const handleMouseUp = () => setPressed(false);
55
+ const handleMouseLeave = () => setPressed(false);
56
+
57
+ const buttonStyle = {
58
+ height: '48px',
59
+ borderRadius: '100px',
60
+ border: `1px solid ${COLORS.btnBorder}`,
61
+ background: `linear-gradient(to bottom, ${COLORS.btnGradStart}, ${COLORS.btnGradEnd})`,
62
+ backgroundColor: COLORS.btnGradEnd, // fallback if gradients are stripped
63
+ position: 'relative',
64
+ overflow: 'hidden',
65
+ width: centered ? 'auto' : '100%',
66
+ minWidth: centered ? '250px' : 'auto',
67
+ maxWidth: centered ? '350px' : 'none',
68
+ margin: centered ? '0 auto' : '0',
69
+ cursor: disabled ? 'not-allowed' : 'pointer',
70
+ opacity: disabled ? 0.65 : 1,
71
+ boxShadow: disabled ? 'none' : '20px 30px 40px rgba(0,0,0,0.10)',
72
+ transition: 'all 0.2s ease',
73
+ appearance: 'none',
74
+ WebkitAppearance: 'none',
75
+ ...style
76
+ };
77
+
78
+ const pressedOverlayStyle = {
79
+ position: 'absolute',
80
+ top: 0,
81
+ left: 0,
82
+ right: 0,
83
+ bottom: 0,
84
+ backgroundColor: 'rgba(0,0,0,0.1)',
85
+ borderRadius: '100px',
86
+ opacity: pressed ? 1 : 0,
87
+ transition: 'opacity 0.1s ease'
88
+ };
89
+
90
+ const textContainerStyle = {
91
+ position: 'absolute',
92
+ left: 0,
93
+ right: 0,
94
+ top: 0,
95
+ bottom: 0,
96
+ display: 'flex',
97
+ justifyContent: 'center',
98
+ alignItems: 'center',
99
+ backgroundColor: 'transparent'
100
+ };
101
+
102
+ const iconPositionStyle = {
103
+ position: 'absolute',
104
+ right: '4px',
105
+ top: '4px',
106
+ bottom: '4px',
107
+ width: '40px',
108
+ display: 'flex',
109
+ justifyContent: 'center',
110
+ alignItems: 'center',
111
+ backgroundColor: 'transparent'
112
+ };
113
+
114
+ const labelStyle = {
115
+ fontFamily: 'Inter, system-ui, sans-serif',
116
+ fontWeight: '600',
117
+ fontSize: '16px',
118
+ color: COLORS.btnLabel,
119
+ WebkitTextFillColor: COLORS.btnLabel,
120
+ textAlign: 'center',
121
+ backgroundColor: 'transparent',
122
+ ...textStyle
123
+ };
124
+
125
+ return (
126
+ <button
127
+ className={`relative ${className}`}
128
+ style={buttonStyle}
129
+ onClick={onClick}
130
+ onMouseDown={handleMouseDown}
131
+ onMouseUp={handleMouseUp}
132
+ onMouseLeave={handleMouseLeave}
133
+ disabled={disabled || loading}
134
+ data-testid={testId}
135
+ aria-label={label}
136
+ {...props}
137
+ >
138
+ {/* Pressed state overlay */}
139
+ <div style={pressedOverlayStyle} />
140
+
141
+ {/* Centered text container */}
142
+ <div style={textContainerStyle}>
143
+ {loading ? (
144
+ <div
145
+ className="animate-spin rounded-full border-2 border-white border-t-transparent"
146
+ style={{ width: '20px', height: '20px' }}
147
+ />
148
+ ) : (
149
+ <span style={labelStyle}>{label}</span>
150
+ )}
151
+ </div>
152
+
153
+ {/* Icon in fixed position on right */}
154
+ <div style={iconPositionStyle}>
155
+ {!loading && (iconRight || <IconCircle />)}
156
+ </div>
157
+ </button>
158
+ );
159
+ };
160
+
161
+ export { IconCircle };
162
+ export default PrimaryButton;
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Button Component
5
+ * A customizable button component with various style variants
6
+ */
7
+ export function Button({
8
+ children,
9
+ className = '',
10
+ variant = 'default',
11
+ size = 'default',
12
+ onClick,
13
+ disabled = false,
14
+ ...props
15
+ }) {
16
+ // Base classes
17
+ const baseClasses = 'inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none';
18
+
19
+ // Size classes
20
+ const sizeClasses = {
21
+ default: 'h-10 py-2 px-4',
22
+ sm: 'h-9 px-3',
23
+ lg: 'h-11 px-8',
24
+ };
25
+
26
+ // Variant classes
27
+ const variantClasses = {
28
+ default: 'bg-black text-white hover:bg-black/90',
29
+ outline: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
30
+ secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
31
+ ghost: 'hover:bg-accent hover:text-accent-foreground',
32
+ link: 'underline-offset-4 hover:underline text-primary',
33
+ };
34
+
35
+ const classes = `${baseClasses} ${sizeClasses[size]} ${variantClasses[variant]} ${className}`;
36
+
37
+ return (
38
+ <button
39
+ className={classes}
40
+ onClick={onClick}
41
+ disabled={disabled}
42
+ {...props}
43
+ >
44
+ {children}
45
+ </button>
46
+ );
47
+ }
48
+
49
+ export default Button;
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Card Component
5
+ * A container component with various parts for creating card-based UIs
6
+ */
7
+ export function Card({ className = '', ...props }) {
8
+ return (
9
+ <div
10
+ className={`rounded-lg border bg-card text-card-foreground shadow-sm ${className}`}
11
+ {...props}
12
+ />
13
+ );
14
+ }
15
+
16
+ export function CardHeader({ className = '', ...props }) {
17
+ return (
18
+ <div
19
+ className={`flex flex-col space-y-1.5 p-6 ${className}`}
20
+ {...props}
21
+ />
22
+ );
23
+ }
24
+
25
+ export function CardTitle({ className = '', ...props }) {
26
+ return (
27
+ <h3
28
+ className={`text-lg font-semibold leading-none tracking-tight ${className}`}
29
+ {...props}
30
+ />
31
+ );
32
+ }
33
+
34
+ export function CardDescription({ className = '', ...props }) {
35
+ return (
36
+ <p
37
+ className={`text-sm text-muted-foreground ${className}`}
38
+ {...props}
39
+ />
40
+ );
41
+ }
42
+
43
+ export function CardContent({ className = '', ...props }) {
44
+ return (
45
+ <div
46
+ className={`p-6 pt-0 ${className}`}
47
+ {...props}
48
+ />
49
+ );
50
+ }
51
+
52
+ export function CardFooter({ className = '', ...props }) {
53
+ return (
54
+ <div
55
+ className={`flex items-center p-6 pt-0 ${className}`}
56
+ {...props}
57
+ />
58
+ );
59
+ }
60
+
61
+ export default Card;
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Checkbox Component
5
+ * A customizable checkbox component
6
+ */
7
+ export function Checkbox({
8
+ id,
9
+ className = '',
10
+ checked,
11
+ onCheckedChange,
12
+ disabled = false,
13
+ ...props
14
+ }) {
15
+ // Base classes
16
+ const baseClasses = 'peer h-4 w-4 shrink-0 rounded-sm border border-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground';
17
+
18
+ const classes = `${baseClasses} ${className}`;
19
+
20
+ return (
21
+ <input
22
+ type="checkbox"
23
+ id={id}
24
+ className={classes}
25
+ checked={checked}
26
+ onChange={(e) => onCheckedChange(e.target.checked)}
27
+ disabled={disabled}
28
+ {...props}
29
+ />
30
+ );
31
+ }
32
+
33
+ export default Checkbox;
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Label Component
5
+ * A customizable label component for form elements
6
+ */
7
+ export function Label({
8
+ htmlFor,
9
+ children,
10
+ className = '',
11
+ ...props
12
+ }) {
13
+ // Base classes
14
+ const baseClasses = 'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70';
15
+
16
+ const classes = `${baseClasses} ${className}`;
17
+
18
+ return (
19
+ <label
20
+ htmlFor={htmlFor}
21
+ className={classes}
22
+ {...props}
23
+ >
24
+ {children}
25
+ </label>
26
+ );
27
+ }
28
+
29
+ export default Label;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * UpdateConnections Utility
3
+ * Handles adding and removing user connections to/from the Onairos server
4
+ */
5
+
6
+ import { getApiBaseUrl } from '../../config/api-config.js';
7
+
8
+ /**
9
+ * Update user connections on the Onairos server
10
+ * @param {Object} options - Update options
11
+ * @param {string} options.updateType - 'Add' or 'Remove'
12
+ * @param {string} options.newConnection - The connection name to add/remove
13
+ * @param {string} options.username - Username (optional, will use localStorage if not provided)
14
+ * @returns {Promise} - Promise resolving with the server response
15
+ */
16
+ export default async function UpdateConnections({ updateType, newConnection, username = null }) {
17
+ const jsonData = {
18
+ session: {
19
+ username: username || localStorage.getItem("username")
20
+ },
21
+ updateType,
22
+ newConnection
23
+ };
24
+
25
+ try {
26
+ const response = await fetch(`${getApiBaseUrl()}/connections/update`, {
27
+ method: 'POST',
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ },
31
+ body: JSON.stringify(jsonData),
32
+ });
33
+
34
+ if (!response.ok) {
35
+ throw new Error(`HTTP error! status: ${response.status}`);
36
+ }
37
+
38
+ const result = await response.json();
39
+ console.log(`UpdateConnections: ${updateType} ${newConnection}`, result);
40
+ return result;
41
+ } catch (error) {
42
+ console.error('UpdateConnections error:', error);
43
+ throw error;
44
+ }
45
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * OAuth Helper Functions
3
+ * Provides utility functions for OAuth authentication
4
+ * Compatible with both web and React Native environments
5
+ */
6
+
7
+ /**
8
+ * Detect the runtime environment (React Native or Web)
9
+ * @returns {boolean} True if running in React Native
10
+ */
11
+ export const isReactNative = () => {
12
+ return typeof global !== 'undefined' && global.nativeModuleProxy !== undefined ||
13
+ typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
14
+ };
15
+
16
+ /**
17
+ * Create OAuth authorization window
18
+ * @param {string} url - OAuth URL to open
19
+ * @param {Object} options - Options for the OAuth window
20
+ * @returns {Promise} - Promise resolving with the auth result
21
+ */
22
+ export const createOAuthWindow = (url, options = {}) => {
23
+ return openAuthWindow(url, options);
24
+ };
25
+
26
+ /**
27
+ * Open OAuth authorization window
28
+ * Handles differences between web and React Native
29
+ * @param {string} url - OAuth URL to open
30
+ * @param {Object} options - Options for the OAuth window
31
+ * @returns {Promise} - Promise resolving with the auth result
32
+ */
33
+ export const openAuthWindow = (url, options = {}) => {
34
+ return new Promise((resolve, reject) => {
35
+ if (isReactNative()) {
36
+ // For React Native, we would typically use Linking API
37
+ // This is a placeholder - in real implementation, you would use
38
+ // react-native's Linking or a library like react-native-app-auth
39
+ console.log("OAuth in React Native environment would open:", url);
40
+
41
+ // Mock successful authentication for testing
42
+ setTimeout(() => {
43
+ resolve({
44
+ success: true,
45
+ token: 'mock-oauth-token-for-react-native'
46
+ });
47
+ }, 1000);
48
+ } else {
49
+ // Web implementation
50
+ const width = options.width || 600;
51
+ const height = options.height || 700;
52
+ const left = window.screen.width / 2 - width / 2;
53
+ const top = window.screen.height / 2 - height / 2;
54
+
55
+ const authWindow = window.open(
56
+ url,
57
+ 'Auth Window',
58
+ `width=${width},height=${height},top=${top},left=${left}`
59
+ );
60
+
61
+ // This would be implemented with message listeners in a real app
62
+ if (!authWindow) {
63
+ reject(new Error('Could not open auth window'));
64
+ }
65
+
66
+ // Mock auth for testing
67
+ setTimeout(() => {
68
+ resolve({
69
+ success: true,
70
+ token: 'mock-oauth-token-for-web'
71
+ });
72
+ }, 1000);
73
+ }
74
+ });
75
+ };
76
+
77
+ /**
78
+ * Handle OAuth callback
79
+ * @param {string} url - Callback URL with auth parameters
80
+ * @returns {Object} - Parsed auth result
81
+ */
82
+ export const handleOAuthCallback = (url) => {
83
+ // Parse URL parameters to extract token, etc.
84
+ const params = new URLSearchParams(url.split('?')[1]);
85
+ return {
86
+ token: params.get('token') || 'mock-token',
87
+ state: params.get('state'),
88
+ error: params.get('error')
89
+ };
90
+ };
91
+
92
+ export default {
93
+ isReactNative,
94
+ openAuthWindow,
95
+ createOAuthWindow,
96
+ handleOAuthCallback
97
+ };
@@ -0,0 +1,138 @@
1
+ /**
2
+ * API Configuration for Onairos
3
+ * Centralized configuration for API endpoints
4
+ *
5
+ * IMPORTANT: All API calls should use getApiBaseUrl() from this file
6
+ * to ensure proper routing for internship.onairos.uk -> api2.onairos.uk
7
+ */
8
+
9
+ // SSR-safe window check
10
+ const isBrowser = typeof window !== 'undefined';
11
+
12
+ // Environment detection (SSR-safe)
13
+ const getIsDevelopment = () => {
14
+ if (!isBrowser) return false;
15
+ return window.location.hostname === 'localhost' ||
16
+ window.location.hostname === '127.0.0.1' ||
17
+ window.location.port === '3000' ||
18
+ window.location.port === '5173' ||
19
+ window.location.port === '8080';
20
+ };
21
+
22
+ // Internship demo detection - uses configured API host
23
+ // Routes all requests to api2.onairos.uk when on internship.onairos.uk domain
24
+ const getIsInternshipDemo = () => {
25
+ if (!isBrowser) return false;
26
+ return window.location.hostname === 'internship.onairos.uk';
27
+ };
28
+
29
+ // Allow override via environment variable or window object
30
+ const getForceProduction = () => {
31
+ if (!isBrowser) return false;
32
+ return window.ONAIROS_FORCE_PRODUCTION ||
33
+ (typeof process !== 'undefined' && process.env?.VITE_ONAIROS_FORCE_PRODUCTION === 'true');
34
+ };
35
+
36
+ // Allow host apps to override the SDK base URL at runtime before bootstrap.
37
+ // This is useful for local/dev harnesses that need to point the SDK at a custom API host
38
+ // without changing the package defaults.
39
+ const getWindowBaseUrlOverride = () => {
40
+ if (!isBrowser) return null;
41
+ const candidate = window.onairosBaseUrl;
42
+ if (typeof candidate !== 'string') return null;
43
+ const trimmed = candidate.trim();
44
+ if (!trimmed.startsWith('http://') && !trimmed.startsWith('https://')) return null;
45
+ return trimmed.replace(/\/$/, '');
46
+ };
47
+
48
+ // Base URLs
49
+ const URLS = {
50
+ DEVELOPMENT: 'https://api2.onairos.uk',
51
+ DEV_SERVER: 'https://api2.onairos.uk',
52
+ PRODUCTION: 'https://api2.onairos.uk',
53
+ };
54
+
55
+ /**
56
+ * Get the API base URL based on current domain
57
+ * - internship.onairos.uk -> https://api2.onairos.uk
58
+ * - All other domains -> https://api2.onairos.uk while dev backend changes are being tested
59
+ *
60
+ * @returns {string} The API base URL
61
+ */
62
+ export function getApiBaseUrl() {
63
+ // SSR fallback
64
+ if (!isBrowser) {
65
+ return URLS.PRODUCTION;
66
+ }
67
+
68
+ const override = getWindowBaseUrlOverride();
69
+ if (override) {
70
+ return override;
71
+ }
72
+
73
+ // Force production override
74
+ if (getForceProduction()) {
75
+ return URLS.PRODUCTION;
76
+ }
77
+
78
+ // Internship demo domain uses the configured dev server URL.
79
+ if (getIsInternshipDemo()) {
80
+ return URLS.DEV_SERVER;
81
+ }
82
+
83
+ // Default to production
84
+ return URLS.PRODUCTION;
85
+ }
86
+
87
+ // API Configuration object for backwards compatibility
88
+ export const API_CONFIG = {
89
+ // Base URLs
90
+ DEVELOPMENT_URL: URLS.DEVELOPMENT,
91
+ DEV_SERVER_URL: URLS.DEV_SERVER,
92
+ PRODUCTION_URL: URLS.PRODUCTION,
93
+
94
+ // Current environment (computed on access for SSR safety)
95
+ get IS_DEVELOPMENT() { return getIsDevelopment(); },
96
+ get IS_INTERNSHIP_DEMO() { return getIsInternshipDemo(); },
97
+
98
+ // Get base URL based on environment
99
+ getBaseUrl() {
100
+ return getApiBaseUrl();
101
+ },
102
+
103
+ // Email verification endpoints
104
+ EMAIL_VERIFY: '/email/verify',
105
+ EMAIL_VERIFY_CONFIRM: '/email/verify/confirm',
106
+
107
+ // Get full URLs
108
+ getEmailVerifyUrl() {
109
+ return `${this.getBaseUrl()}${this.EMAIL_VERIFY}`;
110
+ },
111
+
112
+ getEmailVerifyConfirmUrl() {
113
+ return `${this.getBaseUrl()}${this.EMAIL_VERIFY_CONFIRM}`;
114
+ },
115
+
116
+ // Debug info
117
+ getDebugInfo() {
118
+ if (!isBrowser) {
119
+ return { environment: 'ssr', baseUrl: URLS.PRODUCTION };
120
+ }
121
+ return {
122
+ environment: this.IS_INTERNSHIP_DEMO ? 'internship-demo' : (this.IS_DEVELOPMENT ? 'development' : 'production'),
123
+ baseUrl: this.getBaseUrl(),
124
+ hostname: window.location.hostname,
125
+ port: window.location.port,
126
+ isInternshipDemo: this.IS_INTERNSHIP_DEMO,
127
+ emailVerifyUrl: this.getEmailVerifyUrl(),
128
+ emailVerifyConfirmUrl: this.getEmailVerifyConfirmUrl()
129
+ };
130
+ }
131
+ };
132
+
133
+ // Log configuration on load (only in browser)
134
+ if (isBrowser) {
135
+ console.log('🔧 API Configuration loaded:', API_CONFIG.getDebugInfo());
136
+ }
137
+
138
+ export default API_CONFIG;
@@ -0,0 +1,38 @@
1
+ import React, { useEffect, useState } from "react";
2
+
3
+ const DeepLink = () => {
4
+ const [message, setMessage] = useState("No message passed!");
5
+ const [mode, setMode] = useState("default");
6
+
7
+ useEffect(() => {
8
+ // Check if Telegram's WebApp object is available
9
+ if (window.Telegram && window.Telegram.WebApp) {
10
+ // Tell Telegram the app is ready
11
+ window.Telegram.WebApp.ready();
12
+
13
+ // Access initData
14
+ const initData = window.Telegram.WebApp.initDataUnsafe;
15
+ const startParam = initData?.start_param || "No data found!";
16
+ const modeParam = initData?.mode || "default";
17
+
18
+ setMessage(startParam);
19
+ setMode(modeParam);
20
+ } else {
21
+ // Handle case where Telegram SDK is not available
22
+ console.warn("Telegram WebApp is not available!");
23
+ setMessage("Telegram WebApp is not available!");
24
+ }
25
+ }, []);
26
+
27
+ return (
28
+ <div className="min-h-screen flex items-center justify-center bg-gray-100">
29
+ <div className="p-4 bg-white shadow-lg rounded-lg">
30
+ <h1 className="text-2xl font-bold">Welcome to Onairos Mini App</h1>
31
+ <p className="mt-4 text-lg">Message: {message}</p>
32
+ <p className="mt-2 text-sm">Mode: {mode}</p>
33
+ </div>
34
+ </div>
35
+ );
36
+ };
37
+
38
+ export default DeepLink;
package/src/getPin.js ADDED
@@ -0,0 +1,26 @@
1
+ import { getApiBaseUrl } from './config/api-config.js';
2
+
3
+ export default async function getPin(userSub){
4
+ try {
5
+ const response = await fetch(`${getApiBaseUrl()}/getAccountInfoFromUserSub`, {
6
+ method: 'POST',
7
+ headers: {
8
+ 'Content-Type': 'application/json',
9
+ },
10
+ body: JSON.stringify({
11
+ 'userSub': userSub
12
+ })
13
+ });
14
+
15
+ if (!response.ok) {
16
+ throw new Error(`HTTP error! status: ${response.status}`);
17
+ }
18
+
19
+ return await response.json();
20
+ } catch (error) {
21
+ console.error('Error getting PIN:', error);
22
+ throw error;
23
+ }
24
+ }
25
+
26
+
Binary file
Binary file
Binary file