@onairos/react-native 1.0.0
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/README.md +334 -0
- package/lib/commonjs/components/DataRequestModal.js +176 -0
- package/lib/commonjs/components/DataRequestModal.js.map +1 -0
- package/lib/commonjs/components/Notification.js +106 -0
- package/lib/commonjs/components/Notification.js.map +1 -0
- package/lib/commonjs/components/OnairosButton.js +575 -0
- package/lib/commonjs/components/OnairosButton.js.map +1 -0
- package/lib/commonjs/components/Overlay.js +818 -0
- package/lib/commonjs/components/Overlay.js.map +1 -0
- package/lib/commonjs/components/UniversalOnboarding.js +173 -0
- package/lib/commonjs/components/UniversalOnboarding.js.map +1 -0
- package/lib/commonjs/components/onboarding/OAuthWebView.js +137 -0
- package/lib/commonjs/components/onboarding/OAuthWebView.js.map +1 -0
- package/lib/commonjs/components/onboarding/OnboardingHeader.js +74 -0
- package/lib/commonjs/components/onboarding/OnboardingHeader.js.map +1 -0
- package/lib/commonjs/components/onboarding/PinInput.js +283 -0
- package/lib/commonjs/components/onboarding/PinInput.js.map +1 -0
- package/lib/commonjs/components/onboarding/PlatformConnector.js +244 -0
- package/lib/commonjs/components/onboarding/PlatformConnector.js.map +1 -0
- package/lib/commonjs/components/screens/ConnectorScreen.js +145 -0
- package/lib/commonjs/components/screens/ConnectorScreen.js.map +1 -0
- package/lib/commonjs/components/screens/LoadingScreen.js +91 -0
- package/lib/commonjs/components/screens/LoadingScreen.js.map +1 -0
- package/lib/commonjs/components/screens/PinCreationScreen.js +61 -0
- package/lib/commonjs/components/screens/PinCreationScreen.js.map +1 -0
- package/lib/commonjs/constants/index.js +78 -0
- package/lib/commonjs/constants/index.js.map +1 -0
- package/lib/commonjs/hooks/useConnections.js +89 -0
- package/lib/commonjs/hooks/useConnections.js.map +1 -0
- package/lib/commonjs/hooks/useCredentials.js +85 -0
- package/lib/commonjs/hooks/useCredentials.js.map +1 -0
- package/lib/commonjs/index.js +282 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/services/oauthService.js +362 -0
- package/lib/commonjs/services/oauthService.js.map +1 -0
- package/lib/commonjs/types/declarations.d.js +2 -0
- package/lib/commonjs/types/declarations.d.js.map +1 -0
- package/lib/commonjs/types/index.js +2 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/utils/api.js +129 -0
- package/lib/commonjs/utils/api.js.map +1 -0
- package/lib/commonjs/utils/auth.js +111 -0
- package/lib/commonjs/utils/auth.js.map +1 -0
- package/lib/commonjs/utils/crypto.js +62 -0
- package/lib/commonjs/utils/crypto.js.map +1 -0
- package/lib/commonjs/utils/debugHelper.js +64 -0
- package/lib/commonjs/utils/debugHelper.js.map +1 -0
- package/lib/commonjs/utils/onairosApi.js +270 -0
- package/lib/commonjs/utils/onairosApi.js.map +1 -0
- package/lib/commonjs/utils/secureStorage.js +210 -0
- package/lib/commonjs/utils/secureStorage.js.map +1 -0
- package/lib/module/components/DataRequestModal.js +168 -0
- package/lib/module/components/DataRequestModal.js.map +1 -0
- package/lib/module/components/Notification.js +99 -0
- package/lib/module/components/Notification.js.map +1 -0
- package/lib/module/components/OnairosButton.js +550 -0
- package/lib/module/components/OnairosButton.js.map +1 -0
- package/lib/module/components/Overlay.js +825 -0
- package/lib/module/components/Overlay.js.map +1 -0
- package/lib/module/components/UniversalOnboarding.js +164 -0
- package/lib/module/components/UniversalOnboarding.js.map +1 -0
- package/lib/module/components/onboarding/OAuthWebView.js +128 -0
- package/lib/module/components/onboarding/OAuthWebView.js.map +1 -0
- package/lib/module/components/onboarding/OnboardingHeader.js +66 -0
- package/lib/module/components/onboarding/OnboardingHeader.js.map +1 -0
- package/lib/module/components/onboarding/PinInput.js +274 -0
- package/lib/module/components/onboarding/PinInput.js.map +1 -0
- package/lib/module/components/onboarding/PlatformConnector.js +235 -0
- package/lib/module/components/onboarding/PlatformConnector.js.map +1 -0
- package/lib/module/components/screens/ConnectorScreen.js +137 -0
- package/lib/module/components/screens/ConnectorScreen.js.map +1 -0
- package/lib/module/components/screens/LoadingScreen.js +83 -0
- package/lib/module/components/screens/LoadingScreen.js.map +1 -0
- package/lib/module/components/screens/PinCreationScreen.js +53 -0
- package/lib/module/components/screens/PinCreationScreen.js.map +1 -0
- package/lib/module/constants/index.js +72 -0
- package/lib/module/constants/index.js.map +1 -0
- package/lib/module/hooks/useConnections.js +81 -0
- package/lib/module/hooks/useConnections.js.map +1 -0
- package/lib/module/hooks/useCredentials.js +77 -0
- package/lib/module/hooks/useCredentials.js.map +1 -0
- package/lib/module/index.js +34 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/services/oauthService.js +352 -0
- package/lib/module/services/oauthService.js.map +1 -0
- package/lib/module/types/declarations.d.js +2 -0
- package/lib/module/types/declarations.d.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/api.js +117 -0
- package/lib/module/utils/api.js.map +1 -0
- package/lib/module/utils/auth.js +99 -0
- package/lib/module/utils/auth.js.map +1 -0
- package/lib/module/utils/crypto.js +54 -0
- package/lib/module/utils/crypto.js.map +1 -0
- package/lib/module/utils/debugHelper.js +54 -0
- package/lib/module/utils/debugHelper.js.map +1 -0
- package/lib/module/utils/onairosApi.js +256 -0
- package/lib/module/utils/onairosApi.js.map +1 -0
- package/lib/module/utils/secureStorage.js +196 -0
- package/lib/module/utils/secureStorage.js.map +1 -0
- package/package.json +115 -0
- package/src/components/DataRequestModal.tsx +187 -0
- package/src/components/Notification.js +101 -0
- package/src/components/OnairosButton.js +604 -0
- package/src/components/OnairosButton.tsx +182 -0
- package/src/components/Overlay.js +854 -0
- package/src/components/Overlay.tsx +272 -0
- package/src/components/UniversalOnboarding.tsx +184 -0
- package/src/components/onboarding/OAuthWebView.tsx +134 -0
- package/src/components/onboarding/OnboardingHeader.tsx +70 -0
- package/src/components/onboarding/PinInput.tsx +356 -0
- package/src/components/onboarding/PlatformConnector.tsx +297 -0
- package/src/components/screens/ConnectorScreen.tsx +152 -0
- package/src/components/screens/LoadingScreen.tsx +100 -0
- package/src/components/screens/PinCreationScreen.tsx +67 -0
- package/src/constants/index.ts +78 -0
- package/src/hooks/useConnections.ts +90 -0
- package/src/hooks/useCredentials.ts +83 -0
- package/src/index.js +14 -0
- package/src/index.ts +82 -0
- package/src/services/oauthService.ts +360 -0
- package/src/types/declarations.d.ts +26 -0
- package/src/types/index.ts +82 -0
- package/src/utils/api.js +112 -0
- package/src/utils/auth.js +104 -0
- package/src/utils/crypto.js +60 -0
- package/src/utils/debugHelper.ts +53 -0
- package/src/utils/onairosApi.ts +303 -0
- package/src/utils/secureStorage.ts +230 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { Linking, Platform } from 'react-native';
|
|
2
|
+
import { updateCredentials, OnairosCredentials } from '../utils/secureStorage';
|
|
3
|
+
import { sha256 } from '../utils/crypto';
|
|
4
|
+
|
|
5
|
+
// Define OAuth configuration types
|
|
6
|
+
export interface OAuthConfig {
|
|
7
|
+
clientId: string;
|
|
8
|
+
redirectUri: string;
|
|
9
|
+
scope: string;
|
|
10
|
+
authorizationEndpoint: string;
|
|
11
|
+
tokenEndpoint: string;
|
|
12
|
+
responseType: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Platform-specific OAuth configurations
|
|
16
|
+
const OAUTH_CONFIGS: Record<string, OAuthConfig> = {
|
|
17
|
+
instagram: {
|
|
18
|
+
clientId: 'YOUR_INSTAGRAM_CLIENT_ID', // Replace with actual client ID
|
|
19
|
+
redirectUri: 'onairosreact://auth/instagram',
|
|
20
|
+
scope: 'user_profile,user_media',
|
|
21
|
+
authorizationEndpoint: 'https://api.instagram.com/oauth/authorize',
|
|
22
|
+
tokenEndpoint: 'https://api.instagram.com/oauth/access_token',
|
|
23
|
+
responseType: 'code',
|
|
24
|
+
},
|
|
25
|
+
youtube: {
|
|
26
|
+
clientId: 'YOUR_YOUTUBE_CLIENT_ID', // Replace with actual client ID
|
|
27
|
+
redirectUri: 'onairosreact://auth/youtube',
|
|
28
|
+
scope: 'https://www.googleapis.com/auth/youtube.readonly',
|
|
29
|
+
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',
|
|
30
|
+
tokenEndpoint: 'https://oauth2.googleapis.com/token',
|
|
31
|
+
responseType: 'code',
|
|
32
|
+
},
|
|
33
|
+
pinterest: {
|
|
34
|
+
clientId: 'YOUR_PINTEREST_CLIENT_ID', // Replace with actual client ID
|
|
35
|
+
redirectUri: 'onairosreact://auth/pinterest',
|
|
36
|
+
scope: 'boards:read,pins:read',
|
|
37
|
+
authorizationEndpoint: 'https://www.pinterest.com/oauth/',
|
|
38
|
+
tokenEndpoint: 'https://api.pinterest.com/v5/oauth/token',
|
|
39
|
+
responseType: 'code',
|
|
40
|
+
},
|
|
41
|
+
reddit: {
|
|
42
|
+
clientId: 'YOUR_REDDIT_CLIENT_ID', // Replace with actual client ID
|
|
43
|
+
redirectUri: 'onairosreact://auth/reddit',
|
|
44
|
+
scope: 'identity,read',
|
|
45
|
+
authorizationEndpoint: 'https://www.reddit.com/api/v1/authorize',
|
|
46
|
+
tokenEndpoint: 'https://www.reddit.com/api/v1/access_token',
|
|
47
|
+
responseType: 'code',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Generate a state value for OAuth to prevent CSRF attacks
|
|
53
|
+
*/
|
|
54
|
+
const generateState = (): string => {
|
|
55
|
+
const randomValue = Math.random().toString(36).substring(2, 15);
|
|
56
|
+
return sha256(randomValue).substring(0, 10);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Initialize OAuth service handlers and listeners
|
|
61
|
+
*/
|
|
62
|
+
export const initializeOAuthService = (): void => {
|
|
63
|
+
// Set up deep linking handlers for OAuth redirects
|
|
64
|
+
Linking.addEventListener('url', handleDeepLink);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Clean up OAuth service handlers and listeners
|
|
69
|
+
*/
|
|
70
|
+
export const cleanupOAuthService = (): void => {
|
|
71
|
+
// Clean up deep linking handlers
|
|
72
|
+
if (Platform.OS === 'android') {
|
|
73
|
+
Linking.removeEventListener('url', handleDeepLink);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Keep track of current OAuth state and callbacks
|
|
78
|
+
let currentOAuthState: string | null = null;
|
|
79
|
+
let currentOAuthPlatform: string | null = null;
|
|
80
|
+
let currentOAuthResolve: ((value: any) => void) | null = null;
|
|
81
|
+
let currentOAuthReject: ((error: Error) => void) | null = null;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Handle deep link callbacks from OAuth providers
|
|
85
|
+
*/
|
|
86
|
+
const handleDeepLink = async (event: { url: string }): Promise<void> => {
|
|
87
|
+
try {
|
|
88
|
+
const { url } = event;
|
|
89
|
+
|
|
90
|
+
// Check if this is an OAuth callback URL
|
|
91
|
+
if (!url.startsWith('onairosreact://auth/')) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Extract platform from URL path
|
|
96
|
+
const platform = url.split('onairosreact://auth/')[1].split('?')[0];
|
|
97
|
+
|
|
98
|
+
// Only handle if it matches current OAuth flow
|
|
99
|
+
if (platform !== currentOAuthPlatform) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Parse URL parameters
|
|
104
|
+
const params = new URL(url).searchParams;
|
|
105
|
+
const code = params.get('code');
|
|
106
|
+
const state = params.get('state');
|
|
107
|
+
const error = params.get('error');
|
|
108
|
+
|
|
109
|
+
// Validate state to prevent CSRF attacks
|
|
110
|
+
if (state !== currentOAuthState) {
|
|
111
|
+
if (currentOAuthReject) {
|
|
112
|
+
currentOAuthReject(new Error('OAuth state mismatch - possible CSRF attack'));
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Handle errors
|
|
118
|
+
if (error) {
|
|
119
|
+
if (currentOAuthReject) {
|
|
120
|
+
currentOAuthReject(new Error(`OAuth error: ${error}`));
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Proceed with token exchange if code is present
|
|
126
|
+
if (code) {
|
|
127
|
+
const tokenResult = await exchangeCodeForToken(platform, code);
|
|
128
|
+
|
|
129
|
+
if (currentOAuthResolve) {
|
|
130
|
+
currentOAuthResolve(tokenResult);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
if (currentOAuthReject) {
|
|
134
|
+
currentOAuthReject(new Error('No authorization code received'));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error('Error handling OAuth deep link:', error);
|
|
139
|
+
if (currentOAuthReject) {
|
|
140
|
+
currentOAuthReject(error as Error);
|
|
141
|
+
}
|
|
142
|
+
} finally {
|
|
143
|
+
// Reset state
|
|
144
|
+
currentOAuthState = null;
|
|
145
|
+
currentOAuthPlatform = null;
|
|
146
|
+
currentOAuthResolve = null;
|
|
147
|
+
currentOAuthReject = null;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Exchange OAuth authorization code for access token
|
|
153
|
+
*/
|
|
154
|
+
const exchangeCodeForToken = async (platform: string, code: string): Promise<any> => {
|
|
155
|
+
try {
|
|
156
|
+
const config = OAUTH_CONFIGS[platform];
|
|
157
|
+
|
|
158
|
+
if (!config) {
|
|
159
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Prepare token request parameters
|
|
163
|
+
const params = new URLSearchParams({
|
|
164
|
+
grant_type: 'authorization_code',
|
|
165
|
+
code,
|
|
166
|
+
redirect_uri: config.redirectUri,
|
|
167
|
+
client_id: config.clientId,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Exchange code for token
|
|
171
|
+
const response = await fetch(config.tokenEndpoint, {
|
|
172
|
+
method: 'POST',
|
|
173
|
+
headers: {
|
|
174
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
175
|
+
},
|
|
176
|
+
body: params.toString(),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const data = await response.json();
|
|
180
|
+
|
|
181
|
+
if (!response.ok) {
|
|
182
|
+
throw new Error(data.error || 'Failed to exchange code for token');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Fetch user information based on the platform
|
|
186
|
+
const userInfo = await fetchUserInfo(platform, data.access_token);
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
token: data.access_token,
|
|
190
|
+
refreshToken: data.refresh_token,
|
|
191
|
+
expiresIn: data.expires_in,
|
|
192
|
+
username: userInfo.username,
|
|
193
|
+
userId: userInfo.id,
|
|
194
|
+
};
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.error(`Error exchanging code for token (${platform}):`, error);
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Fetch user information from the connected platform
|
|
203
|
+
*/
|
|
204
|
+
const fetchUserInfo = async (platform: string, accessToken: string): Promise<any> => {
|
|
205
|
+
try {
|
|
206
|
+
let endpoint;
|
|
207
|
+
let headers: Record<string, string> = {
|
|
208
|
+
Authorization: `Bearer ${accessToken}`,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// Platform-specific API endpoints for user info
|
|
212
|
+
switch (platform) {
|
|
213
|
+
case 'instagram':
|
|
214
|
+
endpoint = 'https://graph.instagram.com/me?fields=id,username';
|
|
215
|
+
break;
|
|
216
|
+
case 'youtube':
|
|
217
|
+
endpoint = 'https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true';
|
|
218
|
+
break;
|
|
219
|
+
case 'pinterest':
|
|
220
|
+
endpoint = 'https://api.pinterest.com/v5/user_account';
|
|
221
|
+
break;
|
|
222
|
+
case 'reddit':
|
|
223
|
+
endpoint = 'https://oauth.reddit.com/api/v1/me';
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const response = await fetch(endpoint, { headers });
|
|
230
|
+
const data = await response.json();
|
|
231
|
+
|
|
232
|
+
if (!response.ok) {
|
|
233
|
+
throw new Error(data.error || 'Failed to fetch user info');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Extract user information based on platform-specific response format
|
|
237
|
+
switch (platform) {
|
|
238
|
+
case 'instagram':
|
|
239
|
+
return { id: data.id, username: data.username };
|
|
240
|
+
case 'youtube':
|
|
241
|
+
return {
|
|
242
|
+
id: data.items[0].id,
|
|
243
|
+
username: data.items[0].snippet.title
|
|
244
|
+
};
|
|
245
|
+
case 'pinterest':
|
|
246
|
+
return {
|
|
247
|
+
id: data.id,
|
|
248
|
+
username: data.username || data.full_name
|
|
249
|
+
};
|
|
250
|
+
case 'reddit':
|
|
251
|
+
return { id: data.id, username: data.name };
|
|
252
|
+
default:
|
|
253
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
254
|
+
}
|
|
255
|
+
} catch (error) {
|
|
256
|
+
console.error(`Error fetching user info (${platform}):`, error);
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Initiate OAuth flow for a specific platform
|
|
263
|
+
*/
|
|
264
|
+
export const connectPlatform = (platform: string): Promise<any> => {
|
|
265
|
+
return new Promise((resolve, reject) => {
|
|
266
|
+
try {
|
|
267
|
+
const config = OAUTH_CONFIGS[platform];
|
|
268
|
+
|
|
269
|
+
if (!config) {
|
|
270
|
+
reject(new Error(`Unsupported platform: ${platform}`));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Generate and save state for CSRF protection
|
|
275
|
+
const state = generateState();
|
|
276
|
+
currentOAuthState = state;
|
|
277
|
+
currentOAuthPlatform = platform;
|
|
278
|
+
currentOAuthResolve = resolve;
|
|
279
|
+
currentOAuthReject = reject;
|
|
280
|
+
|
|
281
|
+
// Build OAuth URL
|
|
282
|
+
const authUrl = new URL(config.authorizationEndpoint);
|
|
283
|
+
authUrl.searchParams.append('client_id', config.clientId);
|
|
284
|
+
authUrl.searchParams.append('redirect_uri', config.redirectUri);
|
|
285
|
+
authUrl.searchParams.append('response_type', config.responseType);
|
|
286
|
+
authUrl.searchParams.append('scope', config.scope);
|
|
287
|
+
authUrl.searchParams.append('state', state);
|
|
288
|
+
|
|
289
|
+
// Open browser to start OAuth flow
|
|
290
|
+
Linking.openURL(authUrl.toString());
|
|
291
|
+
} catch (error) {
|
|
292
|
+
reject(error);
|
|
293
|
+
|
|
294
|
+
// Reset state on error
|
|
295
|
+
currentOAuthState = null;
|
|
296
|
+
currentOAuthPlatform = null;
|
|
297
|
+
currentOAuthResolve = null;
|
|
298
|
+
currentOAuthReject = null;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Disconnect a platform by removing its credentials
|
|
305
|
+
*/
|
|
306
|
+
export const disconnectPlatform = async (
|
|
307
|
+
platform: string,
|
|
308
|
+
credentials: OnairosCredentials
|
|
309
|
+
): Promise<boolean> => {
|
|
310
|
+
try {
|
|
311
|
+
if (!credentials.platforms) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Create new credentials object with the platform removed
|
|
316
|
+
const updatedPlatforms = { ...credentials.platforms };
|
|
317
|
+
delete updatedPlatforms[platform as keyof typeof updatedPlatforms];
|
|
318
|
+
|
|
319
|
+
// Update stored credentials
|
|
320
|
+
const result = await updateCredentials({
|
|
321
|
+
platforms: updatedPlatforms,
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
return result;
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error(`Error disconnecting platform (${platform}):`, error);
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Store platform connection in credentials
|
|
333
|
+
*/
|
|
334
|
+
export const storePlatformConnection = async (
|
|
335
|
+
platform: string,
|
|
336
|
+
connectionData: any,
|
|
337
|
+
credentials: OnairosCredentials
|
|
338
|
+
): Promise<boolean> => {
|
|
339
|
+
try {
|
|
340
|
+
// Create updated platforms object
|
|
341
|
+
const updatedPlatforms = {
|
|
342
|
+
...credentials.platforms,
|
|
343
|
+
[platform]: {
|
|
344
|
+
token: connectionData.token,
|
|
345
|
+
username: connectionData.username,
|
|
346
|
+
userId: connectionData.userId,
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// Update stored credentials
|
|
351
|
+
const result = await updateCredentials({
|
|
352
|
+
platforms: updatedPlatforms,
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
return result;
|
|
356
|
+
} catch (error) {
|
|
357
|
+
console.error(`Error storing platform connection (${platform}):`, error);
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Type declarations for modules without type definitions
|
|
2
|
+
|
|
3
|
+
declare module 'react-native-rsa-native' {
|
|
4
|
+
export const RSA: {
|
|
5
|
+
encrypt: (data: string, publicKey: string) => Promise<string>;
|
|
6
|
+
decrypt: (data: string, privateKey: string) => Promise<string>;
|
|
7
|
+
sign: (data: string, privateKey: string, hash?: string) => Promise<string>;
|
|
8
|
+
verify: (data: string, signature: string, publicKey: string, hash?: string) => Promise<boolean>;
|
|
9
|
+
generateKeys: (keySize?: number) => Promise<{ private: string; public: string }>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module 'react-native-crypto-js' {
|
|
14
|
+
export const AES: {
|
|
15
|
+
encrypt: (message: string, secretKey: string) => any;
|
|
16
|
+
decrypt: (ciphertext: any, secretKey: string) => string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function sha256(message: string): any;
|
|
20
|
+
export function MD5(message: string): any;
|
|
21
|
+
export function SHA1(message: string): any;
|
|
22
|
+
export function SHA512(message: string): any;
|
|
23
|
+
export function HmacSHA256(message: string, key: string): any;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Declare any other missing module types here
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export interface OnairosButtonProps {
|
|
2
|
+
AppName: string;
|
|
3
|
+
requestData: Record<string, Record<string, string>>;
|
|
4
|
+
returnLink: string;
|
|
5
|
+
embedd?: boolean;
|
|
6
|
+
color?: string;
|
|
7
|
+
icon?: string;
|
|
8
|
+
onResolved: (apiUrl: string, accessToken: string, loginDetails?: Record<string, any>) => void;
|
|
9
|
+
login?: boolean;
|
|
10
|
+
buttonType?: 'circle' | 'pill';
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
test?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface UniversalOnboardingProps {
|
|
16
|
+
visible: boolean;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
AppName: string;
|
|
19
|
+
requestData: Record<string, Record<string, string>>;
|
|
20
|
+
returnLink: string;
|
|
21
|
+
onComplete: (apiUrl: string, accessToken: string, data: any) => void;
|
|
22
|
+
embedd?: boolean;
|
|
23
|
+
debug?: boolean;
|
|
24
|
+
test?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ConnectionStatus {
|
|
28
|
+
instagram?: { userName: string };
|
|
29
|
+
pinterest?: { userName: string };
|
|
30
|
+
reddit?: { userName: string };
|
|
31
|
+
youtube?: { userName: string };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PlatformListProps {
|
|
35
|
+
connections: ConnectionStatus;
|
|
36
|
+
onToggle: (platform: string, connect: boolean) => Promise<void>;
|
|
37
|
+
isLoading: boolean;
|
|
38
|
+
canProceed: boolean;
|
|
39
|
+
onProceed: () => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface PinInputProps {
|
|
43
|
+
onSubmit: (pin: string) => void;
|
|
44
|
+
minLength?: number;
|
|
45
|
+
requireSpecialChar?: boolean;
|
|
46
|
+
requireNumber?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface TrainingModalProps {
|
|
50
|
+
progress: number;
|
|
51
|
+
eta: string;
|
|
52
|
+
onCancel: () => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface OAuthWebViewProps {
|
|
56
|
+
url: string;
|
|
57
|
+
platform: string;
|
|
58
|
+
onComplete: () => void;
|
|
59
|
+
onClose: () => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface CredentialsResult {
|
|
63
|
+
isValid: boolean;
|
|
64
|
+
credentials?: {
|
|
65
|
+
username?: string;
|
|
66
|
+
userPin?: string;
|
|
67
|
+
accessToken?: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface PlatformConfig {
|
|
72
|
+
name: string;
|
|
73
|
+
icon: string;
|
|
74
|
+
color: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface ApiResponse<T> {
|
|
79
|
+
success: boolean;
|
|
80
|
+
data?: T;
|
|
81
|
+
error?: string;
|
|
82
|
+
}
|
package/src/utils/api.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
|
+
|
|
4
|
+
const API_URL = 'https://api2.onairos.uk';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create an API instance with authorization headers
|
|
8
|
+
* @returns {Promise<Object>} - The axios instance
|
|
9
|
+
*/
|
|
10
|
+
export const createApiInstance = async () => {
|
|
11
|
+
const token = await AsyncStorage.getItem('onairosToken');
|
|
12
|
+
|
|
13
|
+
return axios.create({
|
|
14
|
+
baseURL: API_URL,
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
...(token ? { 'Authorization': `Bearer ${token}` } : {})
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Validate the domain with the Onairos API
|
|
24
|
+
* @returns {Promise<Object>} - The validation response
|
|
25
|
+
*/
|
|
26
|
+
export const validateDomain = async () => {
|
|
27
|
+
try {
|
|
28
|
+
const api = await createApiInstance();
|
|
29
|
+
const response = await api.post('/valid/validate-domain');
|
|
30
|
+
return response.data;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error('Error validating domain:', error);
|
|
33
|
+
return { status: false };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Fetch account information
|
|
39
|
+
* @param {string} identifier - The username or email
|
|
40
|
+
* @param {boolean} isEmail - Whether the identifier is an email
|
|
41
|
+
* @returns {Promise<Object>} - The account information
|
|
42
|
+
*/
|
|
43
|
+
export const fetchAccountInfo = async (identifier, isEmail = false) => {
|
|
44
|
+
try {
|
|
45
|
+
const api = await createApiInstance();
|
|
46
|
+
const jsonData = isEmail
|
|
47
|
+
? { Info: { identifier } }
|
|
48
|
+
: { Info: { userName: identifier } };
|
|
49
|
+
|
|
50
|
+
const endpoint = isEmail ? '/getAccountInfo/email' : '/getAccountInfo';
|
|
51
|
+
const response = await api.post(endpoint, jsonData);
|
|
52
|
+
|
|
53
|
+
return response.data;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Error fetching account info:', error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get API URL for data requests
|
|
62
|
+
* @param {Array} approvedRequests - The approved data requests
|
|
63
|
+
* @param {string} pin - The encrypted PIN
|
|
64
|
+
* @param {string} othentSub - The hashed Othent sub
|
|
65
|
+
* @returns {Promise<Object>} - The API URL response
|
|
66
|
+
*/
|
|
67
|
+
export const getApiUrl = async (approvedRequests, pin, othentSub) => {
|
|
68
|
+
try {
|
|
69
|
+
const api = await createApiInstance();
|
|
70
|
+
const jsonData = {
|
|
71
|
+
Info: {
|
|
72
|
+
EncryptedUserPin: pin,
|
|
73
|
+
confirmations: approvedRequests,
|
|
74
|
+
web3Type: 'othent',
|
|
75
|
+
Domain: Platform.OS,
|
|
76
|
+
proofMode: false,
|
|
77
|
+
OthentSub: othentSub,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const response = await api.post('/getAPIurl', jsonData);
|
|
82
|
+
return response.data;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error('Error getting API URL:', error);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Create a new user account
|
|
91
|
+
* @param {string} othentSub - The hashed Othent sub
|
|
92
|
+
* @param {string} pin - The PIN
|
|
93
|
+
* @param {Array} socialAccounts - The selected social accounts
|
|
94
|
+
* @param {string} email - The user's email
|
|
95
|
+
* @returns {Promise<Object>} - The account creation response
|
|
96
|
+
*/
|
|
97
|
+
export const createAccount = async (othentSub, pin, socialAccounts, email) => {
|
|
98
|
+
try {
|
|
99
|
+
const api = await createApiInstance();
|
|
100
|
+
const response = await api.post('/createAccount', {
|
|
101
|
+
othentSub,
|
|
102
|
+
pin,
|
|
103
|
+
socialAccounts,
|
|
104
|
+
email
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return response.data;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error('Error creating account:', error);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
|
+
|
|
4
|
+
const API_URL = 'https://api2.onairos.uk';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get the encrypted PIN for a user
|
|
8
|
+
* @param {string} hashedOthentSub - The hashed Othent sub
|
|
9
|
+
* @returns {Promise<Object>} - The response containing the encrypted PIN
|
|
10
|
+
*/
|
|
11
|
+
export const getPin = async (hashedOthentSub) => {
|
|
12
|
+
try {
|
|
13
|
+
const response = await axios.post(`${API_URL}/getPin`, {
|
|
14
|
+
hashedOthentSub
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return response.data;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('Error getting PIN:', error);
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Verify a token with the Onairos API
|
|
26
|
+
* @param {string} token - The token to verify
|
|
27
|
+
* @returns {Promise<boolean>} - Whether the token is valid
|
|
28
|
+
*/
|
|
29
|
+
export const verifyToken = async (token) => {
|
|
30
|
+
try {
|
|
31
|
+
const response = await axios.post(`${API_URL}/verifyToken`, {}, {
|
|
32
|
+
headers: {
|
|
33
|
+
'Authorization': `Bearer ${token}`
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return response.data.valid;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('Error verifying token:', error);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Store authentication data
|
|
46
|
+
* @param {string} token - The authentication token
|
|
47
|
+
* @param {string} username - The username
|
|
48
|
+
* @param {Object} othentData - The Othent user data
|
|
49
|
+
*/
|
|
50
|
+
export const storeAuthData = async (token, username = null, othentData = null) => {
|
|
51
|
+
try {
|
|
52
|
+
await AsyncStorage.setItem('onairosToken', token);
|
|
53
|
+
|
|
54
|
+
if (username) {
|
|
55
|
+
await AsyncStorage.setItem('username', username);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (othentData) {
|
|
59
|
+
await AsyncStorage.setItem('othentToken', JSON.stringify(othentData));
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Error storing auth data:', error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Clear authentication data
|
|
69
|
+
*/
|
|
70
|
+
export const clearAuthData = async () => {
|
|
71
|
+
try {
|
|
72
|
+
await AsyncStorage.removeItem('onairosToken');
|
|
73
|
+
await AsyncStorage.removeItem('username');
|
|
74
|
+
await AsyncStorage.removeItem('othentToken');
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error('Error clearing auth data:', error);
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get stored authentication data
|
|
83
|
+
* @returns {Promise<Object>} - The stored authentication data
|
|
84
|
+
*/
|
|
85
|
+
export const getStoredAuthData = async () => {
|
|
86
|
+
try {
|
|
87
|
+
const token = await AsyncStorage.getItem('onairosToken');
|
|
88
|
+
const username = await AsyncStorage.getItem('username');
|
|
89
|
+
const othentToken = await AsyncStorage.getItem('othentToken');
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
token,
|
|
93
|
+
username,
|
|
94
|
+
othentToken: othentToken ? JSON.parse(othentToken) : null
|
|
95
|
+
};
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('Error getting stored auth data:', error);
|
|
98
|
+
return {
|
|
99
|
+
token: null,
|
|
100
|
+
username: null,
|
|
101
|
+
othentToken: null
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|