onairos 2.2.1 → 2.3.1

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.
@@ -0,0 +1,643 @@
1
+ # Onairos Laravel Integration Guide
2
+
3
+ A comprehensive guide for integrating Onairos with Laravel Vite applications, supporting Blade templates, Vue.js, React, and mixed approaches.
4
+
5
+ ## 🚀 Quick Start
6
+
7
+ ### Prerequisites
8
+ - Laravel 9+ with Vite
9
+ - Node.js 16+
10
+ - npm or yarn
11
+
12
+ ### Installation
13
+
14
+ ```bash
15
+ npm install onairos
16
+ ```
17
+
18
+ ## 📋 Integration Options
19
+
20
+ ### Option 1: Blade Templates (PHP Only)
21
+
22
+ Perfect for traditional Laravel applications using Blade templates with minimal JavaScript.
23
+
24
+ #### 1. Add to your `vite.config.js`:
25
+
26
+ ```js
27
+ import { defineConfig } from 'vite';
28
+ import laravel from 'laravel-vite-plugin';
29
+ import { onairosLaravelPlugin } from 'onairos/vite-plugin';
30
+
31
+ export default defineConfig({
32
+ plugins: [
33
+ laravel({
34
+ input: ['resources/css/app.css', 'resources/js/app.js'],
35
+ refresh: true,
36
+ }),
37
+ onairosLaravelPlugin({
38
+ bladeSupport: true,
39
+ injectGlobals: true
40
+ })
41
+ ],
42
+ });
43
+ ```
44
+
45
+ #### 2. Include in your Blade layout:
46
+
47
+ ```blade
48
+ {{-- resources/views/layouts/app.blade.php --}}
49
+ <!DOCTYPE html>
50
+ <html>
51
+ <head>
52
+ <title>{{ config('app.name') }}</title>
53
+ @vite(['resources/css/app.css', 'resources/js/app.js'])
54
+ </head>
55
+ <body>
56
+ @yield('content')
57
+ </body>
58
+ </html>
59
+ ```
60
+
61
+ #### 3. Initialize in your `resources/js/app.js`:
62
+
63
+ ```js
64
+ import './bootstrap';
65
+ import { initializeOnairosForBlade } from 'onairos/blade';
66
+
67
+ // Initialize Onairos for Blade templates
68
+ document.addEventListener('DOMContentLoaded', () => {
69
+ initializeOnairosForBlade({
70
+ testMode: import.meta.env.DEV,
71
+ autoDetectMobile: true,
72
+ globalStyles: true
73
+ });
74
+ });
75
+ ```
76
+
77
+ #### 4. Use in Blade templates:
78
+
79
+ ```blade
80
+ {{-- resources/views/dashboard.blade.php --}}
81
+ @extends('layouts.app')
82
+
83
+ @section('content')
84
+ <div class="container">
85
+ <h1>Welcome to Dashboard</h1>
86
+
87
+ <!-- Simple button -->
88
+ <div id="onairos-button-1"></div>
89
+
90
+ <!-- Custom configuration -->
91
+ <div id="onairos-button-2"></div>
92
+ </div>
93
+
94
+ <script>
95
+ document.addEventListener('DOMContentLoaded', function() {
96
+ // Simple button
97
+ createOnairosButton('onairos-button-1', {
98
+ requestData: ['email', 'profile'],
99
+ webpageName: 'My Dashboard'
100
+ });
101
+
102
+ // Advanced button
103
+ createOnairosButton('onairos-button-2', {
104
+ requestData: {
105
+ basic: { type: "basic", reward: "10 tokens" },
106
+ personality: { type: "personality", reward: "25 tokens" }
107
+ },
108
+ webpageName: 'Advanced Dashboard',
109
+ buttonType: 'icon',
110
+ onComplete: function(result) {
111
+ alert('Connection successful!');
112
+ }
113
+ });
114
+ });
115
+ </script>
116
+ @endsection
117
+ ```
118
+
119
+ ---
120
+
121
+ ### Option 2: Vue.js Integration
122
+
123
+ Perfect for Laravel applications using Vue.js as the frontend framework.
124
+
125
+ #### 1. Install Vue plugin:
126
+
127
+ ```bash
128
+ npm install --save-dev @vitejs/plugin-vue
129
+ ```
130
+
131
+ #### 2. Update `vite.config.js`:
132
+
133
+ ```js
134
+ import { defineConfig } from 'vite';
135
+ import laravel from 'laravel-vite-plugin';
136
+ import vue from '@vitejs/plugin-vue';
137
+ import { onairosVuePlugin } from 'onairos/vite-plugin';
138
+
139
+ export default defineConfig({
140
+ plugins: [
141
+ laravel({
142
+ input: ['resources/css/app.css', 'resources/js/app.js'],
143
+ refresh: true,
144
+ }),
145
+ vue({
146
+ template: {
147
+ transformAssetUrls: {
148
+ base: null,
149
+ includeAbsolute: false,
150
+ },
151
+ },
152
+ }),
153
+ onairosVuePlugin({
154
+ autoImport: true
155
+ })
156
+ ],
157
+ });
158
+ ```
159
+
160
+ #### 3. Set up Vue in `resources/js/app.js`:
161
+
162
+ ```js
163
+ import './bootstrap';
164
+ import { createApp } from 'vue';
165
+ import OnairosVue from 'onairos/src/laravel/OnairosVue.vue';
166
+
167
+ const app = createApp({});
168
+
169
+ // Register Onairos component globally
170
+ app.component('onairos-button', OnairosVue);
171
+
172
+ app.mount('#app');
173
+ ```
174
+
175
+ #### 4. Use in Blade templates:
176
+
177
+ ```blade
178
+ {{-- resources/views/vue-dashboard.blade.php --}}
179
+ @extends('layouts.app')
180
+
181
+ @section('content')
182
+ <div id="app">
183
+ <div class="container">
184
+ <h1>Vue.js Dashboard</h1>
185
+
186
+ <!-- Basic usage -->
187
+ <onairos-button
188
+ :request-data="['email', 'profile']"
189
+ webpage-name="Vue Dashboard"
190
+ @complete="handleComplete"
191
+ ></onairos-button>
192
+
193
+ <!-- Advanced usage -->
194
+ <onairos-button
195
+ :request-data="{
196
+ basic: { type: 'basic', reward: '10 tokens' },
197
+ personality: { type: 'personality', reward: '25 tokens' }
198
+ }"
199
+ webpage-name="Advanced Vue Dashboard"
200
+ button-type="pill"
201
+ size="large"
202
+ @complete="handleAdvancedComplete"
203
+ @error="handleError"
204
+ >
205
+ Connect Advanced Features
206
+ </onairos-button>
207
+ </div>
208
+ </div>
209
+
210
+ <script>
211
+ function handleComplete(result) {
212
+ console.log('Onairos connection completed:', result);
213
+ }
214
+
215
+ function handleAdvancedComplete(result) {
216
+ console.log('Advanced connection completed:', result);
217
+ }
218
+
219
+ function handleError(error) {
220
+ console.error('Connection failed:', error);
221
+ }
222
+ </script>
223
+ @endsection
224
+ ```
225
+
226
+ #### 5. Use in Vue SFC files:
227
+
228
+ ```vue
229
+ {{-- resources/js/components/UserProfile.vue --}}
230
+ <template>
231
+ <div class="user-profile">
232
+ <h2>User Profile</h2>
233
+ <onairos-button
234
+ :request-data="['email', 'profile', 'preferences']"
235
+ :webpage-name="profileName"
236
+ :test-mode="isDevelopment"
237
+ size="medium"
238
+ @complete="onConnectionComplete"
239
+ @loading="onLoading"
240
+ >
241
+ Enhance Profile with AI
242
+ </onairos-button>
243
+ </div>
244
+ </template>
245
+
246
+ <script setup>
247
+ import { ref, computed } from 'vue';
248
+ import OnairosVue from 'onairos/src/laravel/OnairosVue.vue';
249
+
250
+ const profileName = ref('User Profile Enhancement');
251
+ const isDevelopment = computed(() => import.meta.env.DEV);
252
+
253
+ function onConnectionComplete(result) {
254
+ console.log('Profile enhancement completed:', result);
255
+ }
256
+
257
+ function onLoading(isLoading) {
258
+ console.log('Loading state:', isLoading);
259
+ }
260
+ </script>
261
+ ```
262
+
263
+ ---
264
+
265
+ ### Option 3: React Integration
266
+
267
+ For Laravel applications using React as the frontend framework.
268
+
269
+ #### 1. Install React plugin:
270
+
271
+ ```bash
272
+ npm install --save-dev @vitejs/plugin-react
273
+ ```
274
+
275
+ #### 2. Update `vite.config.js`:
276
+
277
+ ```js
278
+ import { defineConfig } from 'vite';
279
+ import laravel from 'laravel-vite-plugin';
280
+ import react from '@vitejs/plugin-react';
281
+ import { onairosReactPlugin } from 'onairos/vite-plugin';
282
+
283
+ export default defineConfig({
284
+ plugins: [
285
+ laravel({
286
+ input: ['resources/css/app.css', 'resources/js/app.jsx'],
287
+ refresh: true,
288
+ }),
289
+ react(),
290
+ onairosReactPlugin({
291
+ autoImport: true
292
+ })
293
+ ],
294
+ });
295
+ ```
296
+
297
+ #### 3. Set up React in `resources/js/app.jsx`:
298
+
299
+ ```jsx
300
+ import './bootstrap';
301
+ import React from 'react';
302
+ import { createRoot } from 'react-dom/client';
303
+ import { OnairosButton } from 'onairos';
304
+
305
+ function App() {
306
+ const handleComplete = (result) => {
307
+ console.log('Onairos connection completed:', result);
308
+ };
309
+
310
+ const handleError = (error) => {
311
+ console.error('Connection failed:', error);
312
+ };
313
+
314
+ return (
315
+ <div className="container">
316
+ <h1>React Dashboard</h1>
317
+
318
+ <OnairosButton
319
+ requestData={['email', 'profile']}
320
+ webpageName="React Dashboard"
321
+ onComplete={handleComplete}
322
+ onError={handleError}
323
+ buttonType="pill"
324
+ textColor="black"
325
+ />
326
+ </div>
327
+ );
328
+ }
329
+
330
+ const container = document.getElementById('app');
331
+ if (container) {
332
+ const root = createRoot(container);
333
+ root.render(<App />);
334
+ }
335
+ ```
336
+
337
+ ---
338
+
339
+ ## 🛠️ Advanced Configuration
340
+
341
+ ### Custom Vite Plugin Options
342
+
343
+ ```js
344
+ // vite.config.js
345
+ onairosLaravelPlugin({
346
+ // Auto-import Onairos components
347
+ autoImport: true,
348
+
349
+ // Inject global helpers for Blade templates
350
+ injectGlobals: true,
351
+
352
+ // Optimize dependencies for faster dev server
353
+ optimizeDeps: true,
354
+
355
+ // Enable Hot Module Replacement
356
+ enableHMR: true,
357
+
358
+ // Watch Blade files for changes
359
+ bladeSupport: true
360
+ })
361
+ ```
362
+
363
+ ### Environment Configuration
364
+
365
+ ```env
366
+ # .env
367
+ VITE_ONAIROS_API_KEY=your_api_key_here
368
+ VITE_ONAIROS_TEST_MODE=true
369
+ VITE_ONAIROS_BASE_URL=https://api2.onairos.uk
370
+ ```
371
+
372
+ ```js
373
+ // resources/js/app.js
374
+ initializeOnairosForBlade({
375
+ apiKey: import.meta.env.VITE_ONAIROS_API_KEY,
376
+ testMode: import.meta.env.VITE_ONAIROS_TEST_MODE === 'true',
377
+ baseUrl: import.meta.env.VITE_ONAIROS_BASE_URL
378
+ });
379
+ ```
380
+
381
+ ### Laravel Backend Integration
382
+
383
+ Create a controller to handle Onairos callbacks:
384
+
385
+ ```php
386
+ <?php
387
+ // app/Http/Controllers/OnairosController.php
388
+
389
+ namespace App\Http\Controllers;
390
+
391
+ use Illuminate\Http\Request;
392
+ use Illuminate\Support\Facades\Log;
393
+
394
+ class OnairosController extends Controller
395
+ {
396
+ public function callback(Request $request)
397
+ {
398
+ $data = $request->validate([
399
+ 'user_hash' => 'required|string',
400
+ 'connections' => 'required|array',
401
+ 'data_types' => 'required|array'
402
+ ]);
403
+
404
+ // Store user connections
405
+ $user = auth()->user();
406
+ if ($user) {
407
+ $user->update([
408
+ 'onairos_hash' => $data['user_hash'],
409
+ 'onairos_connections' => $data['connections'],
410
+ 'onairos_data_types' => $data['data_types']
411
+ ]);
412
+ }
413
+
414
+ Log::info('Onairos callback received', $data);
415
+
416
+ return response()->json(['success' => true]);
417
+ }
418
+ }
419
+ ```
420
+
421
+ Add routes:
422
+
423
+ ```php
424
+ // routes/web.php
425
+ use App\Http\Controllers\OnairosController;
426
+
427
+ Route::post('/onairos/callback', [OnairosController::class, 'callback'])
428
+ ->middleware('auth');
429
+ ```
430
+
431
+ ---
432
+
433
+ ## 🎨 Styling
434
+
435
+ ### Tailwind CSS Integration
436
+
437
+ ```js
438
+ // tailwind.config.js
439
+ module.exports = {
440
+ content: [
441
+ './resources/**/*.blade.php',
442
+ './resources/**/*.js',
443
+ './resources/**/*.vue',
444
+ './node_modules/onairos/**/*.{js,vue}'
445
+ ],
446
+ theme: {
447
+ extend: {
448
+ colors: {
449
+ 'onairos': {
450
+ 50: '#f0f4ff',
451
+ 500: '#667eea',
452
+ 600: '#5a67d8',
453
+ 700: '#4c51bf'
454
+ }
455
+ }
456
+ }
457
+ }
458
+ }
459
+ ```
460
+
461
+ ### Custom CSS
462
+
463
+ ```css
464
+ /* resources/css/onairos-custom.css */
465
+ .onairos-vue-btn {
466
+ @apply bg-gradient-to-r from-blue-500 to-purple-600 hover:from-blue-600 hover:to-purple-700;
467
+ }
468
+
469
+ .onairos-btn-pill {
470
+ @apply rounded-full;
471
+ }
472
+
473
+ .onairos-btn-large {
474
+ @apply px-8 py-4 text-lg;
475
+ }
476
+ ```
477
+
478
+ ---
479
+
480
+ ## 📱 Mobile Optimization
481
+
482
+ Onairos automatically detects mobile devices and switches OAuth flows:
483
+
484
+ - **Desktop**: Popup windows
485
+ - **Mobile**: Redirect-based flow
486
+
487
+ ### Mobile-Specific Configuration
488
+
489
+ ```js
490
+ // Auto-detect and configure for mobile
491
+ initializeOnairosForBlade({
492
+ autoDetectMobile: true,
493
+ mobileRedirectUrl: window.location.href,
494
+ popupDimensions: {
495
+ width: 450,
496
+ height: 700
497
+ }
498
+ });
499
+ ```
500
+
501
+ ---
502
+
503
+ ## 🚨 Troubleshooting
504
+
505
+ ### Common Issues
506
+
507
+ 1. **Vite Plugin Not Working**
508
+ ```bash
509
+ # Clear Vite cache
510
+ rm -rf node_modules/.vite
511
+ npm run dev
512
+ ```
513
+
514
+ 2. **Vue Component Not Rendering**
515
+ ```js
516
+ // Make sure Vue is properly configured
517
+ import { createApp } from 'vue';
518
+ const app = createApp({});
519
+ app.mount('#app');
520
+ ```
521
+
522
+ 3. **Blade Helpers Not Available**
523
+ ```js
524
+ // Check initialization
525
+ console.log(typeof window.createOnairosButton);
526
+ // Should log: "function"
527
+ ```
528
+
529
+ ### Debug Mode
530
+
531
+ Enable debug logging:
532
+
533
+ ```js
534
+ initializeOnairosForBlade({
535
+ debug: true,
536
+ testMode: true
537
+ });
538
+ ```
539
+
540
+ ---
541
+
542
+ ## 📚 API Reference
543
+
544
+ ### Blade Helpers
545
+
546
+ ```js
547
+ // Initialize Onairos for Blade templates
548
+ initializeOnairosForBlade(config)
549
+
550
+ // Create button in specific element
551
+ createOnairosButton(elementId, options)
552
+
553
+ // Render directive (for PHP integration)
554
+ renderOnairosDirective(options)
555
+ ```
556
+
557
+ ### Vue Component Props
558
+
559
+ ```typescript
560
+ interface OnairosVueProps {
561
+ requestData: Array | Object;
562
+ webpageName: string;
563
+ testMode?: boolean;
564
+ autoFetch?: boolean;
565
+ buttonType?: 'pill' | 'icon' | 'rounded';
566
+ textColor?: string;
567
+ textLayout?: 'left' | 'center' | 'right';
568
+ disabled?: boolean;
569
+ customClass?: string;
570
+ loadingText?: string;
571
+ successMessage?: string;
572
+ size?: 'small' | 'medium' | 'large';
573
+ }
574
+ ```
575
+
576
+ ### Events
577
+
578
+ ```js
579
+ // Blade templates
580
+ window.addEventListener('onairosAuthComplete', (event) => {
581
+ console.log('Auth completed:', event.detail);
582
+ });
583
+
584
+ // Vue components
585
+ @complete="handleComplete"
586
+ @error="handleError"
587
+ @loading="handleLoading"
588
+ @click="handleClick"
589
+ ```
590
+
591
+ ---
592
+
593
+ ## 🚀 Production Deployment
594
+
595
+ ### Build for Production
596
+
597
+ ```bash
598
+ npm run build
599
+ ```
600
+
601
+ ### Laravel Deployment
602
+
603
+ 1. Set environment variables:
604
+ ```env
605
+ VITE_ONAIROS_TEST_MODE=false
606
+ VITE_ONAIROS_API_KEY=your_production_key
607
+ ```
608
+
609
+ 2. Optimize assets:
610
+ ```bash
611
+ php artisan optimize
612
+ php artisan view:cache
613
+ ```
614
+
615
+ 3. Configure CDN (optional):
616
+ ```env
617
+ ASSET_URL=https://your-cdn.com
618
+ ```
619
+
620
+ ---
621
+
622
+ ## 📖 Examples
623
+
624
+ Check the `examples/` directory for complete working examples:
625
+
626
+ - `examples/blade-basic/` - Simple Blade integration
627
+ - `examples/vue-advanced/` - Vue.js with advanced features
628
+ - `examples/react-spa/` - React single-page application
629
+ - `examples/mixed-approach/` - Combining Blade + Vue
630
+
631
+ ---
632
+
633
+ ## 🤝 Support
634
+
635
+ - **Documentation**: [Onairos Docs](https://onairos.uk/docs)
636
+ - **GitHub Issues**: [Report Issues](https://github.com/zd819/onairos-npm/issues)
637
+ - **Discord**: [Join Community](https://discord.gg/onairos)
638
+
639
+ ---
640
+
641
+ ## 📝 License
642
+
643
+ MIT License - see LICENSE file for details.