@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,117 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
|
+
const API_URL = 'https://api2.onairos.uk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create an API instance with authorization headers
|
|
7
|
+
* @returns {Promise<Object>} - The axios instance
|
|
8
|
+
*/
|
|
9
|
+
export const createApiInstance = async () => {
|
|
10
|
+
const token = await AsyncStorage.getItem('onairosToken');
|
|
11
|
+
return axios.create({
|
|
12
|
+
baseURL: API_URL,
|
|
13
|
+
headers: {
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
...(token ? {
|
|
16
|
+
'Authorization': `Bearer ${token}`
|
|
17
|
+
} : {})
|
|
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 {
|
|
34
|
+
status: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Fetch account information
|
|
41
|
+
* @param {string} identifier - The username or email
|
|
42
|
+
* @param {boolean} isEmail - Whether the identifier is an email
|
|
43
|
+
* @returns {Promise<Object>} - The account information
|
|
44
|
+
*/
|
|
45
|
+
export const fetchAccountInfo = async (identifier, isEmail = false) => {
|
|
46
|
+
try {
|
|
47
|
+
const api = await createApiInstance();
|
|
48
|
+
const jsonData = isEmail ? {
|
|
49
|
+
Info: {
|
|
50
|
+
identifier
|
|
51
|
+
}
|
|
52
|
+
} : {
|
|
53
|
+
Info: {
|
|
54
|
+
userName: identifier
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const endpoint = isEmail ? '/getAccountInfo/email' : '/getAccountInfo';
|
|
58
|
+
const response = await api.post(endpoint, jsonData);
|
|
59
|
+
return response.data;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error('Error fetching account info:', error);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get API URL for data requests
|
|
68
|
+
* @param {Array} approvedRequests - The approved data requests
|
|
69
|
+
* @param {string} pin - The encrypted PIN
|
|
70
|
+
* @param {string} othentSub - The hashed Othent sub
|
|
71
|
+
* @returns {Promise<Object>} - The API URL response
|
|
72
|
+
*/
|
|
73
|
+
export const getApiUrl = async (approvedRequests, pin, othentSub) => {
|
|
74
|
+
try {
|
|
75
|
+
const api = await createApiInstance();
|
|
76
|
+
const jsonData = {
|
|
77
|
+
Info: {
|
|
78
|
+
EncryptedUserPin: pin,
|
|
79
|
+
confirmations: approvedRequests,
|
|
80
|
+
web3Type: 'othent',
|
|
81
|
+
Domain: Platform.OS,
|
|
82
|
+
proofMode: false,
|
|
83
|
+
OthentSub: othentSub
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const response = await api.post('/getAPIurl', jsonData);
|
|
87
|
+
return response.data;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error('Error getting API URL:', error);
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Create a new user account
|
|
96
|
+
* @param {string} othentSub - The hashed Othent sub
|
|
97
|
+
* @param {string} pin - The PIN
|
|
98
|
+
* @param {Array} socialAccounts - The selected social accounts
|
|
99
|
+
* @param {string} email - The user's email
|
|
100
|
+
* @returns {Promise<Object>} - The account creation response
|
|
101
|
+
*/
|
|
102
|
+
export const createAccount = async (othentSub, pin, socialAccounts, email) => {
|
|
103
|
+
try {
|
|
104
|
+
const api = await createApiInstance();
|
|
105
|
+
const response = await api.post('/createAccount', {
|
|
106
|
+
othentSub,
|
|
107
|
+
pin,
|
|
108
|
+
socialAccounts,
|
|
109
|
+
email
|
|
110
|
+
});
|
|
111
|
+
return response.data;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('Error creating account:', error);
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["axios","AsyncStorage","API_URL","createApiInstance","token","getItem","create","baseURL","headers","validateDomain","api","response","post","data","error","console","status","fetchAccountInfo","identifier","isEmail","jsonData","Info","userName","endpoint","getApiUrl","approvedRequests","pin","othentSub","EncryptedUserPin","confirmations","web3Type","Domain","Platform","OS","proofMode","OthentSub","createAccount","socialAccounts","email"],"sourceRoot":"..\\..\\..\\src","sources":["utils/api.js"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,YAAY,MAAM,2CAA2C;AAEpE,MAAMC,OAAO,GAAG,yBAAyB;;AAEzC;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAG,MAAAA,CAAA,KAAY;EAC3C,MAAMC,KAAK,GAAG,MAAMH,YAAY,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AC","ignoreList":[]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
|
+
const API_URL = 'https://api2.onairos.uk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get the encrypted PIN for a user
|
|
7
|
+
* @param {string} hashedOthentSub - The hashed Othent sub
|
|
8
|
+
* @returns {Promise<Object>} - The response containing the encrypted PIN
|
|
9
|
+
*/
|
|
10
|
+
export const getPin = async hashedOthentSub => {
|
|
11
|
+
try {
|
|
12
|
+
const response = await axios.post(`${API_URL}/getPin`, {
|
|
13
|
+
hashedOthentSub
|
|
14
|
+
});
|
|
15
|
+
return response.data;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error('Error getting PIN:', error);
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Verify a token with the Onairos API
|
|
24
|
+
* @param {string} token - The token to verify
|
|
25
|
+
* @returns {Promise<boolean>} - Whether the token is valid
|
|
26
|
+
*/
|
|
27
|
+
export const verifyToken = async token => {
|
|
28
|
+
try {
|
|
29
|
+
const response = await axios.post(`${API_URL}/verifyToken`, {}, {
|
|
30
|
+
headers: {
|
|
31
|
+
'Authorization': `Bearer ${token}`
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return response.data.valid;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error('Error verifying token:', error);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Store authentication data
|
|
43
|
+
* @param {string} token - The authentication token
|
|
44
|
+
* @param {string} username - The username
|
|
45
|
+
* @param {Object} othentData - The Othent user data
|
|
46
|
+
*/
|
|
47
|
+
export const storeAuthData = async (token, username = null, othentData = null) => {
|
|
48
|
+
try {
|
|
49
|
+
await AsyncStorage.setItem('onairosToken', token);
|
|
50
|
+
if (username) {
|
|
51
|
+
await AsyncStorage.setItem('username', username);
|
|
52
|
+
}
|
|
53
|
+
if (othentData) {
|
|
54
|
+
await AsyncStorage.setItem('othentToken', JSON.stringify(othentData));
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('Error storing auth data:', error);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Clear authentication data
|
|
64
|
+
*/
|
|
65
|
+
export const clearAuthData = async () => {
|
|
66
|
+
try {
|
|
67
|
+
await AsyncStorage.removeItem('onairosToken');
|
|
68
|
+
await AsyncStorage.removeItem('username');
|
|
69
|
+
await AsyncStorage.removeItem('othentToken');
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('Error clearing auth data:', error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get stored authentication data
|
|
78
|
+
* @returns {Promise<Object>} - The stored authentication data
|
|
79
|
+
*/
|
|
80
|
+
export const getStoredAuthData = async () => {
|
|
81
|
+
try {
|
|
82
|
+
const token = await AsyncStorage.getItem('onairosToken');
|
|
83
|
+
const username = await AsyncStorage.getItem('username');
|
|
84
|
+
const othentToken = await AsyncStorage.getItem('othentToken');
|
|
85
|
+
return {
|
|
86
|
+
token,
|
|
87
|
+
username,
|
|
88
|
+
othentToken: othentToken ? JSON.parse(othentToken) : null
|
|
89
|
+
};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error('Error getting stored auth data:', error);
|
|
92
|
+
return {
|
|
93
|
+
token: null,
|
|
94
|
+
username: null,
|
|
95
|
+
othentToken: null
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["axios","AsyncStorage","API_URL","getPin","hashedOthentSub","response","post","data","error","console","verifyToken","token","headers","valid","storeAuthData","username","othentData","setItem","JSON","stringify","clearAuthData","removeItem","getStoredAuthData","getItem","othentToken","parse"],"sourceRoot":"..\\..\\..\\src","sources":["utils/auth.js"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,YAAY,MAAM,2CAA2C;AAEpE,MAAMC,OAAO,GAAG,yBAAyB;;AAEzC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,MAAM,GAAG,MAAOC,eAAe,IAAK;EAC/C,IAAI;IACF,MAAMC,QAAQ,GAAG,MAAML,KAAK,CAACM,IAAI,CAAC,GAAGJ,OAAO,SAAS,EAAE;MACrDE;IACF,CAAC,CAAC;IAEF,OAAOC,QAAQ,CAACE,IAAI;EACtB,CAAC,CAAC,OAAOC,KAAK,EAAE;IACdC,OAAO,CAACD,KAAK,CAAC,oBAAoB,EAAEA,KAAK,CAAC;IAC1C,MAAMA,KAAK;EACb;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,WAAW,GAAG,MAAOC,KAAK,IAAK;EAC1C,IAAI;IACF,MAAMN,QAAQ,GAAG,MAAML,KAAK,CAACM,IAAI,CAAC,GAAGJ,OAAO,cAAc,EAAE,CAAC,CAAC,EAAE;MAC9DU,OAAO,EAAE;QACP,eAAe,EAAE,UAAUD,KAAK;MAClC;IACF,CAAC,CAAC;IAEF,OAAON,QAAQ,CAACE,IAAI,CAACM,KAAK;EAC5B,CAAC,CAAC,OAAOL,KAAK,EAAE;IACdC,OAAO,CAACD,KAAK,CAAC,wBAAwB,EAAEA,KAAK,CAAC;IAC9C,OAAO,KAAK;EACd;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,aAAa,GAAG,MAAAA,CAAOH,KAAK,EAAEI,QAAQ,GAAG,IAAI,EAAEC,UAAU,GAAG,IAAI,KAAK;EAChF,IAAI;IACF,MAAMf,YAAY,CAACgB,OAAO,CAAC,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AiC,EAAEA,KAAK,CAAC;IACvD,OAAO;MACLG,KAAK,EAAE,IAAI;MACXI,QAAQ,EAAE,IAAI;MACdS,WAAW,EAAE;IACf,CAAC;EACH;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RSA } from 'react-native-rsa-native';
|
|
2
|
+
import { sha256 as cryptoSha256 } from 'react-native-crypto-js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Encrypt data using RSA
|
|
6
|
+
* @param {string} publicKey - The RSA public key
|
|
7
|
+
* @param {string} data - The data to encrypt
|
|
8
|
+
* @returns {Promise<string>} - The encrypted data
|
|
9
|
+
*/
|
|
10
|
+
export const rsaEncrypt = async (publicKey, data) => {
|
|
11
|
+
try {
|
|
12
|
+
// Clean the public key format
|
|
13
|
+
const cleanedKey = publicKey.replace(/\\n/g, '').replace(/^\s+|\s+$/g, '').replace('-----BEGIN PUBLIC KEY-----', '').replace('-----END PUBLIC KEY-----', '').trim();
|
|
14
|
+
|
|
15
|
+
// Format the key properly for the library
|
|
16
|
+
const formattedKey = `-----BEGIN PUBLIC KEY-----\n${cleanedKey}\n-----END PUBLIC KEY-----`;
|
|
17
|
+
|
|
18
|
+
// Encrypt the data
|
|
19
|
+
const encrypted = await RSA.encrypt(data, formattedKey);
|
|
20
|
+
return encrypted;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error('RSA encryption failed:', error);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Hash data using SHA-256
|
|
29
|
+
* @param {string} data - The data to hash
|
|
30
|
+
* @returns {string} - The hashed data
|
|
31
|
+
*/
|
|
32
|
+
export const sha256 = data => {
|
|
33
|
+
return cryptoSha256(data).toString();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Convert a base64 string to a buffer
|
|
38
|
+
* @param {string} base64String - The base64 string to convert
|
|
39
|
+
* @returns {ArrayBuffer} - The converted buffer
|
|
40
|
+
*/
|
|
41
|
+
export const base64ToBuffer = base64String => {
|
|
42
|
+
try {
|
|
43
|
+
const binaryString = Buffer.from(base64String, 'base64').toString('binary');
|
|
44
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
45
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
46
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
47
|
+
}
|
|
48
|
+
return bytes.buffer;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error('Error converting base64 to buffer:', error);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RSA","sha256","cryptoSha256","rsaEncrypt","publicKey","data","cleanedKey","replace","trim","formattedKey","encrypted","encrypt","error","console","toString","base64ToBuffer","base64String","binaryString","Buffer","from","bytes","Uint8Array","length","i","charCodeAt","buffer"],"sourceRoot":"..\\..\\..\\src","sources":["utils/crypto.js"],"mappings":"AAAA,SAASA,GAAG,QAAQ,yBAAyB;AAC7C,SAASC,MAAM,IAAIC,YAAY,QAAQ,wBAAwB;;AAE/D;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAG,MAAAA,CAAOC,SAAS,EAAEC,IAAI,KAAK;EACnD,IAAI;IACF;IACA,MAAMC,UAAU,GAAGF,SAAS,CACzBG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CACnBA,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CACzBA,OAAO,CAAC,4BAA4B,EAAE,EAAE,CAAC,CACzCA,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC,CACvCC,IAAI,CAAC,CAAC;;IAET;IACA,MAAMC,YAAY,GAAG,+BAA+BH,UAAU,4BAA4B;;IAE1F;IACA,MAAMI,SAAS,GAAG,MAAMV,GAAG,CAACW,OAAO,CAACN,IAAI,EAAEI,YAAY,CAAC;IACvD,OAAOC,SAAS;EAClB,CAAC,CAAC,OAAOE,KAAK,EAAE;IACdC,OAAO,CAACD,KAAK,CAAC,wBAAwB,EAAEA,KAAK,CAAC;IAC9C,MAAMA,KAAK;EACb;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMX,MAAM,GAAII,IAAI,IAAK;EAC9B,OAAOH,YAAY,CAACG,IAAI,CAAC,CAACS,QAAQ,CAAC,CAAC;AACtC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,GAAIC,YAAY,IAAK;EAC9C,IAAI;IACF,MAAMC,YAAY,GAAGC,MAAM,CAACC,IAAI,CAACH,YAAY,EAAE,QAAQ,CAAC,CAACF,QAAQ,CAAC,QAAQ,CAAC;IAC3E,MAAMM,KAAK,GAAG,IAAIC,UAAU,CAACJ,YAAY,CAACK,MAAM,CAAC;IAEjD,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,YAAY,CAACK,MAAM,EAAEC,CAAC,EAAE,EAAE;MAC5CH,KAAK,CAACG,CAAC,CAAC,GAAGN,YAAY,CAACO,UAAU,CAACD,CAAC,CAAC;IACvC;IAEA,OAAOH,KAAK,CAACK,MAAM;EACrB,CAAC,CAAC,OAAOb,KAAK,EAAE;IACdC,OAAO,CAACD,KAAK,CAAC,oCAAoC,EAAEA,KAAK,CAAC;IAC1D,MAAMA,KAAK;EACb;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug utility functions for Onairos React Native SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Determine if we're in dev mode
|
|
6
|
+
const __DEV__ = process.env.NODE_ENV !== 'production';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Log debug message to console when in development mode
|
|
10
|
+
* @param label Label for the debug message
|
|
11
|
+
* @param data Data to log
|
|
12
|
+
*/
|
|
13
|
+
export const logDebug = (label, data) => {
|
|
14
|
+
if (__DEV__) {
|
|
15
|
+
console.log(`[Onairos Debug] ${label}:`, data || '');
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Log error message to console
|
|
21
|
+
* @param label Label for the error message
|
|
22
|
+
* @param error Error object or message
|
|
23
|
+
*/
|
|
24
|
+
export const logError = (label, error) => {
|
|
25
|
+
if (__DEV__) {
|
|
26
|
+
console.error(`[Onairos Error] ${label}:`, error);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Check if debug mode is enabled
|
|
32
|
+
* @param debug Debug flag passed to component
|
|
33
|
+
* @returns Whether debug mode is enabled
|
|
34
|
+
*/
|
|
35
|
+
export const isDebugMode = debug => {
|
|
36
|
+
return debug === true || __DEV__;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Format and log API request details
|
|
41
|
+
* @param method HTTP method
|
|
42
|
+
* @param url API URL
|
|
43
|
+
* @param data Request data
|
|
44
|
+
*/
|
|
45
|
+
export const logApiRequest = (method, url, data) => {
|
|
46
|
+
if (__DEV__) {
|
|
47
|
+
logDebug('API Request', {
|
|
48
|
+
method,
|
|
49
|
+
url,
|
|
50
|
+
data: data || {}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=debugHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__DEV__","process","env","NODE_ENV","logDebug","label","data","console","log","logError","error","isDebugMode","debug","logApiRequest","method","url"],"sourceRoot":"..\\..\\..\\src","sources":["utils/debugHelper.ts"],"mappings":"AAAA;AACA;AACA;;AAEA;AACA,MAAMA,OAAO,GAAGC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY;;AAErD;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,QAAQ,GAAGA,CAACC,KAAa,EAAEC,IAAU,KAAW;EAC3D,IAAIN,OAAO,EAAE;IACXO,OAAO,CAACC,GAAG,CAAC,mBAAmBH,KAAK,GAAG,EAAEC,IAAI,IAAI,EAAE,CAAC;EACtD;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,QAAQ,GAAGA,CAACJ,KAAa,EAAEK,KAAU,KAAW;EAC3D,IAAIV,OAAO,EAAE;IACXO,OAAO,CAACG,KAAK,CAAC,mBAAmBL,KAAK,GAAG,EAAEK,KAAK,CAAC;EACnD;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAIC,KAAe,IAAc;EACvD,OAAOA,KAAK,KAAK,IAAI,IAAIZ,OAAO;AAClC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMa,aAAa,GAAGA,CAACC,MAAc,EAAEC,GAAW,EAAET,IAAU,KAAW;EAC9E,IAAIN,OAAO,EAAE;IACXI,QAAQ,CAAC,aAAa,EAAE;MACtBU,MAAM;MACNC,GAAG;MACHT,IAAI,EAAEA,IAAI,IAAI,CAAC;IACjB,CAAC,CAAC;EACJ;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import NetInfo from '@react-native-community/netinfo';
|
|
3
|
+
import { logDebug } from './debugHelper';
|
|
4
|
+
|
|
5
|
+
// API configuration
|
|
6
|
+
const API_CONFIG = {
|
|
7
|
+
baseUrl: 'https://api2.onairos.uk',
|
|
8
|
+
version: 'v1',
|
|
9
|
+
timeout: 30000 // 30 seconds
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// API response types
|
|
13
|
+
|
|
14
|
+
// Error types
|
|
15
|
+
|
|
16
|
+
// API error structure
|
|
17
|
+
export class ApiError extends Error {
|
|
18
|
+
constructor(message, type, code, details) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.type = type;
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.details = details;
|
|
23
|
+
this.name = 'ApiError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Check if the device has an active network connection
|
|
29
|
+
*/
|
|
30
|
+
const checkNetworkConnection = async () => {
|
|
31
|
+
const networkState = await NetInfo.fetch();
|
|
32
|
+
return networkState.isConnected === true;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Build API request headers
|
|
37
|
+
*/
|
|
38
|
+
const buildHeaders = (accessToken, additionalHeaders = {}) => {
|
|
39
|
+
const headers = {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
'Accept': 'application/json',
|
|
42
|
+
'User-Agent': `OnairosReactNative/${Platform.OS}/${Platform.Version}`,
|
|
43
|
+
...additionalHeaders
|
|
44
|
+
};
|
|
45
|
+
if (accessToken) {
|
|
46
|
+
headers['Authorization'] = `Bearer ${accessToken}`;
|
|
47
|
+
}
|
|
48
|
+
return headers;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Make API request with proper error handling
|
|
53
|
+
*/
|
|
54
|
+
const apiRequest = async (endpoint, method, options = {}) => {
|
|
55
|
+
const {
|
|
56
|
+
data,
|
|
57
|
+
accessToken,
|
|
58
|
+
headers = {},
|
|
59
|
+
timeout = API_CONFIG.timeout,
|
|
60
|
+
debug = false
|
|
61
|
+
} = options;
|
|
62
|
+
try {
|
|
63
|
+
// Check for network connectivity
|
|
64
|
+
const isConnected = await checkNetworkConnection();
|
|
65
|
+
if (!isConnected) {
|
|
66
|
+
throw new ApiError('No network connection available', 'network_error');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Build request URL
|
|
70
|
+
const url = `${API_CONFIG.baseUrl}/${API_CONFIG.version}/${endpoint}`;
|
|
71
|
+
|
|
72
|
+
// Log request information if debug mode is enabled
|
|
73
|
+
if (debug) {
|
|
74
|
+
logDebug('API Request', {
|
|
75
|
+
url,
|
|
76
|
+
method,
|
|
77
|
+
headers: {
|
|
78
|
+
...buildHeaders(accessToken, headers),
|
|
79
|
+
Authorization: accessToken ? '[REDACTED]' : undefined
|
|
80
|
+
},
|
|
81
|
+
data: data || null
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Set up request options
|
|
86
|
+
const fetchOptions = {
|
|
87
|
+
method,
|
|
88
|
+
headers: buildHeaders(accessToken, headers),
|
|
89
|
+
...(data ? {
|
|
90
|
+
body: JSON.stringify(data)
|
|
91
|
+
} : {})
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Create fetch request with timeout
|
|
95
|
+
const controller = new AbortController();
|
|
96
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
97
|
+
|
|
98
|
+
// Execute request
|
|
99
|
+
const response = await fetch(url, {
|
|
100
|
+
...fetchOptions,
|
|
101
|
+
signal: controller.signal
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Clear timeout
|
|
105
|
+
clearTimeout(timeoutId);
|
|
106
|
+
|
|
107
|
+
// Parse response as JSON
|
|
108
|
+
const responseData = await response.json();
|
|
109
|
+
|
|
110
|
+
// Log response if debug mode is enabled
|
|
111
|
+
if (debug) {
|
|
112
|
+
logDebug('API Response', {
|
|
113
|
+
status: response.status,
|
|
114
|
+
data: responseData
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Handle API error responses
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
var _responseData$error, _responseData$error2, _responseData$error3;
|
|
121
|
+
const errorType = response.status === 401 || response.status === 403 ? 'auth_error' : response.status === 400 ? 'validation_error' : response.status >= 500 ? 'server_error' : 'unknown_error';
|
|
122
|
+
throw new ApiError(((_responseData$error = responseData.error) === null || _responseData$error === void 0 ? void 0 : _responseData$error.message) || 'API request failed', errorType, (_responseData$error2 = responseData.error) === null || _responseData$error2 === void 0 ? void 0 : _responseData$error2.code, (_responseData$error3 = responseData.error) === null || _responseData$error3 === void 0 ? void 0 : _responseData$error3.details);
|
|
123
|
+
}
|
|
124
|
+
return responseData;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
// Handle specific error types
|
|
127
|
+
if (error instanceof ApiError) {
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
if (error.name === 'AbortError') {
|
|
131
|
+
throw new ApiError('Request timed out', 'timeout_error');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Log error if debug mode is enabled
|
|
135
|
+
if (debug) {
|
|
136
|
+
logDebug('API Error', {
|
|
137
|
+
endpoint,
|
|
138
|
+
method,
|
|
139
|
+
error: error.message || 'Unknown error'
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Return a generic error for all other cases
|
|
144
|
+
throw new ApiError(error.message || 'An unexpected error occurred', 'unknown_error');
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Validate user credentials with the API
|
|
150
|
+
*/
|
|
151
|
+
export const validateCredentials = async (username, options = {
|
|
152
|
+
debug: false
|
|
153
|
+
}) => {
|
|
154
|
+
try {
|
|
155
|
+
var _response$data, _response$error;
|
|
156
|
+
const response = await apiRequest('auth/validate', 'POST', {
|
|
157
|
+
data: {
|
|
158
|
+
username
|
|
159
|
+
},
|
|
160
|
+
debug: options.debug
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
isValid: response.success && ((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.isValid) === true,
|
|
164
|
+
message: (_response$error = response.error) === null || _response$error === void 0 ? void 0 : _response$error.message
|
|
165
|
+
};
|
|
166
|
+
} catch (error) {
|
|
167
|
+
return {
|
|
168
|
+
isValid: false,
|
|
169
|
+
message: error.message
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Create a new user account
|
|
176
|
+
*/
|
|
177
|
+
export const createAccount = async (credentials, options = {
|
|
178
|
+
debug: false
|
|
179
|
+
}) => {
|
|
180
|
+
return apiRequest('auth/register', 'POST', {
|
|
181
|
+
data: {
|
|
182
|
+
username: credentials.username,
|
|
183
|
+
platforms: credentials.platforms
|
|
184
|
+
},
|
|
185
|
+
debug: options.debug
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Authenticate with the API using credentials
|
|
191
|
+
*/
|
|
192
|
+
export const authenticate = async (credentials, options = {
|
|
193
|
+
debug: false
|
|
194
|
+
}) => {
|
|
195
|
+
return apiRequest('auth/login', 'POST', {
|
|
196
|
+
data: {
|
|
197
|
+
username: credentials.username,
|
|
198
|
+
pin: credentials.userPin
|
|
199
|
+
},
|
|
200
|
+
debug: options.debug
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Refresh authentication token
|
|
206
|
+
*/
|
|
207
|
+
export const refreshToken = async (refreshToken, options = {
|
|
208
|
+
debug: false
|
|
209
|
+
}) => {
|
|
210
|
+
return apiRequest('auth/refresh', 'POST', {
|
|
211
|
+
data: {
|
|
212
|
+
refreshToken
|
|
213
|
+
},
|
|
214
|
+
debug: options.debug
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Get user's connected platform data
|
|
220
|
+
*/
|
|
221
|
+
export const getPlatformData = async (accessToken, platform, options = {
|
|
222
|
+
debug: false
|
|
223
|
+
}) => {
|
|
224
|
+
return apiRequest(`platforms/${platform}/data`, 'GET', {
|
|
225
|
+
accessToken,
|
|
226
|
+
debug: options.debug
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Get user profile information
|
|
232
|
+
*/
|
|
233
|
+
export const getUserProfile = async (accessToken, options = {
|
|
234
|
+
debug: false
|
|
235
|
+
}) => {
|
|
236
|
+
return apiRequest('user/profile', 'GET', {
|
|
237
|
+
accessToken,
|
|
238
|
+
debug: options.debug
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Update user platform connections
|
|
244
|
+
*/
|
|
245
|
+
export const updatePlatformConnections = async (accessToken, platforms, options = {
|
|
246
|
+
debug: false
|
|
247
|
+
}) => {
|
|
248
|
+
return apiRequest('user/platforms', 'PUT', {
|
|
249
|
+
accessToken,
|
|
250
|
+
data: {
|
|
251
|
+
platforms
|
|
252
|
+
},
|
|
253
|
+
debug: options.debug
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
//# sourceMappingURL=onairosApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Platform","NetInfo","logDebug","API_CONFIG","baseUrl","version","timeout","ApiError","Error","constructor","message","type","code","details","name","checkNetworkConnection","networkState","fetch","isConnected","buildHeaders","accessToken","additionalHeaders","headers","OS","Version","apiRequest","endpoint","method","options","data","debug","url","Authorization","undefined","fetchOptions","body","JSON","stringify","controller","AbortController","timeoutId","setTimeout","abort","response","signal","clearTimeout","responseData","json","status","ok","_responseData$error","_responseData$error2","_responseData$error3","errorType","error","validateCredentials","username","_response$data","_response$error","isValid","success","createAccount","credentials","platforms","authenticate","pin","userPin","refreshToken","getPlatformData","platform","getUserProfile","updatePlatformConnections"],"sourceRoot":"..\\..\\..\\src","sources":["utils/onairosApi.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,OAAOC,OAAO,MAAM,iCAAiC;AAErD,SAASC,QAAQ,QAAQ,eAAe;;AAExC;AACA,MAAMC,UAAU,GAAG;EACjBC,OAAO,EAAE,yBAAyB;EAClCC,OAAO,EAAE,IAAI;EACbC,OAAO,EAAE,KAAK,CAAE;AAClB,CAAC;;AAED;;AAWA;;AASA;AACA,OAAO,MAAMC,QAAQ,SAASC,KAAK,CAAC;EAKlCC,WAAWA,CAACC,OAA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