onairos 4.0.21 → 4.0.23

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.
Files changed (50) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +397 -397
  3. package/dist/10.js +1 -1
  4. package/dist/123.js +1 -1
  5. package/dist/129.js +1 -1
  6. package/dist/18.js +1 -1
  7. package/dist/185.js +1 -1
  8. package/dist/22.js +1 -1
  9. package/dist/225.js +1 -1
  10. package/dist/241.js +1 -1
  11. package/dist/31.js +1 -1
  12. package/dist/336.js +1 -1
  13. package/dist/342.js +1 -1
  14. package/dist/342.js.map +1 -1
  15. package/dist/360.js +1 -1
  16. package/dist/421.js +1 -1
  17. package/dist/433.js +1 -1
  18. package/dist/502.js +1 -1
  19. package/dist/540.js +1 -1
  20. package/dist/540.js.map +1 -1
  21. package/dist/575.js +1 -1
  22. package/dist/592.js +1 -1
  23. package/dist/659.js +1 -1
  24. package/dist/672.js +1 -1
  25. package/dist/672.js.map +1 -1
  26. package/dist/845.js +1 -1
  27. package/dist/911.js +1 -1
  28. package/dist/947.js +1 -1
  29. package/dist/961.js +1 -1
  30. package/dist/961.js.map +1 -1
  31. package/dist/991.js +1 -1
  32. package/dist/999.js +1 -1
  33. package/dist/data_request_iframe.html +11 -11
  34. package/dist/data_request_popup.html +320 -320
  35. package/dist/iframe.bundle.js +1 -1
  36. package/dist/iframe.bundle.js.map +1 -1
  37. package/dist/oauth-callback.html +137 -206
  38. package/dist/onairos-laravel.js +1 -1
  39. package/dist/onairos-laravel.js.map +1 -1
  40. package/dist/onairos.bundle.js +1 -1
  41. package/dist/onairos.bundle.js.map +1 -1
  42. package/dist/onairos.esm.js +1 -1
  43. package/dist/onairos.esm.js.map +1 -1
  44. package/dist/src_onairosButton_jsx.js +1 -1
  45. package/dist/static/8c5b220bf6f482881a90.png +1 -1
  46. package/dist/vendors-node_modules_lottie-react_build_index_umd_js-node_modules_lucide-react_dist_esm_icons-20f774.js +1 -1
  47. package/dist/vendors-node_modules_react-dom_index_js.js +1 -1
  48. package/dist/vendors-node_modules_react_index_js.js +1 -1
  49. package/llm.txt +333 -333
  50. package/package.json +171 -167
package/llm.txt CHANGED
@@ -1,334 +1,334 @@
1
- Using this llm instruction file (@llm.txt) and the Onairos package this is located in (@onairos)
2
- install and setup Onairos so that we have the onairos button setup in the onbaording and the intialization
3
- and everything else is setup, including tthe callback function for us to export the data from onairos easily
4
-
5
- The following is depth description Onairos package
6
-
7
- # Onairos NPM Package - LLM Context
8
-
9
- ## Package Overview
10
- - **Version**: 3.1.23
11
- - **Type**: React Web Library for Data Requests & OAuth Authentication
12
- - **Main Use**: Personal AI training data collection via social media OAuth
13
- - **Base API**: `https://api2.onairos.uk` (production), `staging-api.onairos.uk` (staging), `dev-api.onairos.uk` (development)
14
- - **Authentication**: Two-tier system (Developer API Keys + JWT User Tokens)
15
-
16
- ## Key Features ✅
17
- 1. **Data Request System**: Users can share "basic info", "personality", or "preferences" data
18
- 2. **OAuth Connectors**: 9 platforms (YouTube, LinkedIn, Reddit, Pinterest, Instagram, GitHub, Facebook, Gmail, Notion)
19
- 3. **Mobile Browser Support**: Auto-detects mobile and switches popup → redirect OAuth flow
20
- 4. **API Integration**: Supports both test/live modes with automatic endpoint switching
21
- 5. **PIN-based Encryption**: All models encrypted with user PIN + server key
22
- 6. **Responsive Design**: Tailwind CSS with mobile-first approach
23
- 7. **API Key Initialization**: Developer API key setup for authentication and environment configuration
24
-
25
- ## Mobile Browser Compatibility ✅
26
- **WORKS PERFECTLY**: React components, API calls, touch interactions, responsive design, state management
27
-
28
- **AUTO-OPTIMIZED**: OAuth flow automatically detects mobile devices:
29
- - **Desktop**: Popup OAuth windows (`window.open`)
30
- - **Mobile**: Redirect OAuth flow (`window.location.href`)
31
-
32
- ## OAuth Implementation ✅
33
- **Endpoints**: All OAuth connectors use `api2.onairos.uk/{platform}/authorize`
34
- - YouTube: `api2.onairos.uk/youtube/authorize`
35
- - LinkedIn: `api2.onairos.uk/linkedin/authorize`
36
- - Reddit: `api2.onairos.uk/reddit/authorize`
37
- - Pinterest: `api2.onairos.uk/pinterest/authorize`
38
- - Instagram: `api2.onairos.uk/instagram/authorize`
39
- - GitHub: `api2.onairos.uk/github/authorize`
40
- - Facebook: `api2.onairos.uk/facebook/authorize`
41
- - Gmail: `api2.onairos.uk/gmail/authorize`
42
- - Notion: `api2.onairos.uk/notion/authorize`
43
-
44
- **Flow**: POST request → Get OAuth URL → Open popup/redirect → Handle callback → Update connection state
45
-
46
- ## API Endpoints & Environment Configuration
47
-
48
- ### Environment URLs
49
- ```typescript
50
- const API_ENDPOINTS = {
51
- production: 'https://api2.onairos.uk',
52
- staging: 'https://staging-api.onairos.uk',
53
- development: 'https://dev-api.onairos.uk',
54
- };
55
- ```
56
-
57
- ### Developer API Key Endpoints (Tier 1)
58
- - **API Key Validation**: `POST /auth/validate-key`
59
- - **Email Verification**: `POST /email/verification`
60
- - **App Registration**: `POST /app/register`
61
- - **OAuth Setup**: `POST /oauth/{platform}/setup`
62
-
63
- ### JWT User Token Endpoints (Tier 2)
64
- - **User Profile**: `GET /user/profile`
65
- - **PIN Operations**: `POST /user/pin`
66
- - **Data Requests**: `POST /user/data-request`
67
- - **Training Routes**: `POST /mobile-training/clean` (regular) or `/enoch` (advanced)
68
-
69
- ### Authentication Headers
70
-
71
- **Developer API Key Headers:**
72
- ```typescript
73
- {
74
- 'Content-Type': 'application/json',
75
- 'Authorization': `Bearer ${apiKey}`,
76
- 'User-Agent': 'OnairosSDK/1.0.0',
77
- 'X-SDK-Version': '3.0.72',
78
- 'X-SDK-Environment': 'production',
79
- 'X-API-Key-Type': 'developer',
80
- 'X-Timestamp': new Date().toISOString(),
81
- }
82
- ```
83
-
84
- **JWT User Token Headers:**
85
- ```typescript
86
- {
87
- 'Content-Type': 'application/json',
88
- 'Authorization': `Bearer ${jwtToken}`,
89
- 'User-Agent': 'OnairosSDK/1.0.0',
90
- 'X-SDK-Version': '3.0.72',
91
- 'X-SDK-Environment': 'production',
92
- }
93
- ```
94
-
95
- ## Data Flow
96
- 1. **API Key Initialization** → 2. **Email Authentication** → 3. **OAuth Connections** → 4. **PIN Setup** → 5. **Data Request**
97
-
98
- **Backend Format**:
99
- ```json
100
- {
101
- "Info": {
102
- "web3Type": "Normal",
103
- "confirmations": ["Medium", "Large", "Traits"],
104
- "Domain": "example.com",
105
- "EncryptedUserPin": "encrypted_pin",
106
- "UserSub": "user_hash"
107
- }
108
- }
109
- ```
110
-
111
- ## API Key Setup ✅
112
- **CRITICAL**: Must initialize API key before using any Onairos components
113
-
114
- ### Two-Tier Authentication System 🔐
115
- 1. **Developer API Keys**: For app-level operations (email verification, app registration)
116
- 2. **JWT User Tokens**: For user-level operations (PIN storage, user profile)
117
-
118
- ### Complete Initialization
119
- ```typescript
120
- import { initializeApiKey } from 'onairos';
121
-
122
- // Initialize with developer key
123
- await initializeApiKey({
124
- apiKey: 'ona_your_api_key_here', // Get from Onairos Dashboard
125
- environment: 'production', // 'production' | 'staging' | 'development'
126
- enableLogging: true,
127
- timeout: 30000, // Optional: Request timeout (default: 30000ms)
128
- retryAttempts: 3 // Optional: Retry attempts (default: 3)
129
- });
130
- ```
131
-
132
- ### Supported API Key Formats
133
- - **Developer Keys**: `dev_`, `pk_`, `ona_` prefixes + 32+ characters
134
- - **Admin Key**: Available for testing (contact support for access)
135
- - **Validation**: Backend validation with 5-minute cache
136
-
137
- ### Configuration Interface
138
- ```typescript
139
- interface OnairosConfig {
140
- apiKey: string; // Required: Your API key
141
- environment?: 'production' | 'staging' | 'development'; // Default: 'production'
142
- enableLogging?: boolean; // Default: true
143
- timeout?: number; // Default: 30000ms
144
- retryAttempts?: number; // Default: 3
145
- }
146
- ```
147
-
148
- ## Key Components & Functions
149
-
150
- ### Exposed SDK Functions
151
- - **initializeApiKey**: Primary SDK initialization with developer API key validation (REQUIRED)
152
-
153
- ### UI Components
154
- - **OnairosButton**: Main entry point with props (testMode, autoFetch, requestData)
155
- - **UniversalOnboarding**: OAuth connector management with mobile detection
156
- - **DataRequest**: Data type selection with visual checkmarks
157
- - **EmailAuth**: Email verification flow
158
- - **PinSetup**: PIN creation for encryption
159
-
160
- ### Internal Functions (Not Exposed)
161
- The SDK internally handles:
162
- - JWT token management (store/load/clear)
163
- - Developer vs user request authentication
164
- - API key validation and caching
165
- - OAuth flow management
166
- - Error handling and retry logic
167
-
168
- ## Mobile-Specific Features ✅
169
- - **MobileDataRequestPage**: Mobile-optimized data request UI
170
- - **Touch Events**: Proper touch handling with `touchAction` CSS
171
- - **Viewport Management**: Dynamic viewport height for mobile browsers
172
- - **Mobile OAuth Return**: Handles OAuth callback cleanup in mobile redirect flow
173
-
174
- ## Known Discrepancies
175
- ❌ **NONE** - All OAuth flows now properly handle both desktop and mobile
176
- ❌ **NONE** - All API endpoints use correct `api2.onairos.uk` domain
177
- ❌ **NONE** - Mobile browser compatibility is complete
178
-
179
- ## Recent Updates (v2.1.5 → v3.1.8)
180
- ✅ **Two-Tier Authentication System**: Developer API keys + JWT user tokens
181
- ✅ **Comprehensive SDK Initialization**: `initializeApiKey()` with full validation
182
- ✅ **JWT Token Management**: Automatic storage, loading, and cleanup
183
- ✅ **Multi-Environment Support**: Production, staging, development endpoints
184
- ✅ **Advanced Error Handling**: Retry logic, exponential backoff, auto-recovery
185
- ✅ **API Key Validation**: Backend validation with 5-minute caching
186
- ✅ **Request Authentication**: Separate headers for developer vs user requests
187
- ✅ **Mobile device detection for OAuth flows**
188
- ✅ **Mobile OAuth redirect handling**
189
- ✅ **Enhanced OAuth URL parsing for all 9 platforms**
190
- ✅ **Mobile browser compatibility documentation**
191
- ✅ **Fixed OAuth popup blocking on mobile devices**
192
- ✅ **Fixed TypeScript declaration file resolution issue in package.json exports**
193
- ✅ **React Native AsyncStorage integration for JWT persistence**
194
- ✅ **Comprehensive logging system with configurable levels**
195
- ✅ **Admin key support for testing and development**
196
- ✅ **HTTP client abstraction with automatic authentication headers**
197
-
198
- ## Complete Usage Flow 🚀
199
-
200
- ### Step 1: Initialize SDK (Required)
201
- ```typescript
202
- import { initializeApiKey } from 'onairos';
203
-
204
- // Initialize SDK with developer API key
205
- try {
206
- await initializeApiKey({
207
- apiKey: 'ona_your_api_key_here', // Get from Onairos Dashboard
208
- environment: 'production',
209
- enableLogging: true,
210
- timeout: 30000,
211
- retryAttempts: 3
212
- });
213
-
214
- console.log('SDK initialized successfully!');
215
- } catch (error) {
216
- console.error('SDK initialization failed:', error.message);
217
- }
218
- ```
219
-
220
- ### Step 2: Use Onairos Components
221
- ```typescript
222
- import { OnairosButton } from 'onairos';
223
-
224
- // Components automatically handle all authentication internally
225
- <OnairosButton
226
- requestData={{
227
- basic: { type: "basic", reward: "10 tokens" },
228
- personality: { type: "personality", reward: "25 tokens" },
229
- preferences: { type: "preferences", reward: "15 tokens" }
230
- }}
231
- webpageName="MyApp"
232
- testMode={false}
233
- autoFetch={true}
234
- onComplete={(result) => console.log(result)}
235
- />
236
- ```
237
-
238
- ## Error Handling & Retry Logic 🛡️
239
-
240
- ### API Key Validation Errors
241
- ```typescript
242
- // Invalid format
243
- throw new Error('Invalid API key format. Developer keys must be at least 32 characters and start with "dev_", "pk_", or "ona_"');
244
-
245
- // Backend validation failure
246
- throw new Error(`API key validation failed: ${validation.error}`);
247
-
248
- // Rate limiting
249
- throw new Error('API rate limit exceeded. Please try again later.');
250
- ```
251
-
252
- ### HTTP Request Errors
253
- - **401 Unauthorized**: Invalid/expired API key or JWT token
254
- - **403 Forbidden**: Insufficient permissions
255
- - **429 Too Many Requests**: Rate limit exceeded
256
- - **500 Server Error**: Backend service unavailable
257
-
258
- ### Automatic Retry Logic
259
- - **Retry Attempts**: Configurable (default: 3)
260
- - **Timeout**: Configurable (default: 30000ms)
261
- - **Exponential Backoff**: For 429 and 5xx errors
262
- - **JWT Auto-Clear**: Clears expired JWT tokens on 401
263
-
264
- ## Critical Success Factors
265
- 1. **Two-Tier Authentication**: Developer API keys → JWT tokens → User operations
266
- 2. **SDK Initialization**: Must call `initializeApiKey()` before using any components
267
- 3. **Environment Configuration**: Proper staging/production endpoint management
268
- 4. **Cross-Platform**: Same React code works in desktop browsers, mobile browsers, and React Native
269
- 5. **OAuth Reliability**: Auto-detects environment and uses appropriate OAuth flow
270
- 6. **JWT Token Management**: Automatic storage, loading, and cleanup of user sessions
271
- 7. **Mobile UX**: Touch-friendly UI with proper viewport handling
272
- 8. **Error Handling**: Comprehensive error states, retry logic, and user guidance
273
-
274
- ## TypeScript Support ✅
275
- **Full TypeScript Support**: Complete type definitions provided in `onairos.d.ts`
276
-
277
- **Usage with TypeScript**:
278
- ```typescript
279
- import { OnairosButton } from 'onairos';
280
- import type { OnairosProps } from 'onairos';
281
-
282
- // Component usage with full type safety
283
- const MyComponent: React.FC = () => {
284
- return (
285
- <OnairosButton
286
- requestData={{
287
- basic: { type: "basic", reward: "10 tokens" },
288
- personality: { type: "personality", reward: "25 tokens" },
289
- preferences: { type: "preferences", reward: "15 tokens" }
290
- }}
291
- webpageName="MyApp"
292
- testMode={false}
293
- autoFetch={true}
294
- onComplete={(result) => console.log(result)}
295
- />
296
- );
297
- };
298
- ```
299
-
300
- **Common TypeScript Issues & Solutions**:
301
- - **"Could not find declaration file"**: Fixed in v2.1.5 by adding `types` field to package.json exports
302
- - **Import errors**: Always import from `'onairos'` (not specific paths)
303
- - **Type inference**: All components have full TypeScript support with IntelliSense
304
-
305
- ## SDK Consistency Across Platforms 🔄
306
-
307
- ### For Other SDK Implementations
308
- To ensure consistency across all Onairos SDKs, implement:
309
-
310
- 1. **Same API Key Formats**: `dev_`, `pk_`, `ona_` prefixes + 32+ character length
311
- 2. **Same Validation Endpoint**: `POST /auth/validate-key`
312
- 3. **Same Headers Structure**: Authorization, X-API-Key-Type, X-SDK-Version, etc.
313
- 4. **Same Two-Tier Auth**: Developer keys → JWT tokens → User operations
314
- 5. **Same Error Handling**: 401, 403, 429 status codes with retry logic
315
- 6. **Same Caching**: 5-minute validation cache for API keys
316
- 7. **Same Admin Key**: `'OnairosIsAUnicorn2025'` for testing
317
-
318
- ### Environment Consistency
319
- ```typescript
320
- // All SDKs should use the same endpoint structure
321
- const endpoints = {
322
- production: 'https://api2.onairos.uk',
323
- staging: 'https://staging-api.onairos.uk',
324
- development: 'https://dev-api.onairos.uk'
325
- };
326
- ```
327
-
328
- ## Build & Development
329
- - **Build**: `npm run build` (creates dist/ folder)
330
- - **Test Files**: Multiple test HTML files for different scenarios
331
- - **Entry Points**: `src/index.js` (main), `src/onairos.native.jsx` (React Native)
332
- - **Responsive**: Tailwind CSS with `sm:`, `md:`, `lg:` breakpoints throughout
333
- - **TypeScript**: Full type definitions with proper package.json exports configuration
1
+ Using this llm instruction file (@llm.txt) and the Onairos package this is located in (@onairos)
2
+ install and setup Onairos so that we have the onairos button setup in the onbaording and the intialization
3
+ and everything else is setup, including tthe callback function for us to export the data from onairos easily
4
+
5
+ The following is depth description Onairos package
6
+
7
+ # Onairos NPM Package - LLM Context
8
+
9
+ ## Package Overview
10
+ - **Version**: 3.1.23
11
+ - **Type**: React Web Library for Data Requests & OAuth Authentication
12
+ - **Main Use**: Personal AI training data collection via social media OAuth
13
+ - **Base API**: `https://api2.onairos.uk` (production), `staging-api.onairos.uk` (staging), `dev-api.onairos.uk` (development)
14
+ - **Authentication**: Two-tier system (Developer API Keys + JWT User Tokens)
15
+
16
+ ## Key Features ✅
17
+ 1. **Data Request System**: Users can share "basic info", "personality", or "preferences" data
18
+ 2. **OAuth Connectors**: 9 platforms (YouTube, LinkedIn, Reddit, Pinterest, Instagram, GitHub, Facebook, Gmail, Notion)
19
+ 3. **Mobile Browser Support**: Auto-detects mobile and switches popup → redirect OAuth flow
20
+ 4. **API Integration**: Supports both test/live modes with automatic endpoint switching
21
+ 5. **PIN-based Encryption**: All models encrypted with user PIN + server key
22
+ 6. **Responsive Design**: Tailwind CSS with mobile-first approach
23
+ 7. **API Key Initialization**: Developer API key setup for authentication and environment configuration
24
+
25
+ ## Mobile Browser Compatibility ✅
26
+ **WORKS PERFECTLY**: React components, API calls, touch interactions, responsive design, state management
27
+
28
+ **AUTO-OPTIMIZED**: OAuth flow automatically detects mobile devices:
29
+ - **Desktop**: Popup OAuth windows (`window.open`)
30
+ - **Mobile**: Redirect OAuth flow (`window.location.href`)
31
+
32
+ ## OAuth Implementation ✅
33
+ **Endpoints**: All OAuth connectors use `api2.onairos.uk/{platform}/authorize`
34
+ - YouTube: `api2.onairos.uk/youtube/authorize`
35
+ - LinkedIn: `api2.onairos.uk/linkedin/authorize`
36
+ - Reddit: `api2.onairos.uk/reddit/authorize`
37
+ - Pinterest: `api2.onairos.uk/pinterest/authorize`
38
+ - Instagram: `api2.onairos.uk/instagram/authorize`
39
+ - GitHub: `api2.onairos.uk/github/authorize`
40
+ - Facebook: `api2.onairos.uk/facebook/authorize`
41
+ - Gmail: `api2.onairos.uk/gmail/authorize`
42
+ - Notion: `api2.onairos.uk/notion/authorize`
43
+
44
+ **Flow**: POST request → Get OAuth URL → Open popup/redirect → Handle callback → Update connection state
45
+
46
+ ## API Endpoints & Environment Configuration
47
+
48
+ ### Environment URLs
49
+ ```typescript
50
+ const API_ENDPOINTS = {
51
+ production: 'https://api2.onairos.uk',
52
+ staging: 'https://staging-api.onairos.uk',
53
+ development: 'https://dev-api.onairos.uk',
54
+ };
55
+ ```
56
+
57
+ ### Developer API Key Endpoints (Tier 1)
58
+ - **API Key Validation**: `POST /auth/validate-key`
59
+ - **Email Verification**: `POST /email/verification`
60
+ - **App Registration**: `POST /app/register`
61
+ - **OAuth Setup**: `POST /oauth/{platform}/setup`
62
+
63
+ ### JWT User Token Endpoints (Tier 2)
64
+ - **User Profile**: `GET /user/profile`
65
+ - **PIN Operations**: `POST /user/pin`
66
+ - **Data Requests**: `POST /user/data-request`
67
+ - **Training Routes**: `POST /mobile-training/clean` (regular) or `/enoch` (advanced)
68
+
69
+ ### Authentication Headers
70
+
71
+ **Developer API Key Headers:**
72
+ ```typescript
73
+ {
74
+ 'Content-Type': 'application/json',
75
+ 'Authorization': `Bearer ${apiKey}`,
76
+ 'User-Agent': 'OnairosSDK/1.0.0',
77
+ 'X-SDK-Version': '3.0.72',
78
+ 'X-SDK-Environment': 'production',
79
+ 'X-API-Key-Type': 'developer',
80
+ 'X-Timestamp': new Date().toISOString(),
81
+ }
82
+ ```
83
+
84
+ **JWT User Token Headers:**
85
+ ```typescript
86
+ {
87
+ 'Content-Type': 'application/json',
88
+ 'Authorization': `Bearer ${jwtToken}`,
89
+ 'User-Agent': 'OnairosSDK/1.0.0',
90
+ 'X-SDK-Version': '3.0.72',
91
+ 'X-SDK-Environment': 'production',
92
+ }
93
+ ```
94
+
95
+ ## Data Flow
96
+ 1. **API Key Initialization** → 2. **Email Authentication** → 3. **OAuth Connections** → 4. **PIN Setup** → 5. **Data Request**
97
+
98
+ **Backend Format**:
99
+ ```json
100
+ {
101
+ "Info": {
102
+ "web3Type": "Normal",
103
+ "confirmations": ["Medium", "Large", "Traits"],
104
+ "Domain": "example.com",
105
+ "EncryptedUserPin": "encrypted_pin",
106
+ "UserSub": "user_hash"
107
+ }
108
+ }
109
+ ```
110
+
111
+ ## API Key Setup ✅
112
+ **CRITICAL**: Must initialize API key before using any Onairos components
113
+
114
+ ### Two-Tier Authentication System 🔐
115
+ 1. **Developer API Keys**: For app-level operations (email verification, app registration)
116
+ 2. **JWT User Tokens**: For user-level operations (PIN storage, user profile)
117
+
118
+ ### Complete Initialization
119
+ ```typescript
120
+ import { initializeApiKey } from 'onairos';
121
+
122
+ // Initialize with developer key
123
+ await initializeApiKey({
124
+ apiKey: 'ona_your_api_key_here', // Get from Onairos Dashboard
125
+ environment: 'production', // 'production' | 'staging' | 'development'
126
+ enableLogging: true,
127
+ timeout: 30000, // Optional: Request timeout (default: 30000ms)
128
+ retryAttempts: 3 // Optional: Retry attempts (default: 3)
129
+ });
130
+ ```
131
+
132
+ ### Supported API Key Formats
133
+ - **Developer Keys**: `dev_`, `pk_`, `ona_` prefixes + 32+ characters
134
+ - **Admin Key**: Available for testing (contact support for access)
135
+ - **Validation**: Backend validation with 5-minute cache
136
+
137
+ ### Configuration Interface
138
+ ```typescript
139
+ interface OnairosConfig {
140
+ apiKey: string; // Required: Your API key
141
+ environment?: 'production' | 'staging' | 'development'; // Default: 'production'
142
+ enableLogging?: boolean; // Default: true
143
+ timeout?: number; // Default: 30000ms
144
+ retryAttempts?: number; // Default: 3
145
+ }
146
+ ```
147
+
148
+ ## Key Components & Functions
149
+
150
+ ### Exposed SDK Functions
151
+ - **initializeApiKey**: Primary SDK initialization with developer API key validation (REQUIRED)
152
+
153
+ ### UI Components
154
+ - **OnairosButton**: Main entry point with props (testMode, autoFetch, requestData)
155
+ - **UniversalOnboarding**: OAuth connector management with mobile detection
156
+ - **DataRequest**: Data type selection with visual checkmarks
157
+ - **EmailAuth**: Email verification flow
158
+ - **PinSetup**: PIN creation for encryption
159
+
160
+ ### Internal Functions (Not Exposed)
161
+ The SDK internally handles:
162
+ - JWT token management (store/load/clear)
163
+ - Developer vs user request authentication
164
+ - API key validation and caching
165
+ - OAuth flow management
166
+ - Error handling and retry logic
167
+
168
+ ## Mobile-Specific Features ✅
169
+ - **MobileDataRequestPage**: Mobile-optimized data request UI
170
+ - **Touch Events**: Proper touch handling with `touchAction` CSS
171
+ - **Viewport Management**: Dynamic viewport height for mobile browsers
172
+ - **Mobile OAuth Return**: Handles OAuth callback cleanup in mobile redirect flow
173
+
174
+ ## Known Discrepancies
175
+ ❌ **NONE** - All OAuth flows now properly handle both desktop and mobile
176
+ ❌ **NONE** - All API endpoints use correct `api2.onairos.uk` domain
177
+ ❌ **NONE** - Mobile browser compatibility is complete
178
+
179
+ ## Recent Updates (v2.1.5 → v3.1.8)
180
+ ✅ **Two-Tier Authentication System**: Developer API keys + JWT user tokens
181
+ ✅ **Comprehensive SDK Initialization**: `initializeApiKey()` with full validation
182
+ ✅ **JWT Token Management**: Automatic storage, loading, and cleanup
183
+ ✅ **Multi-Environment Support**: Production, staging, development endpoints
184
+ ✅ **Advanced Error Handling**: Retry logic, exponential backoff, auto-recovery
185
+ ✅ **API Key Validation**: Backend validation with 5-minute caching
186
+ ✅ **Request Authentication**: Separate headers for developer vs user requests
187
+ ✅ **Mobile device detection for OAuth flows**
188
+ ✅ **Mobile OAuth redirect handling**
189
+ ✅ **Enhanced OAuth URL parsing for all 9 platforms**
190
+ ✅ **Mobile browser compatibility documentation**
191
+ ✅ **Fixed OAuth popup blocking on mobile devices**
192
+ ✅ **Fixed TypeScript declaration file resolution issue in package.json exports**
193
+ ✅ **React Native AsyncStorage integration for JWT persistence**
194
+ ✅ **Comprehensive logging system with configurable levels**
195
+ ✅ **Admin key support for testing and development**
196
+ ✅ **HTTP client abstraction with automatic authentication headers**
197
+
198
+ ## Complete Usage Flow 🚀
199
+
200
+ ### Step 1: Initialize SDK (Required)
201
+ ```typescript
202
+ import { initializeApiKey } from 'onairos';
203
+
204
+ // Initialize SDK with developer API key
205
+ try {
206
+ await initializeApiKey({
207
+ apiKey: 'ona_your_api_key_here', // Get from Onairos Dashboard
208
+ environment: 'production',
209
+ enableLogging: true,
210
+ timeout: 30000,
211
+ retryAttempts: 3
212
+ });
213
+
214
+ console.log('SDK initialized successfully!');
215
+ } catch (error) {
216
+ console.error('SDK initialization failed:', error.message);
217
+ }
218
+ ```
219
+
220
+ ### Step 2: Use Onairos Components
221
+ ```typescript
222
+ import { OnairosButton } from 'onairos';
223
+
224
+ // Components automatically handle all authentication internally
225
+ <OnairosButton
226
+ requestData={{
227
+ basic: { type: "basic", reward: "10 tokens" },
228
+ personality: { type: "personality", reward: "25 tokens" },
229
+ preferences: { type: "preferences", reward: "15 tokens" }
230
+ }}
231
+ webpageName="MyApp"
232
+ testMode={false}
233
+ autoFetch={true}
234
+ onComplete={(result) => console.log(result)}
235
+ />
236
+ ```
237
+
238
+ ## Error Handling & Retry Logic 🛡️
239
+
240
+ ### API Key Validation Errors
241
+ ```typescript
242
+ // Invalid format
243
+ throw new Error('Invalid API key format. Developer keys must be at least 32 characters and start with "dev_", "pk_", or "ona_"');
244
+
245
+ // Backend validation failure
246
+ throw new Error(`API key validation failed: ${validation.error}`);
247
+
248
+ // Rate limiting
249
+ throw new Error('API rate limit exceeded. Please try again later.');
250
+ ```
251
+
252
+ ### HTTP Request Errors
253
+ - **401 Unauthorized**: Invalid/expired API key or JWT token
254
+ - **403 Forbidden**: Insufficient permissions
255
+ - **429 Too Many Requests**: Rate limit exceeded
256
+ - **500 Server Error**: Backend service unavailable
257
+
258
+ ### Automatic Retry Logic
259
+ - **Retry Attempts**: Configurable (default: 3)
260
+ - **Timeout**: Configurable (default: 30000ms)
261
+ - **Exponential Backoff**: For 429 and 5xx errors
262
+ - **JWT Auto-Clear**: Clears expired JWT tokens on 401
263
+
264
+ ## Critical Success Factors
265
+ 1. **Two-Tier Authentication**: Developer API keys → JWT tokens → User operations
266
+ 2. **SDK Initialization**: Must call `initializeApiKey()` before using any components
267
+ 3. **Environment Configuration**: Proper staging/production endpoint management
268
+ 4. **Cross-Platform**: Same React code works in desktop browsers, mobile browsers, and React Native
269
+ 5. **OAuth Reliability**: Auto-detects environment and uses appropriate OAuth flow
270
+ 6. **JWT Token Management**: Automatic storage, loading, and cleanup of user sessions
271
+ 7. **Mobile UX**: Touch-friendly UI with proper viewport handling
272
+ 8. **Error Handling**: Comprehensive error states, retry logic, and user guidance
273
+
274
+ ## TypeScript Support ✅
275
+ **Full TypeScript Support**: Complete type definitions provided in `onairos.d.ts`
276
+
277
+ **Usage with TypeScript**:
278
+ ```typescript
279
+ import { OnairosButton } from 'onairos';
280
+ import type { OnairosProps } from 'onairos';
281
+
282
+ // Component usage with full type safety
283
+ const MyComponent: React.FC = () => {
284
+ return (
285
+ <OnairosButton
286
+ requestData={{
287
+ basic: { type: "basic", reward: "10 tokens" },
288
+ personality: { type: "personality", reward: "25 tokens" },
289
+ preferences: { type: "preferences", reward: "15 tokens" }
290
+ }}
291
+ webpageName="MyApp"
292
+ testMode={false}
293
+ autoFetch={true}
294
+ onComplete={(result) => console.log(result)}
295
+ />
296
+ );
297
+ };
298
+ ```
299
+
300
+ **Common TypeScript Issues & Solutions**:
301
+ - **"Could not find declaration file"**: Fixed in v2.1.5 by adding `types` field to package.json exports
302
+ - **Import errors**: Always import from `'onairos'` (not specific paths)
303
+ - **Type inference**: All components have full TypeScript support with IntelliSense
304
+
305
+ ## SDK Consistency Across Platforms 🔄
306
+
307
+ ### For Other SDK Implementations
308
+ To ensure consistency across all Onairos SDKs, implement:
309
+
310
+ 1. **Same API Key Formats**: `dev_`, `pk_`, `ona_` prefixes + 32+ character length
311
+ 2. **Same Validation Endpoint**: `POST /auth/validate-key`
312
+ 3. **Same Headers Structure**: Authorization, X-API-Key-Type, X-SDK-Version, etc.
313
+ 4. **Same Two-Tier Auth**: Developer keys → JWT tokens → User operations
314
+ 5. **Same Error Handling**: 401, 403, 429 status codes with retry logic
315
+ 6. **Same Caching**: 5-minute validation cache for API keys
316
+ 7. **Same Admin Key**: `'OnairosIsAUnicorn2025'` for testing
317
+
318
+ ### Environment Consistency
319
+ ```typescript
320
+ // All SDKs should use the same endpoint structure
321
+ const endpoints = {
322
+ production: 'https://api2.onairos.uk',
323
+ staging: 'https://staging-api.onairos.uk',
324
+ development: 'https://dev-api.onairos.uk'
325
+ };
326
+ ```
327
+
328
+ ## Build & Development
329
+ - **Build**: `npm run build` (creates dist/ folder)
330
+ - **Test Files**: Multiple test HTML files for different scenarios
331
+ - **Entry Points**: `src/index.js` (main), `src/onairos.native.jsx` (React Native)
332
+ - **Responsive**: Tailwind CSS with `sm:`, `md:`, `lg:` breakpoints throughout
333
+ - **TypeScript**: Full type definitions with proper package.json exports configuration
334
334
  - **Authentication**: Two-tier system ensures secure and scalable API access