@onairos/react-native 2.1.1 → 3.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/lib/commonjs/api/index.js +102 -14
- package/lib/commonjs/api/index.js.map +1 -1
- package/lib/commonjs/components/Onairos.js +89 -0
- package/lib/commonjs/components/Onairos.js.map +1 -0
- package/lib/commonjs/components/OnairosButton.js +76 -29
- package/lib/commonjs/components/OnairosButton.js.map +1 -1
- package/lib/commonjs/index.js +12 -276
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/services/oauthService.js +145 -1
- package/lib/commonjs/services/oauthService.js.map +1 -1
- package/lib/commonjs/utils/encryption.js +45 -7
- package/lib/commonjs/utils/encryption.js.map +1 -1
- package/lib/module/api/index.js +103 -14
- package/lib/module/api/index.js.map +1 -1
- package/lib/module/components/Onairos.js +81 -0
- package/lib/module/components/Onairos.js.map +1 -0
- package/lib/module/components/OnairosButton.js +80 -32
- package/lib/module/components/OnairosButton.js.map +1 -1
- package/lib/module/index.js +43 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/services/oauthService.js +144 -0
- package/lib/module/services/oauthService.js.map +1 -1
- package/lib/module/utils/encryption.js +43 -6
- package/lib/module/utils/encryption.js.map +1 -1
- package/package.json +1 -1
- package/src/api/index.ts +113 -20
- package/src/components/Onairos.tsx +117 -0
- package/src/components/OnairosButton.tsx +100 -32
- package/src/index.ts +19 -5
- package/src/services/oauthService.ts +174 -0
- package/src/types/index.ts +38 -7
- package/src/utils/encryption.ts +45 -6
package/lib/module/api/index.js
CHANGED
|
@@ -1,27 +1,116 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Onairos API service for handling API requests
|
|
5
|
+
*/
|
|
6
|
+
export const onairosApi = {
|
|
7
|
+
baseUrl: 'https://api2.onairos.uk',
|
|
8
|
+
/**
|
|
9
|
+
* Make a GET request to the API
|
|
10
|
+
* @param endpoint The endpoint to request
|
|
11
|
+
* @returns The response data
|
|
12
|
+
*/
|
|
13
|
+
get: async endpoint => {
|
|
8
14
|
try {
|
|
9
|
-
const response = await axios.get(`${
|
|
15
|
+
const response = await axios.get(`${onairosApi.baseUrl}/${endpoint}`);
|
|
10
16
|
return response.data;
|
|
11
17
|
} catch (error) {
|
|
12
|
-
console.error(
|
|
18
|
+
console.error(`GET ${endpoint} error:`, error);
|
|
13
19
|
throw error;
|
|
14
20
|
}
|
|
15
|
-
}
|
|
16
|
-
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Make a POST request to the API
|
|
24
|
+
* @param endpoint The endpoint to request
|
|
25
|
+
* @param data The data to send
|
|
26
|
+
* @returns The response data
|
|
27
|
+
*/
|
|
28
|
+
post: async (endpoint, data) => {
|
|
17
29
|
try {
|
|
18
|
-
const response = await axios.post(`${
|
|
30
|
+
const response = await axios.post(`${onairosApi.baseUrl}/${endpoint}`, data);
|
|
19
31
|
return response.data;
|
|
20
32
|
} catch (error) {
|
|
21
|
-
console.error(
|
|
33
|
+
console.error(`POST ${endpoint} error:`, error);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Get the server's public key for encryption
|
|
39
|
+
* @returns The server's public key
|
|
40
|
+
*/
|
|
41
|
+
getServerPublicKey: async () => {
|
|
42
|
+
try {
|
|
43
|
+
const response = await onairosApi.get('public/getPublicKey');
|
|
44
|
+
return response.publicKey;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error('Error getting server public key:', error);
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Validate credentials with the server
|
|
52
|
+
* @param username The username to validate
|
|
53
|
+
* @returns Whether the credentials are valid
|
|
54
|
+
*/
|
|
55
|
+
validateCredentials: async username => {
|
|
56
|
+
try {
|
|
57
|
+
const response = await onairosApi.post('validate', {
|
|
58
|
+
username
|
|
59
|
+
});
|
|
60
|
+
return response.valid === true;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Error validating credentials:', error);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Get account information for a user
|
|
68
|
+
* @param username The username to get account info for
|
|
69
|
+
* @returns The account information
|
|
70
|
+
*/
|
|
71
|
+
getAccountInfo: async username => {
|
|
72
|
+
try {
|
|
73
|
+
const response = await onairosApi.post('getAccountInfo', {
|
|
74
|
+
Info: {
|
|
75
|
+
username
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return response.AccountInfo;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error('Error getting account info:', error);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* Get API URL and token for a user
|
|
86
|
+
* @param params The parameters for the request
|
|
87
|
+
* @returns The API URL and token
|
|
88
|
+
*/
|
|
89
|
+
getApiUrl: async params => {
|
|
90
|
+
try {
|
|
91
|
+
const response = await onairosApi.post('getAPIUrlMobile', {
|
|
92
|
+
Info: {
|
|
93
|
+
storage: 'local',
|
|
94
|
+
appId: params.appId,
|
|
95
|
+
confirmations: params.confirmations,
|
|
96
|
+
developerURL: 'devURL',
|
|
97
|
+
EncryptedUserPin: params.encryptedModelKey,
|
|
98
|
+
account: params.username,
|
|
99
|
+
proofMode: false
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
if (response && response.apiUrl && response.token) {
|
|
103
|
+
return {
|
|
104
|
+
apiUrl: response.apiUrl,
|
|
105
|
+
token: response.token
|
|
106
|
+
};
|
|
107
|
+
} else {
|
|
108
|
+
throw new Error('Invalid response from getAPIUrlMobile');
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error('Error getting API URL:', error);
|
|
22
112
|
throw error;
|
|
23
113
|
}
|
|
24
114
|
}
|
|
25
|
-
}
|
|
26
|
-
export const onairosApi = new OnairosApi();
|
|
115
|
+
};
|
|
27
116
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["axios","
|
|
1
|
+
{"version":3,"names":["axios","onairosApi","baseUrl","get","endpoint","response","data","error","console","post","getServerPublicKey","publicKey","validateCredentials","username","valid","getAccountInfo","Info","AccountInfo","getApiUrl","params","storage","appId","confirmations","developerURL","EncryptedUserPin","encryptedModelKey","account","proofMode","apiUrl","token","Error"],"sourceRoot":"..\\..\\..\\src","sources":["api/index.ts"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;;AAEzB;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAG;EACxBC,OAAO,EAAE,yBAAyB;EAElC;AACF;AACA;AACA;AACA;EACEC,GAAG,EAAE,MAAOC,QAAgB,IAAK;IAC/B,IAAI;MACF,MAAMC,QAAQ,GAAG,MAAML,KAAK,CAACG,GAAG,CAAC,GAAGF,UAAU,CAACC,OAAO,IAAIE,QAAQ,EAAE,CAAC;MACrE,OAAOC,QAAQ,CAACC,IAAI;IACtB,CAAC,CAAC,OAAOC,KAAK,EAAE;MACdC,OAAO,CAACD,KAAK,CAAC,OAAOH,QAAQ,SAAS,EAAEG,KAAK,CAAC;MAC9C,MAAMA,KAAK;IACb;EACF,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEE,IAAI,EAAE,MAAAA,CAAOL,QAAgB,EAAEE,IAAS,KAAK;IAC3C,IAAI;MACF,MAAMD,QAAQ,GAAG,MAAML,KAAK,CAACS,IAAI,CAC/B,GAAGR,UAAU,CAACC,OAAO,IAAIE,QAAQ,EAAE,EACnCE,IACF,CAAC;MACD,OAAOD,QAAQ,CAACC,IAAI;IACtB,CAAC,CAAC,OAAOC,KAAK,EAAE;MACdC,OAAO,CAACD,KAAK,CAAC,QAAQH,QAAQ,SAAS,EAAEG,K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UACJI,OAAO,EAAE,OAAO;UAChBC,KAAK,EAAEF,MAAM,CAACE,KAAK;UACnBC,aAAa,EAAEH,MAAM,CAACG,aAAa;UACnCC,YAAY,EAAE,QAAQ;UACtBC,gBAAgB,EAAEL,MAAM,CAACM,iBAAiB;UAC1CC,OAAO,EAAEP,MAAM,CAACN,QAAQ;UACxBc,SAAS,EAAE;QACb;MACF,CAAC,CAAC;MAEF,IAAItB,QAAQ,IAAIA,QAAQ,CAACuB,MAAM,IAAIvB,QAAQ,CAACwB,KAAK,EAAE;QACjD,OAAO;UACLD,MAAM,EAAEvB,QAAQ,CAACuB,MAAM;UACvBC,KAAK,EAAExB,QAAQ,CAACwB;QAClB,CAAC;MACH,CAAC,MAAM;QACL,MAAM,IAAIC,KAAK,CAAC,uCAAuC,CAAC;MAC1D;IACF,CAAC,CAAC,OAAOvB,KAAK,EAAE;MACdC,OAAO,CAACD,KAAK,CAAC,wBAAwB,EAAEA,KAAK,CAAC;MAC9C,MAAMA,KAAK;IACb;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { OnairosButton } from './OnairosButton';
|
|
4
|
+
import { hasCredentials, getCredentials } from '../utils/secureStorage';
|
|
5
|
+
/**
|
|
6
|
+
* Main Onairos component - wraps OnairosButton with additional state management and logic
|
|
7
|
+
*/
|
|
8
|
+
export const Onairos = ({
|
|
9
|
+
AppName,
|
|
10
|
+
returnLink,
|
|
11
|
+
requestData,
|
|
12
|
+
buttonType = 'normal',
|
|
13
|
+
buttonForm = 'default',
|
|
14
|
+
buttonWidth,
|
|
15
|
+
buttonHeight,
|
|
16
|
+
color,
|
|
17
|
+
hasStroke,
|
|
18
|
+
preferredPlatform,
|
|
19
|
+
onResolved,
|
|
20
|
+
onRejection,
|
|
21
|
+
testMode = false,
|
|
22
|
+
containerStyle
|
|
23
|
+
}) => {
|
|
24
|
+
const [isInitialized, setIsInitialized] = useState(false);
|
|
25
|
+
const [hasExistingCredentials, setHasExistingCredentials] = useState(false);
|
|
26
|
+
const initialize = useCallback(async () => {
|
|
27
|
+
try {
|
|
28
|
+
// Check for existing credentials
|
|
29
|
+
const credentialsExist = await hasCredentials();
|
|
30
|
+
setHasExistingCredentials(credentialsExist);
|
|
31
|
+
if (credentialsExist) {
|
|
32
|
+
// Load credentials to verify they are valid
|
|
33
|
+
const credentials = await getCredentials();
|
|
34
|
+
if (!credentials || !credentials.username || !credentials.userPin) {
|
|
35
|
+
setHasExistingCredentials(false);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('Error initializing Onairos:', error);
|
|
40
|
+
} finally {
|
|
41
|
+
setIsInitialized(true);
|
|
42
|
+
}
|
|
43
|
+
}, []);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
initialize();
|
|
46
|
+
}, [initialize]);
|
|
47
|
+
const handleResolved = useCallback((apiUrl, token, userData) => {
|
|
48
|
+
if (onResolved) {
|
|
49
|
+
onResolved(apiUrl, token, userData);
|
|
50
|
+
}
|
|
51
|
+
}, [onResolved]);
|
|
52
|
+
const handleRejection = useCallback(error => {
|
|
53
|
+
if (onRejection) {
|
|
54
|
+
onRejection(error);
|
|
55
|
+
}
|
|
56
|
+
}, [onRejection]);
|
|
57
|
+
if (!isInitialized) {
|
|
58
|
+
// Could render a loading state here if needed
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
62
|
+
style: containerStyle
|
|
63
|
+
}, /*#__PURE__*/React.createElement(OnairosButton, {
|
|
64
|
+
AppName: AppName,
|
|
65
|
+
returnLink: returnLink,
|
|
66
|
+
requestData: requestData,
|
|
67
|
+
buttonType: buttonType,
|
|
68
|
+
buttonForm: buttonForm,
|
|
69
|
+
buttonWidth: buttonWidth,
|
|
70
|
+
buttonHeight: buttonHeight,
|
|
71
|
+
color: color,
|
|
72
|
+
hasStroke: hasStroke,
|
|
73
|
+
enabled: true,
|
|
74
|
+
preferredPlatform: preferredPlatform,
|
|
75
|
+
onResolved: handleResolved,
|
|
76
|
+
onRejection: handleRejection,
|
|
77
|
+
preCheck: async () => true,
|
|
78
|
+
testMode: testMode
|
|
79
|
+
}));
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=Onairos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useState","useCallback","useEffect","View","OnairosButton","hasCredentials","getCredentials","Onairos","AppName","returnLink","requestData","buttonType","buttonForm","buttonWidth","buttonHeight","color","hasStroke","preferredPlatform","onResolved","onRejection","testMode","containerStyle","isInitialized","setIsInitialized","hasExistingCredentials","setHasExistingCredentials","initialize","credentialsExist","credentials","username","userPin","error","console","handleResolved","apiUrl","token","userData","handleRejection","createElement","style","enabled","preCheck"],"sourceRoot":"..\\..\\..\\src","sources":["components/Onairos.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,QAAQ,OAAO;AAC/D,SAAmBC,IAAI,QAAQ,cAAc;AAC7C,SAASC,aAAa,QAAQ,iBAAiB;AAE/C,SAASC,cAAc,EAAEC,cAAc,QAAQ,wBAAwB;AA4BvE;AACA;AACA;AACA,OAAO,MAAMC,OAA+B,GAAGA,CAAC;EAC9CC,OAAO;EACPC,UAAU;EACVC,WAAW;EACXC,UAAU,GAAG,QAAQ;EACrBC,UAAU,GAAG,SAAS;EACtBC,WAAW;EACXC,YAAY;EACZC,KAAK;EACLC,SAAS;EACTC,iBAAiB;EACjBC,UAAU;EACVC,WAAW;EACXC,QAAQ,GAAG,KAAK;EAChBC;AACF,CAAC,KAAK;EACJ,MAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGvB,QAAQ,CAAC,KAAK,CAAC;EACzD,MAAM,CAACwB,sBAAsB,EAAEC,yBAAyB,CAAC,GAAGzB,QAAQ,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ZI,OAAO,EAAEA,OAAQ;IACjBC,UAAU,EAAEA,UAAW;IACvBC,WAAW,EAAEA,WAAY;IACzBC,UAAU,EAAEA,UAAW;IACvBC,UAAU,EAAEA,UAAW;IACvBC,WAAW,EAAEA,WAAY;IACzBC,YAAY,EAAEA,YAAa;IAC3BC,KAAK,EAAEA,KAAM;IACbC,SAAS,EAAEA,SAAU;IACrBwB,OAAO,EAAE,IAAK;IACdvB,iBAAiB,EAAEA,iBAAkB;IACrCC,UAAU,EAAEe,cAAe;IAC3Bd,WAAW,EAAEkB,eAAgB;IAC7BI,QAAQ,EAAE,MAAAA,CAAA,KAAY,IAAK;IAC3BrB,QAAQ,EAAEA;EAAS,CACpB,CACG,CAAC;AAEX,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { TouchableOpacity, Text, StyleSheet, View } from 'react-native';
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet, View, ActivityIndicator, Alert } from 'react-native';
|
|
3
3
|
import { UniversalOnboarding } from './UniversalOnboarding';
|
|
4
4
|
import { Overlay } from './Overlay';
|
|
5
|
-
import { hasCredentials, getCredentials } from '../utils/secureStorage';
|
|
5
|
+
import { hasCredentials, getCredentials, clearCredentials } from '../utils/secureStorage';
|
|
6
|
+
import { onairosApi } from '../api';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* OnairosButton Component - A sign-in button similar to Google/Apple sign-in
|
|
10
|
+
*/
|
|
6
11
|
export const OnairosButton = ({
|
|
7
12
|
returnLink,
|
|
8
13
|
prefillUrl,
|
|
@@ -26,37 +31,68 @@ export const OnairosButton = ({
|
|
|
26
31
|
const [showOnboarding, setShowOnboarding] = useState(false);
|
|
27
32
|
const [showOverlay, setShowOverlay] = useState(false);
|
|
28
33
|
const [storedCredentials, setStoredCredentials] = useState(null);
|
|
34
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
29
35
|
const isDarkMode = color === 'black' || !color && !hasStroke;
|
|
30
36
|
const handlePress = async () => {
|
|
31
|
-
if (!enabled) return;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
if (!enabled || isLoading) return;
|
|
38
|
+
setIsLoading(true);
|
|
39
|
+
try {
|
|
40
|
+
if (preCheck) {
|
|
41
|
+
const shouldProceed = await preCheck();
|
|
42
|
+
if (!shouldProceed) {
|
|
43
|
+
onRejection === null || onRejection === void 0 || onRejection('Precheck validation failed');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
37
46
|
}
|
|
38
|
-
}
|
|
39
47
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// Check if credentials exist
|
|
49
|
+
const hasStoredCreds = await hasCredentials();
|
|
50
|
+
if (hasStoredCreds) {
|
|
51
|
+
// If credentials exist, fetch them and verify
|
|
52
|
+
const credentials = await getCredentials();
|
|
53
|
+
if (!credentials || !credentials.username || !credentials.userPin) {
|
|
54
|
+
// Invalid credentials, clear and start fresh
|
|
55
|
+
await clearCredentials();
|
|
56
|
+
setShowOnboarding(true);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Validate credentials with server
|
|
61
|
+
const isValid = await onairosApi.validateCredentials(credentials.username);
|
|
62
|
+
if (!isValid) {
|
|
63
|
+
// Clear invalid credentials
|
|
64
|
+
await clearCredentials();
|
|
65
|
+
setShowOnboarding(true);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Store and display overlay with valid credentials
|
|
70
|
+
setStoredCredentials(credentials);
|
|
71
|
+
setShowOverlay(true);
|
|
72
|
+
} else {
|
|
73
|
+
// If no credentials, show onboarding
|
|
74
|
+
setShowOnboarding(true);
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error('Error during button press flow:', error);
|
|
78
|
+
Alert.alert('Error', 'An error occurred. Please try again later.');
|
|
79
|
+
onRejection === null || onRejection === void 0 || onRejection(error instanceof Error ? error.message : 'Unknown error');
|
|
80
|
+
} finally {
|
|
81
|
+
setIsLoading(false);
|
|
50
82
|
}
|
|
51
83
|
};
|
|
52
|
-
const handleOnboardingComplete = (apiUrl, token, data) => {
|
|
84
|
+
const handleOnboardingComplete = useCallback((apiUrl, token, data) => {
|
|
53
85
|
setShowOnboarding(false);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
86
|
+
if (onResolved) {
|
|
87
|
+
onResolved(apiUrl, token, data);
|
|
88
|
+
}
|
|
89
|
+
}, [onResolved]);
|
|
90
|
+
const handleOverlayResolved = useCallback((apiUrl, token, data) => {
|
|
57
91
|
setShowOverlay(false);
|
|
58
|
-
|
|
59
|
-
|
|
92
|
+
if (onResolved) {
|
|
93
|
+
onResolved(apiUrl, token, data);
|
|
94
|
+
}
|
|
95
|
+
}, [onResolved]);
|
|
60
96
|
|
|
61
97
|
// Calculate button styles based on props
|
|
62
98
|
const buttonStyle = [styles.button, buttonType === 'pill' && styles.pillButton, hasStroke && styles.strokedButton, {
|
|
@@ -64,20 +100,26 @@ export const OnairosButton = ({
|
|
|
64
100
|
height: buttonHeight
|
|
65
101
|
}, color ? {
|
|
66
102
|
backgroundColor: color
|
|
67
|
-
} : null, isDarkMode ? styles.darkButton : styles.lightButton, swerv && styles.swervButton].filter(Boolean);
|
|
103
|
+
} : null, isDarkMode ? styles.darkButton : styles.lightButton, swerv && styles.swervButton, !enabled && styles.disabledButton].filter(Boolean);
|
|
68
104
|
|
|
69
105
|
// Calculate text styles based on props
|
|
70
|
-
const textStyle = [styles.buttonText, isDarkMode ? styles.lightText : styles.darkText].filter(Boolean);
|
|
106
|
+
const textStyle = [styles.buttonText, isDarkMode ? styles.lightText : styles.darkText, !enabled && styles.disabledText].filter(Boolean);
|
|
71
107
|
return /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
72
108
|
style: buttonStyle,
|
|
73
109
|
onPress: handlePress,
|
|
74
|
-
disabled: !enabled,
|
|
110
|
+
disabled: !enabled || isLoading,
|
|
75
111
|
accessibilityLabel: `Sign in with Onairos`
|
|
76
|
-
}, /*#__PURE__*/React.createElement(
|
|
112
|
+
}, isLoading ? /*#__PURE__*/React.createElement(ActivityIndicator, {
|
|
113
|
+
size: "small",
|
|
114
|
+
color: isDarkMode ? '#fff' : '#000'
|
|
115
|
+
}) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
|
|
77
116
|
style: textStyle
|
|
78
|
-
}, "Sign in with Onairos")), showOnboarding && /*#__PURE__*/React.createElement(UniversalOnboarding, {
|
|
117
|
+
}, "Sign in with Onairos"))), showOnboarding && /*#__PURE__*/React.createElement(UniversalOnboarding, {
|
|
79
118
|
visible: showOnboarding,
|
|
80
|
-
onClose: () =>
|
|
119
|
+
onClose: () => {
|
|
120
|
+
setShowOnboarding(false);
|
|
121
|
+
onRejection === null || onRejection === void 0 || onRejection('User closed onboarding');
|
|
122
|
+
},
|
|
81
123
|
AppName: AppName,
|
|
82
124
|
requestData: requestData,
|
|
83
125
|
returnLink: returnLink,
|
|
@@ -122,6 +164,9 @@ const styles = StyleSheet.create({
|
|
|
122
164
|
backgroundColor: '#fff',
|
|
123
165
|
borderColor: '#000'
|
|
124
166
|
},
|
|
167
|
+
disabledButton: {
|
|
168
|
+
opacity: 0.6
|
|
169
|
+
},
|
|
125
170
|
buttonText: {
|
|
126
171
|
fontSize: 16,
|
|
127
172
|
fontWeight: '600',
|
|
@@ -132,6 +177,9 @@ const styles = StyleSheet.create({
|
|
|
132
177
|
},
|
|
133
178
|
darkText: {
|
|
134
179
|
color: '#000'
|
|
180
|
+
},
|
|
181
|
+
disabledText: {
|
|
182
|
+
opacity: 0.7
|
|
135
183
|
}
|
|
136
184
|
});
|
|
137
185
|
//# sourceMappingURL=OnairosButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","TouchableOpacity","Text","StyleSheet","View","UniversalOnboarding","Overlay","hasCredentials","getCredentials","OnairosButton","returnLink","prefillUrl","AppName","buttonType","requestData","buttonWidth","buttonHeight","hasStroke","enabled","buttonForm","onRejection","onResolved","preCheck","color","swerv","debug","preferredPlatform","testMode","showOnboarding","setShowOnboarding","showOverlay","setShowOverlay","storedCredentials","setStoredCredentials","isDarkMode","handlePress","shouldProceed","hasStoredCreds","credentials","handleOnboardingComplete","apiUrl","token","data","handleOverlayResolved","buttonStyle","styles","button","pillButton","strokedButton","width","height","backgroundColor","darkButton","lightButton","swervButton","filter","Boolean","textStyle","buttonText","lightText","darkText","createElement","style","onPress","disabled","accessibilityLabel","
|
|
1
|
+
{"version":3,"names":["React","useState","useCallback","TouchableOpacity","Text","StyleSheet","View","ActivityIndicator","Alert","UniversalOnboarding","Overlay","hasCredentials","getCredentials","clearCredentials","onairosApi","OnairosButton","returnLink","prefillUrl","AppName","buttonType","requestData","buttonWidth","buttonHeight","hasStroke","enabled","buttonForm","onRejection","onResolved","preCheck","color","swerv","debug","preferredPlatform","testMode","showOnboarding","setShowOnboarding","showOverlay","setShowOverlay","storedCredentials","setStoredCredentials","isLoading","setIsLoading","isDarkMode","handlePress","shouldProceed","hasStoredCreds","credentials","username","userPin","isValid","validateCredentials","error","console","alert","Error","message","handleOnboardingComplete","apiUrl","token","data","handleOverlayResolved","buttonStyle","styles","button","pillButton","strokedButton","width","height","backgroundColor","darkButton","lightButton","swervButton","disabledButton","filter","Boolean","textStyle","buttonText","lightText","darkText","disabledText","createElement","style","onPress","disabled","accessibilityLabel","size","Fragment","visible","onClose","onComplete","test","modelKey","create","flexDirection","alignItems","justifyContent","paddingVertical","paddingHorizontal","borderRadius","borderWidth","borderColor","transform","rotate","opacity","fontSize","fontWeight","textAlign"],"sourceRoot":"..\\..\\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,CAEC,CAAC;AAEX,CAAC;AAED,MAAME,MAAM,GAAGzD,UAAU,CAACuF,MAAM,CAAC;EAC/B7B,MAAM,EAAE;IACN8B,aAAa,EAAE,KAAK;IACpBC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE,QAAQ;IACxBC,eAAe,EAAE,EAAE;IACnBC,iBAAiB,EAAE,EAAE;IACrBC,YAAY,EAAE;EAChB,CAAC;EACDlC,UAAU,EAAE;IACVkC,YAAY,EAAE;EAChB,CAAC;EACDjC,aAAa,EAAE;IACbG,eAAe,EAAE,aAAa;IAC9B+B,WAAW,EAAE,CAAC;IACdC,WAAW,EAAE;EACf,CAAC;EACD7B,WAAW,EAAE;IACX8B,SAAS,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAQ,CAAC;EACjC,CAAC;EACDjC,UAAU,EAAE;IACVD,eAAe,EAAE,MAAM;IACvBgC,WAAW,EAAE;EACf,CAAC;EACD9B,WAAW,EAAE;IACXF,eAAe,EAAE,MAAM;IACvBgC,WAAW,EAAE;EACf,CAAC;EACD5B,cAAc,EAAE;IACd+B,OAAO,EAAE;EACX,CAAC;EACD3B,UAAU,EAAE;IACV4B,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE,KAAK;IACjBC,SAAS,EAAE;EACb,CAAC;EACD7B,SAAS,EAAE;IACThD,KAAK,EAAE;EACT,CAAC;EACDiD,QAAQ,EAAE;IACRjD,KAAK,EAAE;EACT,CAAC;EACDkD,YAAY,EAAE;IACZwB,OAAO,EAAE;EACX;AACF,CAAC,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,11 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Onairos React Native SDK
|
|
3
|
+
* A React Native implementation for Onairos personalized data integration
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
|
-
//
|
|
7
|
-
export
|
|
6
|
+
// Main components
|
|
7
|
+
export { Onairos } from './components/Onairos';
|
|
8
|
+
export { OnairosButton } from './components/OnairosButton';
|
|
9
|
+
export { Overlay as OnairosOverlay } from './components/Overlay';
|
|
10
|
+
export { UniversalOnboarding } from './components/UniversalOnboarding';
|
|
8
11
|
|
|
9
|
-
//
|
|
10
|
-
export {
|
|
12
|
+
// Screen Components
|
|
13
|
+
export { ConnectorScreen } from './components/screens/ConnectorScreen';
|
|
14
|
+
export { PinCreationScreen } from './components/screens/PinCreationScreen';
|
|
15
|
+
export { LoadingScreen } from './components/screens/LoadingScreen';
|
|
16
|
+
|
|
17
|
+
// Onboarding Components
|
|
18
|
+
export { OAuthWebView } from './components/onboarding/OAuthWebView';
|
|
19
|
+
export { PlatformConnector } from './components/onboarding/PlatformConnector';
|
|
20
|
+
export { OnboardingHeader } from './components/onboarding/OnboardingHeader';
|
|
21
|
+
export { PinInput } from './components/onboarding/PinInput';
|
|
22
|
+
|
|
23
|
+
// Hooks
|
|
24
|
+
export { useCredentials } from './hooks/useCredentials';
|
|
25
|
+
export { useConnections } from './hooks/useConnections';
|
|
26
|
+
|
|
27
|
+
// Utilities
|
|
28
|
+
export { storeCredentials, getCredentials, hasCredentials, deleteCredentials, updateCredentials, generateDeviceUsername, verifyCredentials } from './utils/secureStorage';
|
|
29
|
+
export { validateCredentials, createAccount, authenticate, refreshToken, getPlatformData, getUserProfile, updatePlatformConnections } from './utils/onairosApi';
|
|
30
|
+
export { rsaEncrypt, sha256, base64ToBuffer } from './utils/crypto';
|
|
31
|
+
export { logDebug, logError, isDebugMode } from './utils/debugHelper';
|
|
32
|
+
|
|
33
|
+
// Services
|
|
34
|
+
export { connectPlatform, disconnectPlatform, initializeOAuthService, cleanupOAuthService, storePlatformConnection } from './services/oauthService';
|
|
35
|
+
|
|
36
|
+
// Types
|
|
37
|
+
|
|
38
|
+
// Constants
|
|
39
|
+
export { COLORS, PLATFORMS, API_ENDPOINTS, STORAGE_KEYS, PIN_REQUIREMENTS, DEEP_LINK_CONFIG } from './constants';
|
|
40
|
+
|
|
41
|
+
// API and Services
|
|
42
|
+
export { onairosApi } from './api';
|
|
43
|
+
export { OAuthService } from './services/OAuthService';
|
|
44
|
+
export * from './utils/secureStorage';
|
|
45
|
+
export * from './utils/encryption';
|
|
11
46
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["OnairosButton","
|
|
1
|
+
{"version":3,"names":["Onairos","OnairosButton","Overlay","OnairosOverlay","UniversalOnboarding","ConnectorScreen","PinCreationScreen","LoadingScreen","OAuthWebView","PlatformConnector","OnboardingHeader","PinInput","useCredentials","useConnections","storeCredentials","getCredentials","hasCredentials","deleteCredentials","updateCredentials","generateDeviceUsername","verifyCredentials","validateCredentials","createAccount","authenticate","refreshToken","getPlatformData","getUserProfile","updatePlatformConnections","rsaEncrypt","sha256","base64ToBuffer","logDebug","logError","isDebugMode","connectPlatform","disconnectPlatform","initializeOAuthService","cleanupOAuthService","storePlatformConnection","COLORS","PLATFORMS","API_ENDPOINTS","STORAGE_KEYS","PIN_REQUIREMENTS","DEEP_LINK_CONFIG","onairosApi","OAuthService"],"sourceRoot":"..\\..\\src","sources":["index.ts"],"mappings":"AAAA;AACA;AACA;AACA;;AAEA;AACA,SAASA,OAAO,QAAQ,sBAAsB;AAC9C,SAASC,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,OAAO,IAAIC,cAAc,QAAQ,sBAAsB;AAChE,SAASC,mBAAmB,QAAQ,kCAAkC;;AAEtE;AACA,SAASC,eAAe,QAAQ,sCAAsC;AACtE,SAASC,iBAAiB,QAAQ,wCAAwC;AAC1E,SAASC,aAAa,QAAQ,oCAAoC;;AAElE;AACA,SAASC,YAAY,QAAQ,sCAAsC;AACnE,SAASC,iBAAiB,QAAQ,2CAA2C;AAC7E,SAASC,gBAAgB,QAAQ,0CAA0C;AAC3E,SAASC,QAAQ,QAAQ,kCAAkC;;AAE3D;AACA,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,cAAc,QAAQ,wBAAwB;;AAEvD;AACA,SACEC,gBAAgB,EAChBC,cAAc,EACdC,cAAc,EACdC,iBAAiB,EACjBC,iBAAiB,EACjBC,sBAAsB,EACtBC,iBAAiB,QACZ,uBAAuB;AAE9B,SACEC,mBAAmB,EACnBC,aAAa,EACbC,YAAY,EACZC,YAAY,EACZC,eAAe,EACfC,cAAc,EACdC,yBAAyB,QACpB,oBAAoB;AAE3B,SACEC,UAAU,EACVC,MAAM,EACNC,cAAc,QACT,gBAAgB;AAEvB,SACEC,QAAQ,EACRC,QAAQ,EACRC,WAAW,QACN,qBAAqB;;AAE5B;AACA,SACEC,eAAe,EACfC,kBAAkB,EAClBC,sBAAsB,EACtBC,mBAAmB,EACnBC,uBAAuB,QAClB,yBAAyB;;AAEhC;;AAoBA;AACA,SAASC,MAAM,EAAEC,SAAS,EAAEC,aAAa,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,gBAAgB,QAAQ,aAAa;;AAEhH;AACA,SAASC,UAAU,QAAQ,OAAO;AAClC,SAASC,YAAY,QAAQ,yBAAyB;AACtD,cAAc,uBAAuB;AACrC,cAAc,oBAAoB","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Linking, Platform } from 'react-native';
|
|
2
2
|
import { updateCredentials } from '../utils/secureStorage';
|
|
3
3
|
import { sha256 } from '../utils/crypto';
|
|
4
|
+
import { onairosApi } from '../api';
|
|
4
5
|
|
|
5
6
|
// Define OAuth configuration types
|
|
6
7
|
|
|
@@ -349,4 +350,147 @@ export const storePlatformConnection = async (platform, connectionData, credenti
|
|
|
349
350
|
return false;
|
|
350
351
|
}
|
|
351
352
|
};
|
|
353
|
+
/**
|
|
354
|
+
* Service for handling OAuth connections to various platforms
|
|
355
|
+
*/
|
|
356
|
+
export const OAuthService = {
|
|
357
|
+
// Base API URL
|
|
358
|
+
_apiBaseUrl: 'https://api2.onairos.uk',
|
|
359
|
+
/**
|
|
360
|
+
* Connect to a specific platform using OAuth
|
|
361
|
+
* @param platform The platform to connect to (e.g., 'instagram', 'youtube')
|
|
362
|
+
* @returns A promise that resolves to a connection result
|
|
363
|
+
*/
|
|
364
|
+
connectPlatform: async platform => {
|
|
365
|
+
try {
|
|
366
|
+
console.log(`[OAuth] Initiating connection to ${platform}`);
|
|
367
|
+
|
|
368
|
+
// Get authorization data from API
|
|
369
|
+
const authData = await OAuthService._getAuthorizationData(platform);
|
|
370
|
+
if (!authData || !authData.accountName) {
|
|
371
|
+
throw new Error(`Failed to get authorization data for ${platform}`);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Launch the OAuth flow in a WebView
|
|
375
|
+
const success = await OAuthService._launchOAuthFlow(platform, `${OAuthService._apiBaseUrl}/${authData.accountName}/authorize`, `onairos://${platform.toLowerCase()}/callback`);
|
|
376
|
+
return {
|
|
377
|
+
success,
|
|
378
|
+
userName: success ? `User_${platform}` : undefined,
|
|
379
|
+
error: success ? undefined : `Failed to connect to ${platform}`
|
|
380
|
+
};
|
|
381
|
+
} catch (error) {
|
|
382
|
+
console.error(`${platform} connection error:`, error);
|
|
383
|
+
return {
|
|
384
|
+
success: false,
|
|
385
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
/**
|
|
390
|
+
* Get authorization data for a platform from the API
|
|
391
|
+
* @param platform The platform to get authorization data for
|
|
392
|
+
* @returns Authorization data for the platform
|
|
393
|
+
*/
|
|
394
|
+
_getAuthorizationData: async platform => {
|
|
395
|
+
try {
|
|
396
|
+
// For testing, we can use a mock app ID
|
|
397
|
+
let appId = 'com.onairos.mock';
|
|
398
|
+
|
|
399
|
+
// In real implementation, we would get this from the app's package info
|
|
400
|
+
try {
|
|
401
|
+
// This would normally use react-native-device-info or similar
|
|
402
|
+
// appId = await DeviceInfo.getBundleId();
|
|
403
|
+
} catch (e) {
|
|
404
|
+
console.warn('Failed to get app identifier:', e);
|
|
405
|
+
}
|
|
406
|
+
const response = await onairosApi.post('getOAuthData', {
|
|
407
|
+
platform,
|
|
408
|
+
appId: appId,
|
|
409
|
+
redirectUri: `onairos://${platform.toLowerCase()}/callback`
|
|
410
|
+
});
|
|
411
|
+
if (response && response.accountName) {
|
|
412
|
+
return {
|
|
413
|
+
accountName: response.accountName,
|
|
414
|
+
authUrl: `${OAuthService._apiBaseUrl}/${response.accountName}/authorize`
|
|
415
|
+
};
|
|
416
|
+
} else {
|
|
417
|
+
throw new Error('Invalid response from getOAuthData');
|
|
418
|
+
}
|
|
419
|
+
} catch (error) {
|
|
420
|
+
console.error('Error getting authorization data:', error);
|
|
421
|
+
throw error;
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
/**
|
|
425
|
+
* Launch the OAuth flow for a platform
|
|
426
|
+
* @param platform The platform to launch the OAuth flow for
|
|
427
|
+
* @param authUrl The URL to authorize with
|
|
428
|
+
* @param callbackUrlPattern The URL pattern to expect as a callback
|
|
429
|
+
* @returns A promise that resolves to true if the connection was successful
|
|
430
|
+
*/
|
|
431
|
+
_launchOAuthFlow: async (platform, authUrl, callbackUrlPattern) => {
|
|
432
|
+
try {
|
|
433
|
+
console.log(`[OAuth] Opening URL for ${platform}: ${authUrl}`);
|
|
434
|
+
|
|
435
|
+
// For now, we'll use a simpler approach just to mock the flow
|
|
436
|
+
// In a real implementation, this would open a WebView in a modal
|
|
437
|
+
// and handle the OAuth callback
|
|
438
|
+
|
|
439
|
+
// Check if we can open the URL
|
|
440
|
+
const canOpen = await Linking.canOpenURL(authUrl);
|
|
441
|
+
if (!canOpen) {
|
|
442
|
+
throw new Error(`Cannot open URL: ${authUrl}`);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// We'll simulate a successful connection after a delay
|
|
446
|
+
// In a real app, this would be handled by the WebView navigation
|
|
447
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
448
|
+
|
|
449
|
+
// Return success
|
|
450
|
+
return true;
|
|
451
|
+
} catch (error) {
|
|
452
|
+
console.error(`Error launching OAuth flow for ${platform}:`, error);
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
/**
|
|
457
|
+
* Handle an OAuth callback URL
|
|
458
|
+
* @param url The callback URL to handle
|
|
459
|
+
* @returns The result of processing the callback
|
|
460
|
+
*/
|
|
461
|
+
handleCallback: async url => {
|
|
462
|
+
try {
|
|
463
|
+
console.log(`[OAuth] Handling callback URL: ${url}`);
|
|
464
|
+
|
|
465
|
+
// Extract the platform and parameters from the URL
|
|
466
|
+
const urlParts = url.split('/');
|
|
467
|
+
const platform = urlParts[2]; // Assuming format is onairos://platform/callback
|
|
468
|
+
|
|
469
|
+
// Extract query parameters
|
|
470
|
+
const params = new URLSearchParams(url.split('?')[1] || '');
|
|
471
|
+
const code = params.get('code');
|
|
472
|
+
if (!code) {
|
|
473
|
+
return {
|
|
474
|
+
success: false,
|
|
475
|
+
error: 'No authorization code found in callback URL'
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// In a real implementation, we would send the code to the API
|
|
480
|
+
// to get an access token
|
|
481
|
+
|
|
482
|
+
// Simulate a successful connection
|
|
483
|
+
return {
|
|
484
|
+
success: true,
|
|
485
|
+
userName: `User_${platform}`
|
|
486
|
+
};
|
|
487
|
+
} catch (error) {
|
|
488
|
+
console.error('Error handling OAuth callback:', error);
|
|
489
|
+
return {
|
|
490
|
+
success: false,
|
|
491
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
};
|
|
352
496
|
//# sourceMappingURL=oauthService.js.map
|