@onairos/react-native 3.1.16 → 3.1.18
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 +404 -0
- package/lib/commonjs/assets/images/Checkbox.svg +3 -3
- package/lib/commonjs/assets/images/EnochE.svg +19 -19
- package/lib/commonjs/assets/images/Personalityprofile.svg +3 -3
- package/lib/commonjs/assets/images/Personalitytraits.svg +3 -3
- package/lib/commonjs/assets/images/Userpreferences.svg +3 -3
- package/lib/commonjs/assets/images/arrow.svg +20 -20
- package/lib/commonjs/assets/images/basicproficon.svg +43 -43
- package/lib/commonjs/assets/images/basicprofile.svg +3 -3
- package/lib/commonjs/assets/images/checkmark.svg +4 -4
- package/lib/commonjs/assets/images/contentanalysis.svg +3 -3
- package/lib/commonjs/assets/images/contenticon.svg +23 -23
- package/lib/commonjs/assets/images/personalityicon.svg +18 -18
- package/lib/commonjs/assets/images/x-close.svg +3 -3
- package/lib/commonjs/components/ModalSheet.js +8 -2
- package/lib/commonjs/components/ModalSheet.js.map +1 -1
- package/lib/commonjs/components/OnairosButton.js +290 -0
- package/lib/commonjs/components/OnairosButton.js.map +1 -0
- package/lib/commonjs/components/OnairosSignInButton.js +32 -8
- package/lib/commonjs/components/OnairosSignInButton.js.map +1 -1
- package/lib/commonjs/components/UniversalOnboarding.js +4 -4
- package/lib/commonjs/components/WelcomeScreen.js +29 -13
- package/lib/commonjs/components/WelcomeScreen.js.map +1 -1
- package/lib/commonjs/config/api.js +2 -2
- package/lib/commonjs/hooks/useConnections.js +6 -6
- package/lib/commonjs/hooks/useUserConnections.js +10 -10
- package/lib/commonjs/index.js +13 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/services/apiClient.js +35 -35
- package/lib/commonjs/services/apiKeyService.js +99 -99
- package/lib/commonjs/services/authService.js +82 -82
- package/lib/commonjs/services/biometricPinService.js +10 -10
- package/lib/commonjs/services/connectedAccountsService.js +32 -32
- package/lib/commonjs/services/googleAuthService.js +15 -15
- package/lib/commonjs/services/imageCompressionService.js +15 -15
- package/lib/commonjs/services/jwtStorageService.js +59 -59
- package/lib/commonjs/services/mobileTrainingService.js +14 -14
- package/lib/commonjs/services/pinEncryptionService.js +10 -10
- package/lib/commonjs/services/pinStorageUtils.js +15 -15
- package/lib/commonjs/services/platformAuthService.js +47 -47
- package/lib/commonjs/services/storageService.js +31 -31
- package/lib/commonjs/services/trainingApiHelpers.js +33 -33
- package/lib/commonjs/services/userConnectionsService.js +24 -24
- package/lib/commonjs/utils/Portal.js +4 -4
- package/lib/commonjs/utils/api.js +24 -24
- package/lib/commonjs/utils/auth.js +18 -18
- package/lib/commonjs/utils/crypto.js +13 -13
- package/lib/commonjs/utils/encryption.js +12 -12
- package/lib/commonjs/utils/eventUtils.js +52 -52
- package/lib/commonjs/utils/programmaticFlow.js +16 -16
- package/lib/commonjs/utils/retryHelper.js +27 -27
- package/lib/module/assets/images/Checkbox.svg +3 -3
- package/lib/module/assets/images/EnochE.svg +19 -19
- package/lib/module/assets/images/Personalityprofile.svg +3 -3
- package/lib/module/assets/images/Personalitytraits.svg +3 -3
- package/lib/module/assets/images/Userpreferences.svg +3 -3
- package/lib/module/assets/images/arrow.svg +20 -20
- package/lib/module/assets/images/basicproficon.svg +43 -43
- package/lib/module/assets/images/basicprofile.svg +3 -3
- package/lib/module/assets/images/checkmark.svg +4 -4
- package/lib/module/assets/images/contentanalysis.svg +3 -3
- package/lib/module/assets/images/contenticon.svg +23 -23
- package/lib/module/assets/images/personalityicon.svg +18 -18
- package/lib/module/assets/images/x-close.svg +3 -3
- package/lib/module/components/ModalSheet.js +7 -2
- package/lib/module/components/ModalSheet.js.map +1 -1
- package/lib/module/components/OnairosButton.js +282 -0
- package/lib/module/components/OnairosButton.js.map +1 -0
- package/lib/module/components/OnairosSignInButton.js +32 -8
- package/lib/module/components/OnairosSignInButton.js.map +1 -1
- package/lib/module/components/UniversalOnboarding.js +4 -4
- package/lib/module/components/WelcomeScreen.js +25 -10
- package/lib/module/components/WelcomeScreen.js.map +1 -1
- package/lib/module/config/api.js +2 -2
- package/lib/module/hooks/useConnections.js +6 -6
- package/lib/module/hooks/useUserConnections.js +10 -10
- package/lib/module/index.js +11 -11
- package/lib/module/index.js.map +1 -1
- package/lib/module/services/apiClient.js +35 -35
- package/lib/module/services/apiKeyService.js +99 -99
- package/lib/module/services/authService.js +82 -82
- package/lib/module/services/biometricPinService.js +10 -10
- package/lib/module/services/connectedAccountsService.js +32 -32
- package/lib/module/services/googleAuthService.js +15 -15
- package/lib/module/services/imageCompressionService.js +15 -15
- package/lib/module/services/jwtStorageService.js +59 -59
- package/lib/module/services/mobileTrainingService.js +14 -14
- package/lib/module/services/pinEncryptionService.js +10 -10
- package/lib/module/services/pinStorageUtils.js +15 -15
- package/lib/module/services/platformAuthService.js +47 -47
- package/lib/module/services/storageService.js +31 -31
- package/lib/module/services/trainingApiHelpers.js +33 -33
- package/lib/module/services/userConnectionsService.js +24 -24
- package/lib/module/utils/Portal.js +4 -4
- package/lib/module/utils/api.js +24 -24
- package/lib/module/utils/auth.js +18 -18
- package/lib/module/utils/crypto.js +13 -13
- package/lib/module/utils/encryption.js +12 -12
- package/lib/module/utils/eventUtils.js +52 -52
- package/lib/module/utils/programmaticFlow.js +16 -16
- package/lib/module/utils/retryHelper.js +27 -27
- package/lib/typescript/components/ModalSheet.d.ts.map +1 -1
- package/lib/typescript/components/OnairosButton.d.ts +37 -0
- package/lib/typescript/components/OnairosButton.d.ts.map +1 -0
- package/lib/typescript/components/OnairosSignInButton.d.ts.map +1 -1
- package/lib/typescript/components/WelcomeScreen.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +3 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +145 -163
- package/src/api/index.ts +151 -151
- package/src/assets/images/Checkbox.svg +3 -3
- package/src/assets/images/EnochE.svg +19 -19
- package/src/assets/images/Personalityprofile.svg +3 -3
- package/src/assets/images/Personalitytraits.svg +3 -3
- package/src/assets/images/Userpreferences.svg +3 -3
- package/src/assets/images/arrow.svg +20 -20
- package/src/assets/images/basicproficon.svg +43 -43
- package/src/assets/images/basicprofile.svg +3 -3
- package/src/assets/images/checkmark.svg +4 -4
- package/src/assets/images/contentanalysis.svg +3 -3
- package/src/assets/images/contenticon.svg +23 -23
- package/src/assets/images/personalityicon.svg +18 -18
- package/src/assets/images/x-close.svg +3 -3
- package/src/components/BodyText.tsx +33 -33
- package/src/components/BrandMark.tsx +62 -62
- package/src/components/CodeInput.tsx +32 -32
- package/src/components/DataRequestScreen.tsx +355 -355
- package/src/components/EmailInput.tsx +31 -31
- package/src/components/EmailVerificationModal.tsx +363 -363
- package/src/components/ExistingUserDataConfirmation.tsx +506 -506
- package/src/components/GoogleButton.tsx +55 -55
- package/src/components/HeadingGroup.tsx +49 -49
- package/src/components/ModalHeader.tsx +125 -125
- package/src/components/ModalSheet.tsx +59 -57
- package/src/components/Onairos.tsx +422 -422
- package/src/components/OnairosButton.tsx +339 -0
- package/src/components/OnairosSignInButton.tsx +31 -9
- package/src/components/Overlay.tsx +506 -506
- package/src/components/PersonaImage.tsx +79 -79
- package/src/components/PersonaLoadingScreen.tsx +201 -201
- package/src/components/PersonalizationConsentScreen.tsx +410 -410
- package/src/components/PinCreationScreen.tsx +492 -492
- package/src/components/PinInput.tsx +555 -555
- package/src/components/PlatformConnectorsStep.tsx +891 -891
- package/src/components/PlatformList.tsx +144 -144
- package/src/components/PlatformToggle.tsx +226 -226
- package/src/components/PrimaryButton.tsx +213 -213
- package/src/components/SignInMatchAnimation.tsx +225 -225
- package/src/components/SignInStep.tsx +217 -217
- package/src/components/TrainingModal.tsx +1047 -1047
- package/src/components/UniversalOnboarding.tsx +2887 -2887
- package/src/components/VerificationStep.tsx +198 -198
- package/src/components/WelcomeScreen.tsx +490 -473
- package/src/components/icons/Basicproficon.tsx +30 -30
- package/src/components/icons/Basicprofile.tsx +17 -17
- package/src/components/icons/Checkbox.tsx +17 -17
- package/src/components/icons/Checkmark.tsx +24 -24
- package/src/components/icons/Contentanalysis.tsx +17 -17
- package/src/components/icons/Contenticon.tsx +30 -30
- package/src/components/icons/EnochE.tsx +39 -39
- package/src/components/icons/Personalityicon.tsx +22 -22
- package/src/components/icons/Personalityprofile.tsx +17 -17
- package/src/components/icons/Personalitytraits.tsx +17 -17
- package/src/components/icons/Userpreferences.tsx +17 -17
- package/src/components/icons/index.ts +12 -12
- package/src/components/onboarding/OAuthWebView.tsx +232 -232
- package/src/config/api.ts +25 -25
- package/src/context/AuthContext.tsx +393 -393
- package/src/hooks/useConnectedAccounts.ts +138 -138
- package/src/hooks/useConnections.ts +161 -161
- package/src/hooks/useCredentials.ts +174 -174
- package/src/hooks/useUserConnections.ts +165 -165
- package/src/index.js +14 -0
- package/src/index.ts +99 -96
- package/src/services/apiClient.ts +336 -336
- package/src/services/apiKeyService.ts +919 -919
- package/src/services/authService.ts +1008 -1008
- package/src/services/biometricPinService.ts +192 -192
- package/src/services/connectedAccountsService.ts +289 -289
- package/src/services/googleAuthService.ts +279 -279
- package/src/services/imageCompressionService.ts +302 -302
- package/src/services/jwtStorageService.ts +256 -256
- package/src/services/mobileTrainingService.ts +203 -203
- package/src/services/pinEncryptionService.ts +75 -75
- package/src/services/pinStorageUtils.ts +96 -96
- package/src/services/platformAuthService.ts +1346 -1346
- package/src/services/storageService.ts +451 -451
- package/src/services/trainingApiHelpers.ts +66 -66
- package/src/services/userConnectionsService.ts +556 -556
- package/src/services/youtubeMigrationService.ts +453 -453
- package/src/theme/index.ts +239 -239
- package/src/types/ambient.d.ts +28 -28
- package/src/types/index.ts +265 -265
- package/src/types/node-fix.d.ts +18 -18
- package/src/types/node-override.d.ts +23 -23
- package/src/types/opacity.d.ts +15 -15
- package/src/types/types.d.ts +17 -17
- package/src/utils/Portal.tsx +82 -82
- package/src/utils/api.js +111 -111
- package/src/utils/auth.js +103 -103
- package/src/utils/crypto.js +59 -59
- package/src/utils/encryption.ts +68 -68
- package/src/utils/eventUtils.ts +302 -302
- package/src/utils/haptics.ts +58 -58
- package/src/utils/imagePreloader.ts +2 -2
- package/src/utils/programmaticFlow.ts +112 -112
- package/src/utils/retryHelper.ts +274 -274
package/lib/module/index.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* PUBLIC API - Complete redesigned UI and enhanced functionality
|
|
6
|
-
*/
|
|
1
|
+
import OnairosButton from './components/OnairosButton';
|
|
2
|
+
import * as AuthUtils from './utils/auth';
|
|
3
|
+
import * as CryptoUtils from './utils/crypto';
|
|
4
|
+
import * as ApiUtils from './utils/api';
|
|
7
5
|
|
|
8
|
-
//
|
|
6
|
+
// Export the main component
|
|
7
|
+
export default OnairosButton;
|
|
9
8
|
|
|
10
|
-
// Export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export { OnairosSignInButton } from './components/OnairosSignInButton';
|
|
9
|
+
// Export utilities for advanced usage
|
|
10
|
+
export { AuthUtils, CryptoUtils, ApiUtils };
|
|
11
|
+
//# sourceMappingURL=index.js.mapInButton';
|
|
14
12
|
export { Onairos } from './components/Onairos';
|
|
15
13
|
export { UniversalOnboarding } from './components/UniversalOnboarding';
|
|
16
14
|
|
|
@@ -57,11 +55,13 @@ export { ApiClient } from './services/apiClient';
|
|
|
57
55
|
// export { AuthProvider } from './context/AuthContext';
|
|
58
56
|
|
|
59
57
|
// Default export for convenience
|
|
58
|
+
import { OnairosButton } from './components/OnairosButton';
|
|
60
59
|
import { OnairosSignInButton } from './components/OnairosSignInButton';
|
|
61
60
|
import { Onairos } from './components/Onairos';
|
|
62
61
|
import { UniversalOnboarding } from './components/UniversalOnboarding';
|
|
63
62
|
import WelcomeScreen from './components/WelcomeScreen';
|
|
64
63
|
export default {
|
|
64
|
+
OnairosButton,
|
|
65
65
|
OnairosSignInButton,
|
|
66
66
|
Onairos,
|
|
67
67
|
UniversalOnboarding,
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["OnairosButton","AuthUtils","CryptoUtils","ApiUtils"],"sourceRoot":"../../src","sources":["index.js"],"mappings":"AAAA,OAAOA,aAAa,MAAM,4BAA4B;AACtD,OAAO,KAAKC,SAAS,MAAM,cAAc;AACzC,OAAO,KAAKC,WAAW,MAAM,gBAAgB;AAC7C,OAAO,KAAKC,QAAQ,MAAM,aAAa;;AAEvC;AACA,eAAeH,aAAa;;AAE5B;AACA,SACEC,SAAS,EACTC,WAAW,EACXC,QAAQ","ignoreList":[]}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { getJWTForRoute, TokenType, getTokenTypeForRoute, clearJWT, getAllTokens } from './jwtStorageService';
|
|
2
2
|
import { API_CONFIG } from '../config/api';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Centralized API Client with Route-Based JWT Token Management
|
|
6
|
-
* CORRECTED APPROACH: Uses different JWT tokens for different route families
|
|
7
|
-
*
|
|
8
|
-
* TOKEN ROUTING:
|
|
9
|
-
* - Enoch JWT: /enoch/*, /api/auth/*, /mobile-training/enoch
|
|
10
|
-
* - Onairos JWT: /youtube/*, /gmail/*, social connections
|
|
11
|
-
* - Auth Token: Context-specific auth flows
|
|
4
|
+
/**
|
|
5
|
+
* Centralized API Client with Route-Based JWT Token Management
|
|
6
|
+
* CORRECTED APPROACH: Uses different JWT tokens for different route families
|
|
7
|
+
*
|
|
8
|
+
* TOKEN ROUTING:
|
|
9
|
+
* - Enoch JWT: /enoch/*, /api/auth/*, /mobile-training/enoch
|
|
10
|
+
* - Onairos JWT: /youtube/*, /gmail/*, social connections
|
|
11
|
+
* - Auth Token: Context-specific auth flows
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Global request counter for tracking in-flight requests
|
|
14
|
+
/**
|
|
15
|
+
* Global request counter for tracking in-flight requests
|
|
16
16
|
*/
|
|
17
17
|
let currentRequestId = 0;
|
|
18
18
|
const activeRequests = new Map();
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
* Route-specific authentication triggers
|
|
20
|
+
/**
|
|
21
|
+
* Route-specific authentication triggers
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
* Create API client with route-based token management
|
|
24
|
+
/**
|
|
25
|
+
* Create API client with route-based token management
|
|
26
26
|
*/
|
|
27
27
|
class ApiClient {
|
|
28
28
|
constructor(baseUrl = API_CONFIG.BASE_URL, authTriggers = {}) {
|
|
@@ -30,9 +30,9 @@ class ApiClient {
|
|
|
30
30
|
this.authTriggers = authTriggers;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/**
|
|
34
|
-
* Make authenticated API request with route-based token selection
|
|
35
|
-
* CRITICAL: Uses the correct token type based on route
|
|
33
|
+
/**
|
|
34
|
+
* Make authenticated API request with route-based token selection
|
|
35
|
+
* CRITICAL: Uses the correct token type based on route
|
|
36
36
|
*/
|
|
37
37
|
async request(endpoint, options = {}) {
|
|
38
38
|
const requestId = ++currentRequestId;
|
|
@@ -101,9 +101,9 @@ class ApiClient {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* Get request headers with route-appropriate token
|
|
106
|
-
* CRITICAL: Selects correct token based on route
|
|
104
|
+
/**
|
|
105
|
+
* Get request headers with route-appropriate token
|
|
106
|
+
* CRITICAL: Selects correct token based on route
|
|
107
107
|
*/
|
|
108
108
|
async getRequestHeaders(endpoint, requiresAuth) {
|
|
109
109
|
if (!requiresAuth) {
|
|
@@ -121,9 +121,9 @@ class ApiClient {
|
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
/**
|
|
125
|
-
* Handle 401 errors with route-specific re-authentication
|
|
126
|
-
* CRITICAL FIX: Different auth flows for different token types
|
|
124
|
+
/**
|
|
125
|
+
* Handle 401 errors with route-specific re-authentication
|
|
126
|
+
* CRITICAL FIX: Different auth flows for different token types
|
|
127
127
|
*/
|
|
128
128
|
async handle401Error(requestId, endpoint, tokenType, options) {
|
|
129
129
|
console.error(`🚫 [API Client] Request ${requestId} received 401 for ${tokenType} token on route: ${endpoint}`);
|
|
@@ -146,8 +146,8 @@ class ApiClient {
|
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
/**
|
|
150
|
-
* Trigger appropriate re-authentication based on token type
|
|
149
|
+
/**
|
|
150
|
+
* Trigger appropriate re-authentication based on token type
|
|
151
151
|
*/
|
|
152
152
|
async triggerReAuthForTokenType(tokenType, endpoint) {
|
|
153
153
|
console.log(`🔄 [API Client] Triggering re-auth for ${tokenType} token (endpoint: ${endpoint})`);
|
|
@@ -183,8 +183,8 @@ class ApiClient {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
/**
|
|
187
|
-
* Cancel requests using a specific token type
|
|
186
|
+
/**
|
|
187
|
+
* Cancel requests using a specific token type
|
|
188
188
|
*/
|
|
189
189
|
cancelRequestsForTokenType(tokenType, excludeRequestId) {
|
|
190
190
|
let cancelledCount = 0;
|
|
@@ -203,8 +203,8 @@ class ApiClient {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
/**
|
|
207
|
-
* Replace token for specific type and cancel related requests
|
|
206
|
+
/**
|
|
207
|
+
* Replace token for specific type and cancel related requests
|
|
208
208
|
*/
|
|
209
209
|
async replaceTokenForType(tokenType, newToken) {
|
|
210
210
|
console.log(`🔄 [API Client] Replacing ${tokenType} token`);
|
|
@@ -223,8 +223,8 @@ class ApiClient {
|
|
|
223
223
|
return replaced;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
/**
|
|
227
|
-
* Debug: Get all current tokens
|
|
226
|
+
/**
|
|
227
|
+
* Debug: Get all current tokens
|
|
228
228
|
*/
|
|
229
229
|
async debugTokens() {
|
|
230
230
|
console.log('🔍 [API Client] Debug: Current token status');
|
|
@@ -239,8 +239,8 @@ class ApiClient {
|
|
|
239
239
|
return tokens;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
/**
|
|
243
|
-
* Set authentication triggers
|
|
242
|
+
/**
|
|
243
|
+
* Set authentication triggers
|
|
244
244
|
*/
|
|
245
245
|
setAuthTriggers(triggers) {
|
|
246
246
|
this.authTriggers = {
|
|
@@ -250,8 +250,8 @@ class ApiClient {
|
|
|
250
250
|
console.log('🔧 [API Client] Authentication triggers updated');
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
/**
|
|
254
|
-
* Convenience methods for common HTTP verbs
|
|
253
|
+
/**
|
|
254
|
+
* Convenience methods for common HTTP verbs
|
|
255
255
|
*/
|
|
256
256
|
async get(endpoint, options = {}) {
|
|
257
257
|
return this.request(endpoint, {
|
|
@@ -14,23 +14,23 @@ export let ApiKeyType = /*#__PURE__*/function (ApiKeyType) {
|
|
|
14
14
|
// JWT token storage key
|
|
15
15
|
const JWT_TOKEN_KEY = 'onairos_jwt_token';
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Two-Tier Authentication Service for Onairos React Native SDK
|
|
19
|
-
*
|
|
20
|
-
* This service implements the two-tier authentication system:
|
|
21
|
-
* 1. Developer API Keys: For app-level operations (email verification, app registration)
|
|
22
|
-
* 2. JWT User Tokens: For user-level operations (PIN storage, user profile)
|
|
23
|
-
*
|
|
24
|
-
* How it works:
|
|
25
|
-
* 1. Initialize with developer API key
|
|
26
|
-
* 2. Use API key for email verification requests
|
|
27
|
-
* 3. Store JWT token from email verification response
|
|
28
|
-
* 4. Use JWT token for user-authenticated requests
|
|
29
|
-
* 5. Handle token expiration gracefully
|
|
30
|
-
*
|
|
31
|
-
* Backend Integration:
|
|
32
|
-
* - Developer routes: Authorization: Bearer ${API_KEY}
|
|
33
|
-
* - User routes: Authorization: Bearer ${JWT_TOKEN}
|
|
17
|
+
/**
|
|
18
|
+
* Two-Tier Authentication Service for Onairos React Native SDK
|
|
19
|
+
*
|
|
20
|
+
* This service implements the two-tier authentication system:
|
|
21
|
+
* 1. Developer API Keys: For app-level operations (email verification, app registration)
|
|
22
|
+
* 2. JWT User Tokens: For user-level operations (PIN storage, user profile)
|
|
23
|
+
*
|
|
24
|
+
* How it works:
|
|
25
|
+
* 1. Initialize with developer API key
|
|
26
|
+
* 2. Use API key for email verification requests
|
|
27
|
+
* 3. Store JWT token from email verification response
|
|
28
|
+
* 4. Use JWT token for user-authenticated requests
|
|
29
|
+
* 5. Handle token expiration gracefully
|
|
30
|
+
*
|
|
31
|
+
* Backend Integration:
|
|
32
|
+
* - Developer routes: Authorization: Bearer ${API_KEY}
|
|
33
|
+
* - User routes: Authorization: Bearer ${JWT_TOKEN}
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
// Global configuration state
|
|
@@ -49,9 +49,9 @@ const API_ENDPOINTS = {
|
|
|
49
49
|
development: 'https://dev-api.onairos.uk'
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
/**
|
|
53
|
-
* Initialize the SDK with developer API key
|
|
54
|
-
* @param config API configuration including developer API key
|
|
52
|
+
/**
|
|
53
|
+
* Initialize the SDK with developer API key
|
|
54
|
+
* @param config API configuration including developer API key
|
|
55
55
|
*/
|
|
56
56
|
export const initializeApiKey = async config => {
|
|
57
57
|
try {
|
|
@@ -124,10 +124,10 @@ export const initializeApiKey = async config => {
|
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
-
/**
|
|
128
|
-
* Determine API key type
|
|
129
|
-
* @param apiKey The API key to check
|
|
130
|
-
* @returns The type of API key
|
|
127
|
+
/**
|
|
128
|
+
* Determine API key type
|
|
129
|
+
* @param apiKey The API key to check
|
|
130
|
+
* @returns The type of API key
|
|
131
131
|
*/
|
|
132
132
|
export const getApiKeyType = apiKey => {
|
|
133
133
|
if (apiKey === ADMIN_API_KEY) {
|
|
@@ -141,19 +141,19 @@ export const getApiKeyType = apiKey => {
|
|
|
141
141
|
return ApiKeyType.INVALID;
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
-
/**
|
|
145
|
-
* Check if API key is admin key
|
|
146
|
-
* @param apiKey The API key to check
|
|
147
|
-
* @returns True if admin key
|
|
144
|
+
/**
|
|
145
|
+
* Check if API key is admin key
|
|
146
|
+
* @param apiKey The API key to check
|
|
147
|
+
* @returns True if admin key
|
|
148
148
|
*/
|
|
149
149
|
export const isAdminKey = apiKey => {
|
|
150
150
|
return apiKey === ADMIN_API_KEY;
|
|
151
151
|
};
|
|
152
152
|
|
|
153
|
-
/**
|
|
154
|
-
* Validate an API key with the Onairos backend
|
|
155
|
-
* @param apiKey The API key to validate
|
|
156
|
-
* @returns Validation result with permissions and rate limits
|
|
153
|
+
/**
|
|
154
|
+
* Validate an API key with the Onairos backend
|
|
155
|
+
* @param apiKey The API key to validate
|
|
156
|
+
* @returns Validation result with permissions and rate limits
|
|
157
157
|
*/
|
|
158
158
|
export const validateApiKey = async apiKey => {
|
|
159
159
|
try {
|
|
@@ -389,34 +389,34 @@ export const validateApiKey = async apiKey => {
|
|
|
389
389
|
}
|
|
390
390
|
};
|
|
391
391
|
|
|
392
|
-
/**
|
|
393
|
-
* Get the current API configuration
|
|
394
|
-
* @returns Current API configuration or null if not initialized
|
|
392
|
+
/**
|
|
393
|
+
* Get the current API configuration
|
|
394
|
+
* @returns Current API configuration or null if not initialized
|
|
395
395
|
*/
|
|
396
396
|
export const getApiConfig = () => {
|
|
397
397
|
return globalConfig;
|
|
398
398
|
};
|
|
399
399
|
|
|
400
|
-
/**
|
|
401
|
-
* Get the current API key
|
|
402
|
-
* @returns Current API key or null if not initialized
|
|
400
|
+
/**
|
|
401
|
+
* Get the current API key
|
|
402
|
+
* @returns Current API key or null if not initialized
|
|
403
403
|
*/
|
|
404
404
|
export const getApiKey = () => {
|
|
405
405
|
var _globalConfig9;
|
|
406
406
|
return ((_globalConfig9 = globalConfig) === null || _globalConfig9 === void 0 ? void 0 : _globalConfig9.apiKey) || null;
|
|
407
407
|
};
|
|
408
408
|
|
|
409
|
-
/**
|
|
410
|
-
* Check if the SDK is properly initialized
|
|
411
|
-
* @returns True if initialized with valid API key
|
|
409
|
+
/**
|
|
410
|
+
* Check if the SDK is properly initialized
|
|
411
|
+
* @returns True if initialized with valid API key
|
|
412
412
|
*/
|
|
413
413
|
export const isApiKeyInitialized = () => {
|
|
414
414
|
return isInitialized && globalConfig !== null;
|
|
415
415
|
};
|
|
416
416
|
|
|
417
|
-
/**
|
|
418
|
-
* Store JWT token securely after email verification
|
|
419
|
-
* @param token JWT token from email verification response
|
|
417
|
+
/**
|
|
418
|
+
* Store JWT token securely after email verification
|
|
419
|
+
* @param token JWT token from email verification response
|
|
420
420
|
*/
|
|
421
421
|
export const storeJWT = async token => {
|
|
422
422
|
try {
|
|
@@ -432,9 +432,9 @@ export const storeJWT = async token => {
|
|
|
432
432
|
}
|
|
433
433
|
};
|
|
434
434
|
|
|
435
|
-
/**
|
|
436
|
-
* Load JWT token from storage
|
|
437
|
-
* @returns JWT token or null if not found
|
|
435
|
+
/**
|
|
436
|
+
* Load JWT token from storage
|
|
437
|
+
* @returns JWT token or null if not found
|
|
438
438
|
*/
|
|
439
439
|
export const loadJWT = async () => {
|
|
440
440
|
try {
|
|
@@ -447,16 +447,16 @@ export const loadJWT = async () => {
|
|
|
447
447
|
}
|
|
448
448
|
};
|
|
449
449
|
|
|
450
|
-
/**
|
|
451
|
-
* Get current JWT token
|
|
452
|
-
* @returns JWT token or null if not available
|
|
450
|
+
/**
|
|
451
|
+
* Get current JWT token
|
|
452
|
+
* @returns JWT token or null if not available
|
|
453
453
|
*/
|
|
454
454
|
export const getJWT = () => {
|
|
455
455
|
return userToken;
|
|
456
456
|
};
|
|
457
457
|
|
|
458
|
-
/**
|
|
459
|
-
* Clear JWT token (on logout or token expiration)
|
|
458
|
+
/**
|
|
459
|
+
* Clear JWT token (on logout or token expiration)
|
|
460
460
|
*/
|
|
461
461
|
export const clearJWT = async () => {
|
|
462
462
|
try {
|
|
@@ -471,10 +471,10 @@ export const clearJWT = async () => {
|
|
|
471
471
|
}
|
|
472
472
|
};
|
|
473
473
|
|
|
474
|
-
/**
|
|
475
|
-
* React Native compatible base64 decoder
|
|
476
|
-
* @param str Base64 encoded string
|
|
477
|
-
* @returns Decoded string
|
|
474
|
+
/**
|
|
475
|
+
* React Native compatible base64 decoder
|
|
476
|
+
* @param str Base64 encoded string
|
|
477
|
+
* @returns Decoded string
|
|
478
478
|
*/
|
|
479
479
|
const base64Decode = str => {
|
|
480
480
|
// Simple base64 decoding for React Native
|
|
@@ -495,10 +495,10 @@ const base64Decode = str => {
|
|
|
495
495
|
return result;
|
|
496
496
|
};
|
|
497
497
|
|
|
498
|
-
/**
|
|
499
|
-
* Decode JWT token payload (React Native compatible)
|
|
500
|
-
* @param token JWT token string
|
|
501
|
-
* @returns Decoded payload or null if invalid
|
|
498
|
+
/**
|
|
499
|
+
* Decode JWT token payload (React Native compatible)
|
|
500
|
+
* @param token JWT token string
|
|
501
|
+
* @returns Decoded payload or null if invalid
|
|
502
502
|
*/
|
|
503
503
|
export const decodeJWTPayload = token => {
|
|
504
504
|
try {
|
|
@@ -525,10 +525,10 @@ export const decodeJWTPayload = token => {
|
|
|
525
525
|
}
|
|
526
526
|
};
|
|
527
527
|
|
|
528
|
-
/**
|
|
529
|
-
* Extract username from JWT token
|
|
530
|
-
* @param token JWT token (optional, uses stored token if not provided)
|
|
531
|
-
* @returns Username or null if not found
|
|
528
|
+
/**
|
|
529
|
+
* Extract username from JWT token
|
|
530
|
+
* @param token JWT token (optional, uses stored token if not provided)
|
|
531
|
+
* @returns Username or null if not found
|
|
532
532
|
*/
|
|
533
533
|
export const extractUsernameFromJWT = token => {
|
|
534
534
|
try {
|
|
@@ -555,10 +555,10 @@ export const extractUsernameFromJWT = token => {
|
|
|
555
555
|
}
|
|
556
556
|
};
|
|
557
557
|
|
|
558
|
-
/**
|
|
559
|
-
* Extract user data from JWT token
|
|
560
|
-
* @param token JWT token (optional, uses stored token if not provided)
|
|
561
|
-
* @returns User data object or null if not found
|
|
558
|
+
/**
|
|
559
|
+
* Extract user data from JWT token
|
|
560
|
+
* @param token JWT token (optional, uses stored token if not provided)
|
|
561
|
+
* @returns User data object or null if not found
|
|
562
562
|
*/
|
|
563
563
|
export const extractUserDataFromJWT = token => {
|
|
564
564
|
try {
|
|
@@ -591,17 +591,17 @@ export const extractUserDataFromJWT = token => {
|
|
|
591
591
|
}
|
|
592
592
|
};
|
|
593
593
|
|
|
594
|
-
/**
|
|
595
|
-
* Check if user is authenticated with JWT token
|
|
596
|
-
* @returns True if user has valid JWT token
|
|
594
|
+
/**
|
|
595
|
+
* Check if user is authenticated with JWT token
|
|
596
|
+
* @returns True if user has valid JWT token
|
|
597
597
|
*/
|
|
598
598
|
export const isUserAuthenticated = () => {
|
|
599
599
|
return !!userToken;
|
|
600
600
|
};
|
|
601
601
|
|
|
602
|
-
/**
|
|
603
|
-
* Get authenticated headers for API requests
|
|
604
|
-
* @returns Headers object with Authorization and other required headers
|
|
602
|
+
/**
|
|
603
|
+
* Get authenticated headers for API requests
|
|
604
|
+
* @returns Headers object with Authorization and other required headers
|
|
605
605
|
*/
|
|
606
606
|
export const getAuthHeaders = () => {
|
|
607
607
|
var _globalConfig12;
|
|
@@ -620,9 +620,9 @@ export const getAuthHeaders = () => {
|
|
|
620
620
|
};
|
|
621
621
|
};
|
|
622
622
|
|
|
623
|
-
/**
|
|
624
|
-
* Get authentication headers for developer API requests
|
|
625
|
-
* @returns Headers with developer API key
|
|
623
|
+
/**
|
|
624
|
+
* Get authentication headers for developer API requests
|
|
625
|
+
* @returns Headers with developer API key
|
|
626
626
|
*/
|
|
627
627
|
export const getDeveloperAuthHeaders = () => {
|
|
628
628
|
var _globalConfig13;
|
|
@@ -641,9 +641,9 @@ export const getDeveloperAuthHeaders = () => {
|
|
|
641
641
|
};
|
|
642
642
|
};
|
|
643
643
|
|
|
644
|
-
/**
|
|
645
|
-
* Get authentication headers for user JWT requests
|
|
646
|
-
* @returns Headers with user JWT token
|
|
644
|
+
/**
|
|
645
|
+
* Get authentication headers for user JWT requests
|
|
646
|
+
* @returns Headers with user JWT token
|
|
647
647
|
*/
|
|
648
648
|
export const getUserAuthHeaders = () => {
|
|
649
649
|
var _globalConfig14;
|
|
@@ -659,11 +659,11 @@ export const getUserAuthHeaders = () => {
|
|
|
659
659
|
};
|
|
660
660
|
};
|
|
661
661
|
|
|
662
|
-
/**
|
|
663
|
-
* Make an authenticated API request
|
|
664
|
-
* @param endpoint The API endpoint (relative to base URL)
|
|
665
|
-
* @param options Fetch options
|
|
666
|
-
* @returns Response promise
|
|
662
|
+
/**
|
|
663
|
+
* Make an authenticated API request
|
|
664
|
+
* @param endpoint The API endpoint (relative to base URL)
|
|
665
|
+
* @param options Fetch options
|
|
666
|
+
* @returns Response promise
|
|
667
667
|
*/
|
|
668
668
|
export const makeAuthenticatedRequest = async (endpoint, options = {}) => {
|
|
669
669
|
if (!isApiKeyInitialized()) {
|
|
@@ -720,11 +720,11 @@ export const makeAuthenticatedRequest = async (endpoint, options = {}) => {
|
|
|
720
720
|
}
|
|
721
721
|
};
|
|
722
722
|
|
|
723
|
-
/**
|
|
724
|
-
* Make authenticated request with developer API key
|
|
725
|
-
* @param endpoint The API endpoint
|
|
726
|
-
* @param options Fetch options
|
|
727
|
-
* @returns Response promise
|
|
723
|
+
/**
|
|
724
|
+
* Make authenticated request with developer API key
|
|
725
|
+
* @param endpoint The API endpoint
|
|
726
|
+
* @param options Fetch options
|
|
727
|
+
* @returns Response promise
|
|
728
728
|
*/
|
|
729
729
|
export const makeDeveloperRequest = async (endpoint, options = {}) => {
|
|
730
730
|
if (!isApiKeyInitialized()) {
|
|
@@ -781,11 +781,11 @@ export const makeDeveloperRequest = async (endpoint, options = {}) => {
|
|
|
781
781
|
}
|
|
782
782
|
};
|
|
783
783
|
|
|
784
|
-
/**
|
|
785
|
-
* Make authenticated request with user JWT token
|
|
786
|
-
* @param endpoint The API endpoint
|
|
787
|
-
* @param options Fetch options
|
|
788
|
-
* @returns Response promise
|
|
784
|
+
/**
|
|
785
|
+
* Make authenticated request with user JWT token
|
|
786
|
+
* @param endpoint The API endpoint
|
|
787
|
+
* @param options Fetch options
|
|
788
|
+
* @returns Response promise
|
|
789
789
|
*/
|
|
790
790
|
export const makeUserRequest = async (endpoint, options = {}) => {
|
|
791
791
|
if (!isUserAuthenticated()) {
|
|
@@ -846,8 +846,8 @@ export const makeUserRequest = async (endpoint, options = {}) => {
|
|
|
846
846
|
}
|
|
847
847
|
};
|
|
848
848
|
|
|
849
|
-
/**
|
|
850
|
-
* Clear the API key validation cache
|
|
849
|
+
/**
|
|
850
|
+
* Clear the API key validation cache
|
|
851
851
|
*/
|
|
852
852
|
export const clearValidationCache = () => {
|
|
853
853
|
var _globalConfig15;
|
|
@@ -857,8 +857,8 @@ export const clearValidationCache = () => {
|
|
|
857
857
|
}
|
|
858
858
|
};
|
|
859
859
|
|
|
860
|
-
/**
|
|
861
|
-
* Reset the SDK initialization state
|
|
860
|
+
/**
|
|
861
|
+
* Reset the SDK initialization state
|
|
862
862
|
*/
|
|
863
863
|
export const resetApiKeyService = () => {
|
|
864
864
|
globalConfig = null;
|