@onairos/react-native 3.5.4 → 3.6.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 +423 -423
- package/lib/commonjs/api/index.js +1 -1
- package/lib/commonjs/assets/images/Checkbox.svg +3 -3
- package/lib/commonjs/assets/images/EnochE.svg +19 -19
- package/lib/commonjs/assets/images/OnairosNewLogo.png +0 -0
- 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/BodyText.js +1 -1
- package/lib/commonjs/components/BrandMark.js +1 -1
- package/lib/commonjs/components/CodeInput.js +1 -1
- package/lib/commonjs/components/EmailInput.js +1 -1
- package/lib/commonjs/components/GoogleButton.js +1 -1
- package/lib/commonjs/components/HeadingGroup.js +1 -1
- package/lib/commonjs/components/LLMDataInputModal.js +1 -1
- package/lib/commonjs/components/ModalHeader.js +1 -1
- package/lib/commonjs/components/ModalSheet.js +1 -1
- package/lib/commonjs/components/Onairos.js +1 -1
- package/lib/commonjs/components/OnairosButton.js +1 -1
- package/lib/commonjs/components/OnairosSignInButton.js +1 -1
- package/lib/commonjs/components/Overlay.js +1 -1
- package/lib/commonjs/components/PersonaImage.js +1 -1
- package/lib/commonjs/components/PersonaLoadingScreen.js +1 -1
- package/lib/commonjs/components/PersonalizationConsentScreen.js +1 -1
- package/lib/commonjs/components/PinCreationScreen.js +1 -1
- package/lib/commonjs/components/PinInput.js +1 -1
- package/lib/commonjs/components/PlatformConnectorsStep.js +3 -2
- package/lib/commonjs/components/PlatformList.js +1 -1
- package/lib/commonjs/components/PlatformToggle.js +1 -1
- package/lib/commonjs/components/PrimaryButton.js +1 -1
- package/lib/commonjs/components/SignInMatchAnimation.js +1 -1
- package/lib/commonjs/components/SignInStep.js +1 -1
- package/lib/commonjs/components/UniversalOnboarding.js +2 -1
- package/lib/commonjs/components/VerificationStep.js +1 -1
- package/lib/commonjs/components/WelcomeScreen.js +2 -1
- package/lib/commonjs/components/icons/Basicproficon.js +1 -1
- package/lib/commonjs/components/icons/Basicprofile.js +1 -1
- package/lib/commonjs/components/icons/Checkbox.js +1 -1
- package/lib/commonjs/components/icons/Checkmark.js +1 -1
- package/lib/commonjs/components/icons/Contentanalysis.js +1 -1
- package/lib/commonjs/components/icons/Contenticon.js +1 -1
- package/lib/commonjs/components/icons/EnochE.js +1 -1
- package/lib/commonjs/components/icons/Personalityicon.js +1 -1
- package/lib/commonjs/components/icons/Personalityprofile.js +1 -1
- package/lib/commonjs/components/icons/Personalitytraits.js +1 -1
- package/lib/commonjs/components/icons/Userpreferences.js +1 -1
- package/lib/commonjs/components/icons/index.js +1 -1
- package/lib/commonjs/components/onboarding/OAuthWebView.js +6 -2
- package/lib/commonjs/components/onboarding/OnboardingHeader.js +1 -1
- package/lib/commonjs/components/onboarding/PinInput.js +1 -1
- package/lib/commonjs/components/onboarding/PlatformConnector.js +1 -1
- package/lib/commonjs/config/api.js +1 -1
- package/lib/commonjs/constants/index.js +1 -1
- package/lib/commonjs/context/AuthContext.js +1 -1
- package/lib/commonjs/hooks/useConnectedAccounts.js +1 -1
- package/lib/commonjs/hooks/useConnections.js +1 -1
- package/lib/commonjs/hooks/useCredentials.js +1 -1
- package/lib/commonjs/hooks/useUserConnections.js +1 -1
- package/lib/commonjs/index.js +5 -6
- package/lib/commonjs/services/SDK_API_KEY_VALIDATION.md +421 -421
- package/lib/commonjs/services/apiClient.js +1 -1
- package/lib/commonjs/services/apiKeyService.js +1 -1
- package/lib/commonjs/services/authService.js +1 -1
- package/lib/commonjs/services/biometricPinService.js +1 -1
- package/lib/commonjs/services/chatGPTConversationExtractor.js +1 -1
- package/lib/commonjs/services/chatGPTConversationService.js +1 -1
- package/lib/commonjs/services/claudeConversationExtractor.js +1 -1
- package/lib/commonjs/services/claudeConversationService.js +1 -1
- package/lib/commonjs/services/connectedAccountsService.js +1 -1
- package/lib/commonjs/services/googleAuthService.js +1 -1
- package/lib/commonjs/services/hingeDataExtractor.js +8 -0
- package/lib/commonjs/services/hingeDataService.js +9 -0
- package/lib/commonjs/services/imageCompressionService.js +1 -1
- package/lib/commonjs/services/instagramDataExtractor.js +8 -0
- package/lib/commonjs/services/instagramDataService.js +9 -0
- package/lib/commonjs/services/jwtStorageService.js +1 -1
- package/lib/commonjs/services/linkedinDOMExtractor.js +1 -1
- package/lib/commonjs/services/linkedinProfileService.js +1 -1
- package/lib/commonjs/services/linkedinScrapingService.js +1 -1
- package/lib/commonjs/services/llmDataStorage.js +1 -1
- package/lib/commonjs/services/mobileTrainingService.js +1 -1
- package/lib/commonjs/services/oauthService.js +1 -1
- package/lib/commonjs/services/pinEncryptionService.js +1 -1
- package/lib/commonjs/services/pinStorageUtils.js +1 -1
- package/lib/commonjs/services/platformAuthService.js +1 -1
- package/lib/commonjs/services/sephoraDataExtractor.js +8 -0
- package/lib/commonjs/services/sephoraDataService.js +9 -0
- package/lib/commonjs/services/storageService.js +1 -1
- package/lib/commonjs/services/telegramDataExtractor.js +8 -0
- package/lib/commonjs/services/telegramDataService.js +11 -0
- package/lib/commonjs/services/trainingApiHelpers.js +1 -1
- package/lib/commonjs/services/userConnectionsService.js +1 -1
- package/lib/commonjs/services/youtubeMigrationService.js +1 -1
- package/lib/commonjs/theme/index.js +1 -1
- package/lib/commonjs/types/index.js +1 -1
- package/lib/commonjs/types.js +1 -1
- package/lib/commonjs/utils/Portal.js +1 -1
- package/lib/commonjs/utils/api.js +1 -1
- package/lib/commonjs/utils/assetRegistry.js +2 -2
- package/lib/commonjs/utils/auth.js +1 -1
- package/lib/commonjs/utils/connectorTests.js +29 -0
- package/lib/commonjs/utils/crypto.js +1 -1
- package/lib/commonjs/utils/debugHelper.js +1 -1
- package/lib/commonjs/utils/encryption.js +1 -1
- package/lib/commonjs/utils/eventUtils.js +1 -1
- package/lib/commonjs/utils/haptics.js +1 -1
- package/lib/commonjs/utils/imagePreloader.js +1 -1
- package/lib/commonjs/utils/networkDiagnostics.js +1 -1
- package/lib/commonjs/utils/onairosApi.js +1 -1
- package/lib/commonjs/utils/programmaticFlow.js +1 -1
- package/lib/commonjs/utils/retryHelper.js +1 -1
- package/lib/commonjs/utils/secureStorage.js +1 -1
- package/lib/commonjs/utils/webviewScripts/chatgpt.js +1 -1
- package/lib/commonjs/utils/webviewScripts/claude.js +1 -1
- package/lib/commonjs/utils/webviewScripts/hinge.js +1 -0
- package/lib/commonjs/utils/webviewScripts/index.js +6 -2
- package/lib/commonjs/utils/webviewScripts/instagram.js +1 -0
- package/lib/commonjs/utils/webviewScripts/linkedin.js +1 -1
- package/lib/commonjs/utils/webviewScripts/sephora.js +1 -0
- package/lib/commonjs/utils/webviewScripts/telegram.js +1 -0
- package/lib/module/api/index.js +1 -1
- package/lib/module/assets/images/Checkbox.svg +3 -3
- package/lib/module/assets/images/EnochE.svg +19 -19
- package/lib/module/assets/images/OnairosNewLogo.png +0 -0
- 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/BodyText.js +1 -1
- package/lib/module/components/BrandMark.js +1 -1
- package/lib/module/components/CodeInput.js +1 -1
- package/lib/module/components/EmailInput.js +1 -1
- package/lib/module/components/GoogleButton.js +1 -1
- package/lib/module/components/HeadingGroup.js +1 -1
- package/lib/module/components/LLMDataInputModal.js +1 -1
- package/lib/module/components/ModalHeader.js +1 -1
- package/lib/module/components/ModalSheet.js +1 -1
- package/lib/module/components/Onairos.js +1 -1
- package/lib/module/components/OnairosButton.js +1 -1
- package/lib/module/components/OnairosSignInButton.js +1 -1
- package/lib/module/components/Overlay.js +1 -1
- package/lib/module/components/PersonaImage.js +1 -1
- package/lib/module/components/PersonaLoadingScreen.js +1 -1
- package/lib/module/components/PersonalizationConsentScreen.js +1 -1
- package/lib/module/components/PinCreationScreen.js +1 -1
- package/lib/module/components/PinInput.js +1 -1
- package/lib/module/components/PlatformConnectorsStep.js +7 -1
- package/lib/module/components/PlatformList.js +1 -1
- package/lib/module/components/PlatformToggle.js +1 -1
- package/lib/module/components/PrimaryButton.js +1 -1
- package/lib/module/components/SignInMatchAnimation.js +1 -1
- package/lib/module/components/SignInStep.js +1 -1
- package/lib/module/components/UniversalOnboarding.js +1 -1
- package/lib/module/components/VerificationStep.js +1 -1
- package/lib/module/components/WelcomeScreen.js +1 -1
- package/lib/module/components/icons/Basicproficon.js +1 -1
- package/lib/module/components/icons/Basicprofile.js +1 -1
- package/lib/module/components/icons/Checkbox.js +1 -1
- package/lib/module/components/icons/Checkmark.js +1 -1
- package/lib/module/components/icons/Contentanalysis.js +1 -1
- package/lib/module/components/icons/Contenticon.js +1 -1
- package/lib/module/components/icons/EnochE.js +1 -1
- package/lib/module/components/icons/Personalityicon.js +1 -1
- package/lib/module/components/icons/Personalityprofile.js +1 -1
- package/lib/module/components/icons/Personalitytraits.js +1 -1
- package/lib/module/components/icons/Userpreferences.js +1 -1
- package/lib/module/components/onboarding/OAuthWebView.js +1 -1
- package/lib/module/components/onboarding/OnboardingHeader.js +1 -1
- package/lib/module/components/onboarding/PinInput.js +1 -1
- package/lib/module/components/onboarding/PlatformConnector.js +1 -1
- package/lib/module/config/api.js +1 -1
- package/lib/module/constants/index.js +1 -1
- package/lib/module/context/AuthContext.js +1 -1
- package/lib/module/hooks/useConnectedAccounts.js +1 -1
- package/lib/module/hooks/useConnections.js +1 -1
- package/lib/module/hooks/useCredentials.js +1 -1
- package/lib/module/hooks/useUserConnections.js +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/services/SDK_API_KEY_VALIDATION.md +421 -421
- package/lib/module/services/apiClient.js +1 -1
- package/lib/module/services/apiKeyService.js +1 -1
- package/lib/module/services/authService.js +1 -1
- package/lib/module/services/biometricPinService.js +1 -1
- package/lib/module/services/chatGPTConversationExtractor.js +1 -1
- package/lib/module/services/chatGPTConversationService.js +1 -1
- package/lib/module/services/claudeConversationExtractor.js +1 -1
- package/lib/module/services/claudeConversationService.js +1 -1
- package/lib/module/services/connectedAccountsService.js +1 -1
- package/lib/module/services/googleAuthService.js +1 -1
- package/lib/module/services/hingeDataExtractor.js +1 -0
- package/lib/module/services/hingeDataService.js +1 -0
- package/lib/module/services/imageCompressionService.js +1 -1
- package/lib/module/services/instagramDataExtractor.js +1 -0
- package/lib/module/services/instagramDataService.js +1 -0
- package/lib/module/services/jwtStorageService.js +1 -1
- package/lib/module/services/linkedinDOMExtractor.js +1 -1
- package/lib/module/services/linkedinProfileService.js +1 -1
- package/lib/module/services/linkedinScrapingService.js +1 -1
- package/lib/module/services/llmDataStorage.js +1 -1
- package/lib/module/services/mobileTrainingService.js +1 -1
- package/lib/module/services/oauthService.js +1 -1
- package/lib/module/services/pinEncryptionService.js +1 -1
- package/lib/module/services/pinStorageUtils.js +1 -1
- package/lib/module/services/platformAuthService.js +1 -1
- package/lib/module/services/sephoraDataExtractor.js +1 -0
- package/lib/module/services/sephoraDataService.js +1 -0
- package/lib/module/services/storageService.js +1 -1
- package/lib/module/services/telegramDataExtractor.js +1 -0
- package/lib/module/services/telegramDataService.js +8 -0
- package/lib/module/services/trainingApiHelpers.js +1 -1
- package/lib/module/services/userConnectionsService.js +1 -1
- package/lib/module/services/youtubeMigrationService.js +1 -1
- package/lib/module/theme/index.js +1 -1
- package/lib/module/types.js +1 -1
- package/lib/module/utils/Portal.js +1 -1
- package/lib/module/utils/api.js +1 -1
- package/lib/module/utils/assetRegistry.js +2 -2
- package/lib/module/utils/auth.js +1 -1
- package/lib/module/utils/connectorTests.js +28 -0
- package/lib/module/utils/crypto.js +1 -1
- package/lib/module/utils/debugHelper.js +1 -1
- package/lib/module/utils/encryption.js +1 -1
- package/lib/module/utils/eventUtils.js +1 -1
- package/lib/module/utils/haptics.js +1 -1
- package/lib/module/utils/networkDiagnostics.js +1 -1
- package/lib/module/utils/onairosApi.js +1 -1
- package/lib/module/utils/programmaticFlow.js +1 -1
- package/lib/module/utils/retryHelper.js +1 -1
- package/lib/module/utils/secureStorage.js +1 -1
- package/lib/module/utils/webviewScripts/chatgpt.js +1 -1
- package/lib/module/utils/webviewScripts/claude.js +1 -1
- package/lib/module/utils/webviewScripts/hinge.js +1 -0
- package/lib/module/utils/webviewScripts/index.js +1 -1
- package/lib/module/utils/webviewScripts/instagram.js +1 -0
- package/lib/module/utils/webviewScripts/linkedin.js +1 -1
- package/lib/module/utils/webviewScripts/sephora.js +1 -0
- package/lib/module/utils/webviewScripts/telegram.js +1 -0
- package/package.json +1 -1
|
@@ -1,421 +1,421 @@
|
|
|
1
|
-
# Onairos SDK API Key Validation - Standardized Documentation
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
This document outlines the standardized API key validation system for all Onairos SDKs (React Native, Web, Mobile, etc.). The system provides a unified interface for initializing and validating developer API keys across all platforms.
|
|
6
|
-
|
|
7
|
-
## 🔑 API Key Format
|
|
8
|
-
|
|
9
|
-
### Developer API Keys
|
|
10
|
-
- **Format**: Must be at least 32 characters
|
|
11
|
-
- **Prefixes**: `dev_`, `pk_`, or `ona_`
|
|
12
|
-
- **Example**: `ona_1234567890abcdef1234567890abcdef12345678`
|
|
13
|
-
|
|
14
|
-
### Admin API Keys (Internal Use)
|
|
15
|
-
- **Format**: Special admin keys for internal testing
|
|
16
|
-
- **Permissions**: Full access (`*`)
|
|
17
|
-
|
|
18
|
-
## 🚀 SDK Initialization Standard
|
|
19
|
-
|
|
20
|
-
### Step 1: Initialize SDK (Required for all SDKs)
|
|
21
|
-
|
|
22
|
-
All SDKs should implement an `initializeApiKey` function that validates the API key before allowing SDK usage.
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
import { initializeApiKey } from 'onairos';
|
|
26
|
-
|
|
27
|
-
// Initialize SDK with developer API key
|
|
28
|
-
try {
|
|
29
|
-
await initializeApiKey({
|
|
30
|
-
apiKey: 'ona_your_api_key_here', // Get from Onairos Dashboard
|
|
31
|
-
environment: 'production', // 'production' | 'development'
|
|
32
|
-
enableLogging: true,
|
|
33
|
-
timeout: 30000,
|
|
34
|
-
retryAttempts: 3
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
console.log('SDK initialized successfully!');
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.error('SDK initialization failed:', error.message);
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Step 2: Use SDK Components
|
|
44
|
-
|
|
45
|
-
After successful initialization, all SDK components work automatically:
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { OnairosButton } from 'onairos';
|
|
49
|
-
|
|
50
|
-
// Components automatically handle authentication internally
|
|
51
|
-
<OnairosButton
|
|
52
|
-
requestData={{
|
|
53
|
-
basic: { type: "basic", reward: "10 tokens" },
|
|
54
|
-
personality: { type: "personality", reward: "25 tokens" },
|
|
55
|
-
preferences: { type: "preferences", reward: "15 tokens" }
|
|
56
|
-
}}
|
|
57
|
-
webpageName="MyApp"
|
|
58
|
-
testMode={false}
|
|
59
|
-
autoFetch={true}
|
|
60
|
-
onComplete={(result) => console.log(result)}
|
|
61
|
-
/>
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## 🌐 API Endpoints
|
|
65
|
-
|
|
66
|
-
### Primary Validation Endpoint
|
|
67
|
-
|
|
68
|
-
**POST** `/dev/validate`
|
|
69
|
-
|
|
70
|
-
This is the main endpoint that all SDKs should use for API key validation.
|
|
71
|
-
|
|
72
|
-
#### Request Headers
|
|
73
|
-
```http
|
|
74
|
-
Authorization: Bearer ona_your_api_key_here
|
|
75
|
-
Content-Type: application/json
|
|
76
|
-
X-SDK-Platform: react-native|web|mobile (optional)
|
|
77
|
-
User-Agent: OnairosReactNative/3.1.10 (optional)
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
#### Request Body
|
|
81
|
-
```json
|
|
82
|
-
{
|
|
83
|
-
"environment": "production",
|
|
84
|
-
"sdk_version": "3.1.10",
|
|
85
|
-
"platform": "react-native",
|
|
86
|
-
"keyType": "developer",
|
|
87
|
-
"timestamp": "2024-01-01T00:00:00.000Z",
|
|
88
|
-
"attempt": 1
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
#### Success Response (200)
|
|
93
|
-
```json
|
|
94
|
-
{
|
|
95
|
-
"valid": true,
|
|
96
|
-
"apiKey": {
|
|
97
|
-
"id": "68f7f1bef71b2523faade626",
|
|
98
|
-
"name": "My App Key",
|
|
99
|
-
"createdAt": "2025-10-21T20:49:02.205Z",
|
|
100
|
-
"lastUsed": "2025-10-24T00:15:54.478Z",
|
|
101
|
-
"usageCount": 13
|
|
102
|
-
},
|
|
103
|
-
"application": {
|
|
104
|
-
"name": "My Application",
|
|
105
|
-
"theme": "productivity",
|
|
106
|
-
"description": "Application description"
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
#### Error Response (401/400/500)
|
|
112
|
-
```json
|
|
113
|
-
{
|
|
114
|
-
"valid": false,
|
|
115
|
-
"error": "Invalid API key format",
|
|
116
|
-
"message": "Developer keys must be at least 32 characters and start with 'dev_', 'pk_', or 'ona_'",
|
|
117
|
-
"code": "INVALID_API_KEY_FORMAT"
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Alternative Endpoints
|
|
122
|
-
|
|
123
|
-
#### Legacy Endpoints (Deprecated)
|
|
124
|
-
- **POST** `/auth/validate-key` - Old validation endpoint (deprecated, use `/dev/validate`)
|
|
125
|
-
- **GET** `/auth/validate-key?key=API_KEY` - Old GET validation (deprecated)
|
|
126
|
-
|
|
127
|
-
## 🛡️ Error Handling & Retry Logic
|
|
128
|
-
|
|
129
|
-
### Common Error Codes
|
|
130
|
-
|
|
131
|
-
| Code | Description | Action |
|
|
132
|
-
|------|-------------|--------|
|
|
133
|
-
| `MISSING_API_KEY` | No API key provided | Provide API key in Authorization header |
|
|
134
|
-
| `INVALID_API_KEY_FORMAT` | Invalid key format | Check key format (32+ chars, correct prefix) |
|
|
135
|
-
| `INVALID_API_KEY` | Key not found/inactive | Verify key exists and is active |
|
|
136
|
-
| `API_KEY_EXPIRED` | Key has expired | Renew or generate new API key |
|
|
137
|
-
| `DEVELOPER_NOT_FOUND` | Developer account inactive | Contact support |
|
|
138
|
-
| `RATE_LIMIT_EXCEEDED` | Too many requests | Wait and retry |
|
|
139
|
-
| `INTERNAL_ERROR` | Server error | Retry with exponential backoff |
|
|
140
|
-
|
|
141
|
-
### Retry Strategy
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
const validateApiKey = async (apiKey: string, config: Config): Promise<ValidationResult> => {
|
|
145
|
-
const maxRetries = config.retryAttempts || 3;
|
|
146
|
-
|
|
147
|
-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
148
|
-
try {
|
|
149
|
-
const response = await fetch(`${baseUrl}/auth/validate-key`, {
|
|
150
|
-
method: 'POST',
|
|
151
|
-
headers: {
|
|
152
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
153
|
-
'Content-Type': 'application/json',
|
|
154
|
-
'X-SDK-Platform': config.platform || 'unknown'
|
|
155
|
-
},
|
|
156
|
-
body: JSON.stringify({
|
|
157
|
-
environment: config.environment || 'production',
|
|
158
|
-
sdk_version: config.sdkVersion,
|
|
159
|
-
platform: config.platform,
|
|
160
|
-
timestamp: new Date().toISOString(),
|
|
161
|
-
attempt
|
|
162
|
-
}),
|
|
163
|
-
signal: AbortSignal.timeout(config.timeout || 30000)
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
if (response.ok) {
|
|
167
|
-
return await response.json();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Don't retry client errors (4xx)
|
|
171
|
-
if (response.status >= 400 && response.status < 500) {
|
|
172
|
-
throw new Error(`Client error: ${response.status}`);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Retry server errors (5xx)
|
|
176
|
-
if (attempt === maxRetries) {
|
|
177
|
-
throw new Error(`Server error after ${maxRetries} attempts`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
} catch (error) {
|
|
181
|
-
if (attempt === maxRetries) {
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Exponential backoff
|
|
186
|
-
const delay = Math.min(1000 * Math.pow(2, attempt - 1), 5000);
|
|
187
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## 📱 Platform-Specific Implementation
|
|
194
|
-
|
|
195
|
-
### React Native SDK
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
export const validateApiKey = async (apiKey: string): Promise<ApiKeyValidationResult> => {
|
|
199
|
-
// Check admin keys first
|
|
200
|
-
if (isAdminKey(apiKey)) {
|
|
201
|
-
return {
|
|
202
|
-
isValid: true,
|
|
203
|
-
permissions: ['*'],
|
|
204
|
-
rateLimits: { remaining: 999999, resetTime: Date.now() + 24*60*60*1000 },
|
|
205
|
-
keyType: ApiKeyType.ADMIN
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Validate format
|
|
210
|
-
const keyType = getApiKeyType(apiKey);
|
|
211
|
-
if (keyType === ApiKeyType.INVALID) {
|
|
212
|
-
return {
|
|
213
|
-
isValid: false,
|
|
214
|
-
error: 'Invalid API key format',
|
|
215
|
-
keyType: ApiKeyType.INVALID
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Make API call
|
|
220
|
-
const response = await fetch(`${baseUrl}/dev/validate`, {
|
|
221
|
-
method: 'POST',
|
|
222
|
-
headers: {
|
|
223
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
224
|
-
'Content-Type': 'application/json',
|
|
225
|
-
'User-Agent': 'OnairosReactNative/3.3.1',
|
|
226
|
-
'X-API-Key-Type': keyType,
|
|
227
|
-
'X-SDK-Platform': 'react-native'
|
|
228
|
-
},
|
|
229
|
-
body: JSON.stringify({
|
|
230
|
-
environment: globalConfig?.environment || 'production',
|
|
231
|
-
sdk_version: '3.3.1',
|
|
232
|
-
platform: 'react-native',
|
|
233
|
-
keyType,
|
|
234
|
-
timestamp: new Date().toISOString()
|
|
235
|
-
})
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
const data = await response.json();
|
|
239
|
-
|
|
240
|
-
if (data.valid || data.success) {
|
|
241
|
-
return {
|
|
242
|
-
isValid: true,
|
|
243
|
-
permissions: data.permissions || [],
|
|
244
|
-
rateLimits: data.rateLimits || null,
|
|
245
|
-
keyType: keyType
|
|
246
|
-
};
|
|
247
|
-
} else {
|
|
248
|
-
return {
|
|
249
|
-
isValid: false,
|
|
250
|
-
error: data.error || data.message,
|
|
251
|
-
keyType: keyType
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
### Web SDK
|
|
258
|
-
|
|
259
|
-
```typescript
|
|
260
|
-
class OnairosSDK {
|
|
261
|
-
private apiKey: string | null = null;
|
|
262
|
-
private isInitialized: boolean = false;
|
|
263
|
-
|
|
264
|
-
async initialize(config: InitConfig): Promise<void> {
|
|
265
|
-
const validation = await this.validateApiKey(config.apiKey);
|
|
266
|
-
|
|
267
|
-
if (!validation.isValid) {
|
|
268
|
-
throw new Error(`SDK initialization failed: ${validation.error}`);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
this.apiKey = config.apiKey;
|
|
272
|
-
this.isInitialized = true;
|
|
273
|
-
|
|
274
|
-
console.log('Onairos SDK initialized successfully');
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
private async validateApiKey(apiKey: string): Promise<ValidationResult> {
|
|
278
|
-
// Similar implementation to React Native
|
|
279
|
-
// ...
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
## 🔧 Configuration Options
|
|
285
|
-
|
|
286
|
-
### InitConfig Interface
|
|
287
|
-
|
|
288
|
-
```typescript
|
|
289
|
-
interface InitConfig {
|
|
290
|
-
apiKey: string; // Required: Developer API key
|
|
291
|
-
environment?: 'production' | 'development'; // Default: 'production'
|
|
292
|
-
enableLogging?: boolean; // Default: false
|
|
293
|
-
timeout?: number; // Default: 30000ms
|
|
294
|
-
retryAttempts?: number; // Default: 3
|
|
295
|
-
baseUrl?: string; // Default: auto-detected
|
|
296
|
-
}
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
### ValidationResult Interface
|
|
300
|
-
|
|
301
|
-
```typescript
|
|
302
|
-
interface ValidationResult {
|
|
303
|
-
isValid: boolean;
|
|
304
|
-
permissions?: string[];
|
|
305
|
-
rateLimits?: {
|
|
306
|
-
remaining: number;
|
|
307
|
-
resetTime: number;
|
|
308
|
-
};
|
|
309
|
-
keyType: 'admin' | 'developer' | 'invalid';
|
|
310
|
-
error?: string;
|
|
311
|
-
}
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
## 🌍 Environment Configuration
|
|
315
|
-
|
|
316
|
-
### Base URLs
|
|
317
|
-
|
|
318
|
-
```typescript
|
|
319
|
-
const API_ENDPOINTS = {
|
|
320
|
-
production: 'https://api2.onairos.uk',
|
|
321
|
-
development: 'https://dev-api2.onairos.uk'
|
|
322
|
-
};
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
### Environment Detection
|
|
326
|
-
|
|
327
|
-
```typescript
|
|
328
|
-
const detectEnvironment = (): 'production' | 'development' => {
|
|
329
|
-
if (typeof window !== 'undefined') {
|
|
330
|
-
// Browser environment
|
|
331
|
-
return window.location.hostname.includes('localhost') ? 'development' : 'production';
|
|
332
|
-
} else {
|
|
333
|
-
// Node.js/React Native environment
|
|
334
|
-
return process.env.NODE_ENV === 'development' ? 'development' : 'production';
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
## 🚀 Quick Start Examples
|
|
340
|
-
|
|
341
|
-
### React Native
|
|
342
|
-
|
|
343
|
-
```typescript
|
|
344
|
-
import { initializeApiKey, OnairosButton } from 'onairos-react-native';
|
|
345
|
-
|
|
346
|
-
// 1. Initialize SDK
|
|
347
|
-
await initializeApiKey({
|
|
348
|
-
apiKey: 'ona_your_key_here',
|
|
349
|
-
environment: 'production'
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
// 2. Use components
|
|
353
|
-
<OnairosButton requestData={{...}} onComplete={handleResult} />
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### Web/JavaScript
|
|
357
|
-
|
|
358
|
-
```typescript
|
|
359
|
-
import { OnairosSDK } from 'onairos-web';
|
|
360
|
-
|
|
361
|
-
// 1. Initialize SDK
|
|
362
|
-
const sdk = new OnairosSDK();
|
|
363
|
-
await sdk.initialize({
|
|
364
|
-
apiKey: 'ona_your_key_here',
|
|
365
|
-
environment: 'production'
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
// 2. Use SDK methods
|
|
369
|
-
const result = await sdk.collectData({...});
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
### Node.js Backend
|
|
373
|
-
|
|
374
|
-
```typescript
|
|
375
|
-
import { OnairosAPI } from 'onairos-node';
|
|
376
|
-
|
|
377
|
-
// 1. Initialize API client
|
|
378
|
-
const api = new OnairosAPI({
|
|
379
|
-
apiKey: 'ona_your_key_here',
|
|
380
|
-
environment: 'production'
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
// 2. Make API calls
|
|
384
|
-
const validation = await api.validateKey();
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
## 🔍 Testing & Debugging
|
|
388
|
-
|
|
389
|
-
### Test API Key Validation
|
|
390
|
-
|
|
391
|
-
```bash
|
|
392
|
-
# Test with curl
|
|
393
|
-
curl -X POST https://api2.onairos.uk/dev/validate \
|
|
394
|
-
-H "Authorization: Bearer ona_your_key_here" \
|
|
395
|
-
-H "Content-Type: application/json" \
|
|
396
|
-
-d '{
|
|
397
|
-
"environment": "production",
|
|
398
|
-
"platform": "test"
|
|
399
|
-
}'
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
### Debug Mode
|
|
403
|
-
|
|
404
|
-
Enable logging in SDK initialization:
|
|
405
|
-
|
|
406
|
-
```typescript
|
|
407
|
-
await initializeApiKey({
|
|
408
|
-
apiKey: 'ona_your_key_here',
|
|
409
|
-
enableLogging: true // Shows detailed logs
|
|
410
|
-
});
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
## 📞 Support
|
|
414
|
-
|
|
415
|
-
- **Documentation**: https://docs.onairos.uk
|
|
416
|
-
- **Dashboard**: https://dashboard.onairos.uk
|
|
417
|
-
- **Support**: support@onairos.uk
|
|
418
|
-
|
|
419
|
-
---
|
|
420
|
-
|
|
421
|
-
*Last updated: October 2024*
|
|
1
|
+
# Onairos SDK API Key Validation - Standardized Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This document outlines the standardized API key validation system for all Onairos SDKs (React Native, Web, Mobile, etc.). The system provides a unified interface for initializing and validating developer API keys across all platforms.
|
|
6
|
+
|
|
7
|
+
## 🔑 API Key Format
|
|
8
|
+
|
|
9
|
+
### Developer API Keys
|
|
10
|
+
- **Format**: Must be at least 32 characters
|
|
11
|
+
- **Prefixes**: `dev_`, `pk_`, or `ona_`
|
|
12
|
+
- **Example**: `ona_1234567890abcdef1234567890abcdef12345678`
|
|
13
|
+
|
|
14
|
+
### Admin API Keys (Internal Use)
|
|
15
|
+
- **Format**: Special admin keys for internal testing
|
|
16
|
+
- **Permissions**: Full access (`*`)
|
|
17
|
+
|
|
18
|
+
## 🚀 SDK Initialization Standard
|
|
19
|
+
|
|
20
|
+
### Step 1: Initialize SDK (Required for all SDKs)
|
|
21
|
+
|
|
22
|
+
All SDKs should implement an `initializeApiKey` function that validates the API key before allowing SDK usage.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { initializeApiKey } from 'onairos';
|
|
26
|
+
|
|
27
|
+
// Initialize SDK with developer API key
|
|
28
|
+
try {
|
|
29
|
+
await initializeApiKey({
|
|
30
|
+
apiKey: 'ona_your_api_key_here', // Get from Onairos Dashboard
|
|
31
|
+
environment: 'production', // 'production' | 'development'
|
|
32
|
+
enableLogging: true,
|
|
33
|
+
timeout: 30000,
|
|
34
|
+
retryAttempts: 3
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
console.log('SDK initialized successfully!');
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('SDK initialization failed:', error.message);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Step 2: Use SDK Components
|
|
44
|
+
|
|
45
|
+
After successful initialization, all SDK components work automatically:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { OnairosButton } from 'onairos';
|
|
49
|
+
|
|
50
|
+
// Components automatically handle authentication internally
|
|
51
|
+
<OnairosButton
|
|
52
|
+
requestData={{
|
|
53
|
+
basic: { type: "basic", reward: "10 tokens" },
|
|
54
|
+
personality: { type: "personality", reward: "25 tokens" },
|
|
55
|
+
preferences: { type: "preferences", reward: "15 tokens" }
|
|
56
|
+
}}
|
|
57
|
+
webpageName="MyApp"
|
|
58
|
+
testMode={false}
|
|
59
|
+
autoFetch={true}
|
|
60
|
+
onComplete={(result) => console.log(result)}
|
|
61
|
+
/>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 🌐 API Endpoints
|
|
65
|
+
|
|
66
|
+
### Primary Validation Endpoint
|
|
67
|
+
|
|
68
|
+
**POST** `/dev/validate`
|
|
69
|
+
|
|
70
|
+
This is the main endpoint that all SDKs should use for API key validation.
|
|
71
|
+
|
|
72
|
+
#### Request Headers
|
|
73
|
+
```http
|
|
74
|
+
Authorization: Bearer ona_your_api_key_here
|
|
75
|
+
Content-Type: application/json
|
|
76
|
+
X-SDK-Platform: react-native|web|mobile (optional)
|
|
77
|
+
User-Agent: OnairosReactNative/3.1.10 (optional)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Request Body
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"environment": "production",
|
|
84
|
+
"sdk_version": "3.1.10",
|
|
85
|
+
"platform": "react-native",
|
|
86
|
+
"keyType": "developer",
|
|
87
|
+
"timestamp": "2024-01-01T00:00:00.000Z",
|
|
88
|
+
"attempt": 1
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Success Response (200)
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"valid": true,
|
|
96
|
+
"apiKey": {
|
|
97
|
+
"id": "68f7f1bef71b2523faade626",
|
|
98
|
+
"name": "My App Key",
|
|
99
|
+
"createdAt": "2025-10-21T20:49:02.205Z",
|
|
100
|
+
"lastUsed": "2025-10-24T00:15:54.478Z",
|
|
101
|
+
"usageCount": 13
|
|
102
|
+
},
|
|
103
|
+
"application": {
|
|
104
|
+
"name": "My Application",
|
|
105
|
+
"theme": "productivity",
|
|
106
|
+
"description": "Application description"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Error Response (401/400/500)
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"valid": false,
|
|
115
|
+
"error": "Invalid API key format",
|
|
116
|
+
"message": "Developer keys must be at least 32 characters and start with 'dev_', 'pk_', or 'ona_'",
|
|
117
|
+
"code": "INVALID_API_KEY_FORMAT"
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Alternative Endpoints
|
|
122
|
+
|
|
123
|
+
#### Legacy Endpoints (Deprecated)
|
|
124
|
+
- **POST** `/auth/validate-key` - Old validation endpoint (deprecated, use `/dev/validate`)
|
|
125
|
+
- **GET** `/auth/validate-key?key=API_KEY` - Old GET validation (deprecated)
|
|
126
|
+
|
|
127
|
+
## 🛡️ Error Handling & Retry Logic
|
|
128
|
+
|
|
129
|
+
### Common Error Codes
|
|
130
|
+
|
|
131
|
+
| Code | Description | Action |
|
|
132
|
+
|------|-------------|--------|
|
|
133
|
+
| `MISSING_API_KEY` | No API key provided | Provide API key in Authorization header |
|
|
134
|
+
| `INVALID_API_KEY_FORMAT` | Invalid key format | Check key format (32+ chars, correct prefix) |
|
|
135
|
+
| `INVALID_API_KEY` | Key not found/inactive | Verify key exists and is active |
|
|
136
|
+
| `API_KEY_EXPIRED` | Key has expired | Renew or generate new API key |
|
|
137
|
+
| `DEVELOPER_NOT_FOUND` | Developer account inactive | Contact support |
|
|
138
|
+
| `RATE_LIMIT_EXCEEDED` | Too many requests | Wait and retry |
|
|
139
|
+
| `INTERNAL_ERROR` | Server error | Retry with exponential backoff |
|
|
140
|
+
|
|
141
|
+
### Retry Strategy
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
const validateApiKey = async (apiKey: string, config: Config): Promise<ValidationResult> => {
|
|
145
|
+
const maxRetries = config.retryAttempts || 3;
|
|
146
|
+
|
|
147
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
148
|
+
try {
|
|
149
|
+
const response = await fetch(`${baseUrl}/auth/validate-key`, {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
headers: {
|
|
152
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
153
|
+
'Content-Type': 'application/json',
|
|
154
|
+
'X-SDK-Platform': config.platform || 'unknown'
|
|
155
|
+
},
|
|
156
|
+
body: JSON.stringify({
|
|
157
|
+
environment: config.environment || 'production',
|
|
158
|
+
sdk_version: config.sdkVersion,
|
|
159
|
+
platform: config.platform,
|
|
160
|
+
timestamp: new Date().toISOString(),
|
|
161
|
+
attempt
|
|
162
|
+
}),
|
|
163
|
+
signal: AbortSignal.timeout(config.timeout || 30000)
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
if (response.ok) {
|
|
167
|
+
return await response.json();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Don't retry client errors (4xx)
|
|
171
|
+
if (response.status >= 400 && response.status < 500) {
|
|
172
|
+
throw new Error(`Client error: ${response.status}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Retry server errors (5xx)
|
|
176
|
+
if (attempt === maxRetries) {
|
|
177
|
+
throw new Error(`Server error after ${maxRetries} attempts`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (attempt === maxRetries) {
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Exponential backoff
|
|
186
|
+
const delay = Math.min(1000 * Math.pow(2, attempt - 1), 5000);
|
|
187
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## 📱 Platform-Specific Implementation
|
|
194
|
+
|
|
195
|
+
### React Native SDK
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
export const validateApiKey = async (apiKey: string): Promise<ApiKeyValidationResult> => {
|
|
199
|
+
// Check admin keys first
|
|
200
|
+
if (isAdminKey(apiKey)) {
|
|
201
|
+
return {
|
|
202
|
+
isValid: true,
|
|
203
|
+
permissions: ['*'],
|
|
204
|
+
rateLimits: { remaining: 999999, resetTime: Date.now() + 24*60*60*1000 },
|
|
205
|
+
keyType: ApiKeyType.ADMIN
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Validate format
|
|
210
|
+
const keyType = getApiKeyType(apiKey);
|
|
211
|
+
if (keyType === ApiKeyType.INVALID) {
|
|
212
|
+
return {
|
|
213
|
+
isValid: false,
|
|
214
|
+
error: 'Invalid API key format',
|
|
215
|
+
keyType: ApiKeyType.INVALID
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Make API call
|
|
220
|
+
const response = await fetch(`${baseUrl}/dev/validate`, {
|
|
221
|
+
method: 'POST',
|
|
222
|
+
headers: {
|
|
223
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
224
|
+
'Content-Type': 'application/json',
|
|
225
|
+
'User-Agent': 'OnairosReactNative/3.3.1',
|
|
226
|
+
'X-API-Key-Type': keyType,
|
|
227
|
+
'X-SDK-Platform': 'react-native'
|
|
228
|
+
},
|
|
229
|
+
body: JSON.stringify({
|
|
230
|
+
environment: globalConfig?.environment || 'production',
|
|
231
|
+
sdk_version: '3.3.1',
|
|
232
|
+
platform: 'react-native',
|
|
233
|
+
keyType,
|
|
234
|
+
timestamp: new Date().toISOString()
|
|
235
|
+
})
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const data = await response.json();
|
|
239
|
+
|
|
240
|
+
if (data.valid || data.success) {
|
|
241
|
+
return {
|
|
242
|
+
isValid: true,
|
|
243
|
+
permissions: data.permissions || [],
|
|
244
|
+
rateLimits: data.rateLimits || null,
|
|
245
|
+
keyType: keyType
|
|
246
|
+
};
|
|
247
|
+
} else {
|
|
248
|
+
return {
|
|
249
|
+
isValid: false,
|
|
250
|
+
error: data.error || data.message,
|
|
251
|
+
keyType: keyType
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Web SDK
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
class OnairosSDK {
|
|
261
|
+
private apiKey: string | null = null;
|
|
262
|
+
private isInitialized: boolean = false;
|
|
263
|
+
|
|
264
|
+
async initialize(config: InitConfig): Promise<void> {
|
|
265
|
+
const validation = await this.validateApiKey(config.apiKey);
|
|
266
|
+
|
|
267
|
+
if (!validation.isValid) {
|
|
268
|
+
throw new Error(`SDK initialization failed: ${validation.error}`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this.apiKey = config.apiKey;
|
|
272
|
+
this.isInitialized = true;
|
|
273
|
+
|
|
274
|
+
console.log('Onairos SDK initialized successfully');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private async validateApiKey(apiKey: string): Promise<ValidationResult> {
|
|
278
|
+
// Similar implementation to React Native
|
|
279
|
+
// ...
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## 🔧 Configuration Options
|
|
285
|
+
|
|
286
|
+
### InitConfig Interface
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
interface InitConfig {
|
|
290
|
+
apiKey: string; // Required: Developer API key
|
|
291
|
+
environment?: 'production' | 'development'; // Default: 'production'
|
|
292
|
+
enableLogging?: boolean; // Default: false
|
|
293
|
+
timeout?: number; // Default: 30000ms
|
|
294
|
+
retryAttempts?: number; // Default: 3
|
|
295
|
+
baseUrl?: string; // Default: auto-detected
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### ValidationResult Interface
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
interface ValidationResult {
|
|
303
|
+
isValid: boolean;
|
|
304
|
+
permissions?: string[];
|
|
305
|
+
rateLimits?: {
|
|
306
|
+
remaining: number;
|
|
307
|
+
resetTime: number;
|
|
308
|
+
};
|
|
309
|
+
keyType: 'admin' | 'developer' | 'invalid';
|
|
310
|
+
error?: string;
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## 🌍 Environment Configuration
|
|
315
|
+
|
|
316
|
+
### Base URLs
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
const API_ENDPOINTS = {
|
|
320
|
+
production: 'https://api2.onairos.uk',
|
|
321
|
+
development: 'https://dev-api2.onairos.uk'
|
|
322
|
+
};
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Environment Detection
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
const detectEnvironment = (): 'production' | 'development' => {
|
|
329
|
+
if (typeof window !== 'undefined') {
|
|
330
|
+
// Browser environment
|
|
331
|
+
return window.location.hostname.includes('localhost') ? 'development' : 'production';
|
|
332
|
+
} else {
|
|
333
|
+
// Node.js/React Native environment
|
|
334
|
+
return process.env.NODE_ENV === 'development' ? 'development' : 'production';
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## 🚀 Quick Start Examples
|
|
340
|
+
|
|
341
|
+
### React Native
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
import { initializeApiKey, OnairosButton } from 'onairos-react-native';
|
|
345
|
+
|
|
346
|
+
// 1. Initialize SDK
|
|
347
|
+
await initializeApiKey({
|
|
348
|
+
apiKey: 'ona_your_key_here',
|
|
349
|
+
environment: 'production'
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
// 2. Use components
|
|
353
|
+
<OnairosButton requestData={{...}} onComplete={handleResult} />
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Web/JavaScript
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
import { OnairosSDK } from 'onairos-web';
|
|
360
|
+
|
|
361
|
+
// 1. Initialize SDK
|
|
362
|
+
const sdk = new OnairosSDK();
|
|
363
|
+
await sdk.initialize({
|
|
364
|
+
apiKey: 'ona_your_key_here',
|
|
365
|
+
environment: 'production'
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
// 2. Use SDK methods
|
|
369
|
+
const result = await sdk.collectData({...});
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Node.js Backend
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
import { OnairosAPI } from 'onairos-node';
|
|
376
|
+
|
|
377
|
+
// 1. Initialize API client
|
|
378
|
+
const api = new OnairosAPI({
|
|
379
|
+
apiKey: 'ona_your_key_here',
|
|
380
|
+
environment: 'production'
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// 2. Make API calls
|
|
384
|
+
const validation = await api.validateKey();
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
## 🔍 Testing & Debugging
|
|
388
|
+
|
|
389
|
+
### Test API Key Validation
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
# Test with curl
|
|
393
|
+
curl -X POST https://api2.onairos.uk/dev/validate \
|
|
394
|
+
-H "Authorization: Bearer ona_your_key_here" \
|
|
395
|
+
-H "Content-Type: application/json" \
|
|
396
|
+
-d '{
|
|
397
|
+
"environment": "production",
|
|
398
|
+
"platform": "test"
|
|
399
|
+
}'
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Debug Mode
|
|
403
|
+
|
|
404
|
+
Enable logging in SDK initialization:
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
await initializeApiKey({
|
|
408
|
+
apiKey: 'ona_your_key_here',
|
|
409
|
+
enableLogging: true // Shows detailed logs
|
|
410
|
+
});
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## 📞 Support
|
|
414
|
+
|
|
415
|
+
- **Documentation**: https://docs.onairos.uk
|
|
416
|
+
- **Dashboard**: https://dashboard.onairos.uk
|
|
417
|
+
- **Support**: support@onairos.uk
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
*Last updated: October 2024*
|