onairos 2.2.1 → 2.3.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/LARAVEL_INTEGRATION_GUIDE.md +643 -0
- package/LARAVEL_TECHNICAL_EXPLANATION.md +465 -0
- package/README.md +122 -43
- package/dist/onairos-laravel.js +2 -0
- package/dist/onairos-laravel.js.map +1 -0
- package/laravel.txt +430 -0
- package/package.json +31 -2
- package/src/laravel/OnairosVue.vue +398 -0
- package/src/laravel/blade-helpers.js +263 -0
- package/src/laravel/vite-plugin.js +179 -0
- package/tests/laravel/examples/blade-example.test.js +283 -0
- package/tests/laravel/laravel-integration.test.js +647 -0
- package/tests/laravel/setup.js +84 -0
- package/tests/laravel/vitest.config.js +20 -0
- package/webpack.config.js +46 -13
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onairos-laravel.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,iBAAkB,GAAIH,GACH,iBAAZC,QACdA,QAAwB,eAAID,IAE5BD,EAAqB,eAAIC,GAC1B,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,wmCCSvD,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webpack/bootstrap","webpack://OnairosLaravel/webpack/runtime/define property getters","webpack://OnairosLaravel/webpack/runtime/hasOwnProperty shorthand","webpack://OnairosLaravel/webpack/runtime/make namespace object","webpack://OnairosLaravel/./src/laravel/blade-helpers.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"OnairosLaravel\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"OnairosLaravel\"] = factory();\n\telse\n\t\troot[\"OnairosLaravel\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\r\n * Onairos Laravel Blade Integration Helpers\r\n * \r\n * This file provides utilities for integrating Onairos components\r\n * directly in PHP Blade templates without requiring React setup.\r\n */\r\n\r\n// Global Onairos instance for Blade templates\r\nlet onairosInstance = null;\r\n\r\n/**\r\n * Initialize Onairos for Blade template usage\r\n * @param {Object} config - Global configuration\r\n */\r\nexport function initializeOnairosForBlade(config = {}) {\r\n const defaultConfig = {\r\n apiKey: null,\r\n baseUrl: 'https://api2.onairos.uk',\r\n testMode: false,\r\n autoDetectMobile: true,\r\n globalStyles: true\r\n };\r\n\r\n window.OnairosConfig = { ...defaultConfig, ...config };\r\n \r\n // Inject global styles if enabled\r\n if (window.OnairosConfig.globalStyles) {\r\n injectOnairosStyles();\r\n }\r\n\r\n // Initialize mobile detection\r\n window.OnairosUtils = {\r\n isMobile: detectMobileDevice(),\r\n detectMobile: detectMobileDevice\r\n };\r\n\r\n console.log('🔥 Onairos initialized for Laravel Blade templates');\r\n}\r\n\r\n/**\r\n * Create an Onairos button element that can be used in Blade templates\r\n * @param {string} targetElementId - ID of the element to mount to\r\n * @param {Object} options - Onairos button options\r\n */\r\nexport function createOnairosButton(targetElementId, options = {}) {\r\n const element = document.getElementById(targetElementId);\r\n if (!element) {\r\n console.error(`❌ Element with ID \"${targetElementId}\" not found`);\r\n return;\r\n }\r\n\r\n const defaultOptions = {\r\n requestData: ['email', 'profile'],\r\n webpageName: 'Laravel App',\r\n testMode: window.OnairosConfig?.testMode || false,\r\n autoFetch: true,\r\n buttonType: 'pill',\r\n textColor: 'black'\r\n };\r\n\r\n const config = { ...defaultOptions, ...options };\r\n\r\n // Create button HTML\r\n element.innerHTML = `\r\n <div class=\"onairos-button-container\">\r\n <button \r\n id=\"${targetElementId}-btn\" \r\n class=\"onairos-btn onairos-btn-${config.buttonType}\"\r\n data-onairos-config='${JSON.stringify(config)}'\r\n >\r\n <span class=\"onairos-btn-text\" style=\"color: ${config.textColor}\">\r\n Connect with Onairos\r\n </span>\r\n <span class=\"onairos-btn-loading\" style=\"display: none;\">\r\n Loading...\r\n </span>\r\n </button>\r\n </div>\r\n `;\r\n\r\n // Add event listener\r\n const button = document.getElementById(`${targetElementId}-btn`);\r\n button.addEventListener('click', () => handleOnairosButtonClick(config));\r\n}\r\n\r\n/**\r\n * Handle Onairos button click in Blade context\r\n * @param {Object} config - Button configuration\r\n */\r\nfunction handleOnairosButtonClick(config) {\r\n // For Blade templates, we'll use the popup/iframe approach\r\n if (window.OnairosUtils.isMobile) {\r\n handleMobileFlow(config);\r\n } else {\r\n handleDesktopFlow(config);\r\n }\r\n}\r\n\r\n/**\r\n * Handle mobile OAuth flow (redirect-based)\r\n * @param {Object} config - Configuration\r\n */\r\nfunction handleMobileFlow(config) {\r\n const authUrl = buildAuthUrl(config);\r\n window.location.href = authUrl;\r\n}\r\n\r\n/**\r\n * Handle desktop OAuth flow (popup-based)\r\n * @param {Object} config - Configuration\r\n */\r\nfunction handleDesktopFlow(config) {\r\n const authUrl = buildAuthUrl(config);\r\n \r\n const popup = window.open(\r\n authUrl,\r\n 'onairosAuth',\r\n 'width=450,height=700,scrollbars=yes,resizable=yes'\r\n );\r\n\r\n if (popup) {\r\n const checkClosed = setInterval(() => {\r\n if (popup.closed) {\r\n clearInterval(checkClosed);\r\n handleAuthComplete(config);\r\n }\r\n }, 1000);\r\n }\r\n}\r\n\r\n/**\r\n * Build authentication URL for OAuth flow\r\n * @param {Object} config - Configuration\r\n * @returns {string} Auth URL\r\n */\r\nfunction buildAuthUrl(config) {\r\n const baseUrl = window.OnairosConfig.baseUrl;\r\n const params = new URLSearchParams({\r\n webpageName: config.webpageName,\r\n requestData: JSON.stringify(config.requestData),\r\n testMode: config.testMode,\r\n returnUrl: window.location.href\r\n });\r\n \r\n return `${baseUrl}/auth/laravel?${params.toString()}`;\r\n}\r\n\r\n/**\r\n * Handle authentication completion\r\n * @param {Object} config - Configuration\r\n */\r\nfunction handleAuthComplete(config) {\r\n if (config.onComplete && typeof config.onComplete === 'function') {\r\n config.onComplete({\r\n success: true,\r\n timestamp: new Date().toISOString()\r\n });\r\n }\r\n \r\n // Trigger custom event for Laravel apps to listen to\r\n const event = new CustomEvent('onairosAuthComplete', {\r\n detail: { config, success: true }\r\n });\r\n window.dispatchEvent(event);\r\n}\r\n\r\n/**\r\n * Detect if device is mobile\r\n * @returns {boolean}\r\n */\r\nfunction detectMobileDevice() {\r\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ||\r\n (window.innerWidth <= 768);\r\n}\r\n\r\n/**\r\n * Inject Onairos styles into the page\r\n */\r\nfunction injectOnairosStyles() {\r\n if (document.getElementById('onairos-styles')) return;\r\n\r\n const styles = `\r\n <style id=\"onairos-styles\">\r\n .onairos-button-container {\r\n display: inline-block;\r\n margin: 10px 0;\r\n }\r\n \r\n .onairos-btn {\r\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\r\n border: none;\r\n border-radius: 25px;\r\n padding: 12px 24px;\r\n color: white;\r\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\r\n font-size: 14px;\r\n font-weight: 600;\r\n cursor: pointer;\r\n transition: all 0.3s ease;\r\n box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);\r\n }\r\n \r\n .onairos-btn:hover {\r\n transform: translateY(-2px);\r\n box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);\r\n }\r\n \r\n .onairos-btn-pill {\r\n border-radius: 25px;\r\n }\r\n \r\n .onairos-btn-icon {\r\n border-radius: 50%;\r\n width: 45px;\r\n height: 45px;\r\n padding: 0;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n }\r\n \r\n .onairos-btn-loading {\r\n color: #888;\r\n }\r\n \r\n @media (max-width: 768px) {\r\n .onairos-btn {\r\n width: 100%;\r\n padding: 15px 20px;\r\n font-size: 16px;\r\n }\r\n }\r\n </style>\r\n `;\r\n \r\n document.head.insertAdjacentHTML('beforeend', styles);\r\n}\r\n\r\n/**\r\n * Laravel Blade template directive helper\r\n * Usage in Blade: @onairos(['requestData' => ['email'], 'webpageName' => 'My App'])\r\n */\r\nexport function renderOnairosDirective(options = {}) {\r\n const elementId = `onairos-${Math.random().toString(36).substr(2, 9)}`;\r\n \r\n return `\r\n <div id=\"${elementId}\"></div>\r\n <script>\r\n document.addEventListener('DOMContentLoaded', function() {\r\n if (window.createOnairosButton) {\r\n window.createOnairosButton('${elementId}', ${JSON.stringify(options)});\r\n }\r\n });\r\n </script>\r\n `;\r\n}\r\n\r\n// Expose functions globally for Blade template access\r\nif (typeof window !== 'undefined') {\r\n window.initializeOnairosForBlade = initializeOnairosForBlade;\r\n window.createOnairosButton = createOnairosButton;\r\n window.renderOnairosDirective = renderOnairosDirective;\r\n} "],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","initializeOnairosForBlade","config","arguments","length","undefined","window","OnairosConfig","_objectSpread","apiKey","baseUrl","testMode","autoDetectMobile","globalStyles","document","getElementById","styles","head","insertAdjacentHTML","injectOnairosStyles","OnairosUtils","isMobile","detectMobileDevice","detectMobile","console","log","createOnairosButton","targetElementId","_window$OnairosConfig","options","element","error","concat","requestData","webpageName","autoFetch","buttonType","textColor","innerHTML","JSON","stringify","addEventListener","authUrl","buildAuthUrl","location","href","handleMobileFlow","popup","open","checkClosed","setInterval","closed","clearInterval","onComplete","success","timestamp","Date","toISOString","event","CustomEvent","detail","dispatchEvent","handleAuthComplete","handleDesktopFlow","handleOnairosButtonClick","params","URLSearchParams","returnUrl","toString","test","navigator","userAgent","innerWidth","renderOnairosDirective","elementId","Math","random","substr"],"sourceRoot":""}
|
package/laravel.txt
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
# Onairos NPM Package - Laravel Integration Context
|
|
2
|
+
|
|
3
|
+
## Laravel Integration Overview
|
|
4
|
+
- **Package Version**: 2.2.1+
|
|
5
|
+
- **Laravel Support**: Laravel 9+ with Vite
|
|
6
|
+
- **Integration Types**: Blade Templates, Vue.js, React, Mixed Approaches
|
|
7
|
+
- **Build System**: Vite with custom plugins
|
|
8
|
+
- **Mobile Support**: Auto-detection with responsive OAuth flows
|
|
9
|
+
|
|
10
|
+
## Key Laravel-Specific Features ✅
|
|
11
|
+
1. **Blade Template Integration**: Direct PHP template support without React setup
|
|
12
|
+
2. **Vite Plugin System**: Custom plugins for Laravel, Vue, and React optimization
|
|
13
|
+
3. **Multi-Framework Support**: Seamless Vue.js and React integration within Laravel
|
|
14
|
+
4. **Mobile-First Design**: Automatic mobile detection with appropriate OAuth flows
|
|
15
|
+
5. **Laravel Backend Integration**: PHP controllers and route handlers
|
|
16
|
+
6. **Production Optimization**: Laravel-specific build and deployment strategies
|
|
17
|
+
|
|
18
|
+
## Laravel Integration Architecture ✅
|
|
19
|
+
|
|
20
|
+
### Entry Points
|
|
21
|
+
- **Main Package**: `onairos` (standard React components)
|
|
22
|
+
- **Laravel Blade**: `onairos/blade` (vanilla JS helpers)
|
|
23
|
+
- **Vite Plugin**: `onairos/vite-plugin` (build-time optimization)
|
|
24
|
+
- **Vue Component**: `onairos/src/laravel/OnairosVue.vue` (Vue 3 SFC)
|
|
25
|
+
|
|
26
|
+
### Build Targets
|
|
27
|
+
- **UMD Bundle**: `dist/onairos.bundle.js` (browser globals)
|
|
28
|
+
- **ES Module**: `dist/onairos.esm.js` (modern imports)
|
|
29
|
+
- **Laravel Specific**: `dist/onairos-laravel.js` (Blade helpers)
|
|
30
|
+
|
|
31
|
+
## Integration Approaches ✅
|
|
32
|
+
|
|
33
|
+
### 1. Blade Templates (PHP-Focused)
|
|
34
|
+
**Use Case**: Traditional Laravel apps with minimal JavaScript
|
|
35
|
+
**Technology Stack**: PHP Blade + Vanilla JS + Tailwind CSS
|
|
36
|
+
|
|
37
|
+
**Implementation**:
|
|
38
|
+
```javascript
|
|
39
|
+
// Vite plugin handles build-time optimization
|
|
40
|
+
onairosLaravelPlugin({
|
|
41
|
+
bladeSupport: true, // Watch .blade.php files
|
|
42
|
+
injectGlobals: true, // Auto-inject helpers
|
|
43
|
+
optimizeDeps: true, // Optimize for Laravel
|
|
44
|
+
enableHMR: true // Hot module replacement
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Runtime Flow**:
|
|
49
|
+
1. `initializeOnairosForBlade()` sets up global configuration
|
|
50
|
+
2. `createOnairosButton()` generates DOM elements with event handlers
|
|
51
|
+
3. Mobile detection switches between popup/redirect OAuth flows
|
|
52
|
+
4. Custom events communicate with Laravel backend
|
|
53
|
+
|
|
54
|
+
### 2. Vue.js Integration
|
|
55
|
+
**Use Case**: Laravel apps using Vue.js as primary frontend
|
|
56
|
+
**Technology Stack**: PHP Blade + Vue 3 + Composition API + Vite
|
|
57
|
+
|
|
58
|
+
**Implementation**:
|
|
59
|
+
```javascript
|
|
60
|
+
// Specialized Vue plugin with auto-imports
|
|
61
|
+
onairosVuePlugin({
|
|
62
|
+
autoImport: true, // Auto-import OnairosButton in .vue files
|
|
63
|
+
optimizeDeps: true // Optimize Vue + Onairos dependencies
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Component Architecture**:
|
|
68
|
+
- **OnairosVue.vue**: Complete Vue 3 component with Composition API
|
|
69
|
+
- **Props System**: Vue-style props with validation and defaults
|
|
70
|
+
- **Event System**: Vue custom events (@complete, @error, @loading)
|
|
71
|
+
- **Reactive State**: Vue reactivity for loading, success, error states
|
|
72
|
+
|
|
73
|
+
### 3. React Integration
|
|
74
|
+
**Use Case**: Laravel apps using React as primary frontend
|
|
75
|
+
**Technology Stack**: PHP Blade + React 18 + JSX + Vite
|
|
76
|
+
|
|
77
|
+
**Implementation**:
|
|
78
|
+
```javascript
|
|
79
|
+
// React-specific optimizations
|
|
80
|
+
onairosReactPlugin({
|
|
81
|
+
autoImport: true, // Auto-import in .jsx/.tsx files
|
|
82
|
+
optimizeDeps: true // Optimize React + Onairos bundle
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Integration Pattern**:
|
|
87
|
+
- Uses existing `OnairosButton` React component
|
|
88
|
+
- Laravel Vite plugin handles React-specific builds
|
|
89
|
+
- Automatic JSX transformation and optimization
|
|
90
|
+
|
|
91
|
+
## Technical Implementation Details ✅
|
|
92
|
+
|
|
93
|
+
### Vite Plugin System
|
|
94
|
+
**Core Plugin**: `onairosLaravelPlugin()`
|
|
95
|
+
- **Development**: Injects initialization scripts, enables HMR
|
|
96
|
+
- **Production**: Optimizes bundles, handles asset generation
|
|
97
|
+
- **File Watching**: Watches .blade.php files for changes
|
|
98
|
+
- **Dependency Optimization**: Pre-bundles Onairos for faster dev server
|
|
99
|
+
|
|
100
|
+
**Specialized Plugins**:
|
|
101
|
+
- `onairosVuePlugin()`: Vue-specific optimizations and auto-imports
|
|
102
|
+
- `onairosReactPlugin()`: React-specific optimizations and auto-imports
|
|
103
|
+
|
|
104
|
+
### Mobile Detection & OAuth Flow
|
|
105
|
+
```javascript
|
|
106
|
+
// Automatic mobile detection
|
|
107
|
+
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || (window.innerWidth <= 768);
|
|
108
|
+
|
|
109
|
+
// OAuth flow selection
|
|
110
|
+
if (isMobile) {
|
|
111
|
+
// Redirect-based flow for mobile browsers
|
|
112
|
+
window.location.href = authUrl;
|
|
113
|
+
} else {
|
|
114
|
+
// Popup-based flow for desktop
|
|
115
|
+
window.open(authUrl, 'onairosAuth', 'width=450,height=700');
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Laravel Backend Integration
|
|
120
|
+
```php
|
|
121
|
+
// Example Laravel controller
|
|
122
|
+
class OnairosController extends Controller {
|
|
123
|
+
public function callback(Request $request) {
|
|
124
|
+
$data = $request->validate([
|
|
125
|
+
'user_hash' => 'required|string',
|
|
126
|
+
'connections' => 'required|array',
|
|
127
|
+
'data_types' => 'required|array'
|
|
128
|
+
]);
|
|
129
|
+
|
|
130
|
+
auth()->user()->update([
|
|
131
|
+
'onairos_hash' => $data['user_hash'],
|
|
132
|
+
'onairos_connections' => $data['connections']
|
|
133
|
+
]);
|
|
134
|
+
|
|
135
|
+
return response()->json(['success' => true]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Differences from Standard Integration ✅
|
|
141
|
+
|
|
142
|
+
### 1. Build System Integration
|
|
143
|
+
**Standard**: Uses webpack UMD build for browser globals
|
|
144
|
+
**Laravel**: Custom Vite plugins with Laravel-specific optimizations
|
|
145
|
+
|
|
146
|
+
### 2. Component Rendering
|
|
147
|
+
**Standard**: React components mounted via ReactDOM
|
|
148
|
+
**Laravel Blade**: Vanilla JS functions that generate DOM elements
|
|
149
|
+
**Laravel Vue**: Native Vue 3 single-file components
|
|
150
|
+
**Laravel React**: React components optimized for Laravel Vite
|
|
151
|
+
|
|
152
|
+
### 3. State Management
|
|
153
|
+
**Standard**: React state hooks and context
|
|
154
|
+
**Laravel Blade**: Global window objects and DOM manipulation
|
|
155
|
+
**Laravel Vue**: Vue 3 Composition API with reactive refs
|
|
156
|
+
**Laravel React**: React hooks within Laravel ecosystem
|
|
157
|
+
|
|
158
|
+
### 4. OAuth Flow Handling
|
|
159
|
+
**Standard**: Hardcoded popup approach
|
|
160
|
+
**Laravel**: Environment-aware with automatic mobile detection
|
|
161
|
+
- Desktop: Popup windows
|
|
162
|
+
- Mobile: Redirect-based flow with return URL handling
|
|
163
|
+
|
|
164
|
+
### 5. Styling Integration
|
|
165
|
+
**Standard**: Inline styles and CSS-in-JS
|
|
166
|
+
**Laravel**:
|
|
167
|
+
- Tailwind CSS integration out of the box
|
|
168
|
+
- Scoped Vue styles for Vue components
|
|
169
|
+
- Laravel Mix/Vite asset compilation
|
|
170
|
+
- Global CSS injection for Blade templates
|
|
171
|
+
|
|
172
|
+
### 6. Development Experience
|
|
173
|
+
**Standard**: Create React App or manual webpack setup
|
|
174
|
+
**Laravel**:
|
|
175
|
+
- Vite HMR with Blade file watching
|
|
176
|
+
- Automatic dependency optimization
|
|
177
|
+
- Laravel-specific error handling and debugging
|
|
178
|
+
- Integration with Laravel development tools
|
|
179
|
+
|
|
180
|
+
## Package Structure Changes ✅
|
|
181
|
+
|
|
182
|
+
### New Files Added
|
|
183
|
+
```
|
|
184
|
+
src/laravel/
|
|
185
|
+
├── blade-helpers.js # Vanilla JS helpers for Blade templates
|
|
186
|
+
├── vite-plugin.js # Custom Vite plugins for Laravel
|
|
187
|
+
└── OnairosVue.vue # Vue 3 component for Laravel
|
|
188
|
+
|
|
189
|
+
LARAVEL_INTEGRATION_GUIDE.md # Comprehensive integration guide
|
|
190
|
+
laravel.txt # This context file
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Package.json Exports
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"exports": {
|
|
197
|
+
".": {
|
|
198
|
+
"import": "./dist/onairos.esm.js",
|
|
199
|
+
"require": "./dist/onairos.bundle.js",
|
|
200
|
+
"browser": "./dist/onairos.bundle.js"
|
|
201
|
+
},
|
|
202
|
+
"./laravel": {
|
|
203
|
+
"import": "./dist/onairos.laravel.js",
|
|
204
|
+
"require": "./dist/onairos.laravel.js"
|
|
205
|
+
},
|
|
206
|
+
"./blade": "./src/laravel/blade-helpers.js",
|
|
207
|
+
"./vite-plugin": "./src/laravel/vite-plugin.js"
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Webpack Configuration
|
|
213
|
+
```javascript
|
|
214
|
+
// Laravel-specific build target
|
|
215
|
+
{
|
|
216
|
+
entry: {
|
|
217
|
+
'onairos-laravel': path.resolve(__dirname, 'src', 'laravel', 'blade-helpers.js')
|
|
218
|
+
},
|
|
219
|
+
output: {
|
|
220
|
+
filename: '[name].js',
|
|
221
|
+
libraryTarget: 'umd',
|
|
222
|
+
library: 'OnairosLaravel'
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Developer Experience Improvements ✅
|
|
228
|
+
|
|
229
|
+
### 1. Installation Simplicity
|
|
230
|
+
```bash
|
|
231
|
+
# Single package for all Laravel integration types
|
|
232
|
+
npm install onairos
|
|
233
|
+
|
|
234
|
+
# Optional: Framework-specific plugins
|
|
235
|
+
npm install --save-dev @vitejs/plugin-vue # For Vue
|
|
236
|
+
npm install --save-dev @vitejs/plugin-react # For React
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### 2. Configuration Patterns
|
|
240
|
+
**Blade Only**:
|
|
241
|
+
```javascript
|
|
242
|
+
// Minimal setup
|
|
243
|
+
onairosLaravelPlugin({ bladeSupport: true })
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Vue Integration**:
|
|
247
|
+
```javascript
|
|
248
|
+
// Vue + Laravel optimization
|
|
249
|
+
plugins: [laravel(), vue(), onairosVuePlugin()]
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**React Integration**:
|
|
253
|
+
```javascript
|
|
254
|
+
// React + Laravel optimization
|
|
255
|
+
plugins: [laravel(), react(), onairosReactPlugin()]
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### 3. Environment Configuration
|
|
259
|
+
```env
|
|
260
|
+
# Laravel .env integration
|
|
261
|
+
VITE_ONAIROS_API_KEY=your_api_key
|
|
262
|
+
VITE_ONAIROS_TEST_MODE=true
|
|
263
|
+
VITE_ONAIROS_BASE_URL=https://api2.onairos.uk
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### 4. Debug and Development
|
|
267
|
+
```javascript
|
|
268
|
+
// Enhanced debugging for Laravel
|
|
269
|
+
initializeOnairosForBlade({
|
|
270
|
+
debug: true, // Enable console logging
|
|
271
|
+
testMode: import.meta.env.DEV, // Auto-detect dev environment
|
|
272
|
+
autoDetectMobile: true // Mobile detection logging
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Production Deployment ✅
|
|
277
|
+
|
|
278
|
+
### 1. Build Process
|
|
279
|
+
```bash
|
|
280
|
+
# Laravel standard build
|
|
281
|
+
npm run build
|
|
282
|
+
|
|
283
|
+
# Generates optimized bundles:
|
|
284
|
+
# - dist/onairos.bundle.js (UMD)
|
|
285
|
+
# - dist/onairos.esm.js (ES modules)
|
|
286
|
+
# - dist/onairos-laravel.js (Laravel-specific)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### 2. Laravel Optimization
|
|
290
|
+
```php
|
|
291
|
+
// Laravel production commands
|
|
292
|
+
php artisan optimize # Route/config caching
|
|
293
|
+
php artisan view:cache # Blade template caching
|
|
294
|
+
php artisan config:cache # Environment caching
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### 3. CDN Integration
|
|
298
|
+
```env
|
|
299
|
+
# Laravel asset CDN
|
|
300
|
+
ASSET_URL=https://your-cdn.com
|
|
301
|
+
|
|
302
|
+
# Automatic asset URL prefixing
|
|
303
|
+
# https://your-cdn.com/build/assets/onairos-laravel.abc123.js
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Testing Strategy ✅
|
|
307
|
+
|
|
308
|
+
### 1. Unit Tests
|
|
309
|
+
- Laravel Blade helpers functionality
|
|
310
|
+
- Vue component props and events
|
|
311
|
+
- Vite plugin configuration
|
|
312
|
+
- Mobile detection logic
|
|
313
|
+
|
|
314
|
+
### 2. Integration Tests
|
|
315
|
+
- Laravel controller callbacks
|
|
316
|
+
- OAuth flow completion
|
|
317
|
+
- Database integration
|
|
318
|
+
- Environment variable handling
|
|
319
|
+
|
|
320
|
+
### 3. End-to-End Tests
|
|
321
|
+
- Full Laravel application flows
|
|
322
|
+
- Mobile and desktop OAuth
|
|
323
|
+
- Vue/React component integration
|
|
324
|
+
- Production build verification
|
|
325
|
+
|
|
326
|
+
## Known Laravel-Specific Considerations ✅
|
|
327
|
+
|
|
328
|
+
### 1. CSRF Protection
|
|
329
|
+
Laravel CSRF tokens are automatically handled in AJAX requests when using Laravel's default Axios configuration.
|
|
330
|
+
|
|
331
|
+
### 2. Route Caching
|
|
332
|
+
OAuth callback routes must be registered before route caching in production.
|
|
333
|
+
|
|
334
|
+
### 3. Session Management
|
|
335
|
+
Laravel sessions are used for OAuth state management alongside Onairos user hashes.
|
|
336
|
+
|
|
337
|
+
### 4. Middleware Integration
|
|
338
|
+
Custom Laravel middleware can be created to handle Onairos authentication states.
|
|
339
|
+
|
|
340
|
+
### 5. Queue Integration
|
|
341
|
+
Heavy OAuth processing can be queued using Laravel's queue system for better performance.
|
|
342
|
+
|
|
343
|
+
## Migration from Standard Integration ✅
|
|
344
|
+
|
|
345
|
+
### For Existing React Users
|
|
346
|
+
- No changes needed to existing React components
|
|
347
|
+
- Optional: Add Laravel Vite plugin for optimization
|
|
348
|
+
- Optional: Use Laravel backend integration features
|
|
349
|
+
|
|
350
|
+
### For New Laravel Projects
|
|
351
|
+
- Choose integration approach (Blade/Vue/React)
|
|
352
|
+
- Install appropriate Vite plugins
|
|
353
|
+
- Follow Laravel-specific setup guide
|
|
354
|
+
- Configure environment variables
|
|
355
|
+
|
|
356
|
+
### For Hybrid Approaches
|
|
357
|
+
- Mix Blade templates with Vue/React components
|
|
358
|
+
- Use different integration methods in different parts of the app
|
|
359
|
+
- Leverage Laravel's flexibility for gradual adoption
|
|
360
|
+
|
|
361
|
+
## Performance Considerations ✅
|
|
362
|
+
|
|
363
|
+
### 1. Bundle Size Optimization
|
|
364
|
+
- Vite plugins optimize bundle splitting
|
|
365
|
+
- Laravel-specific builds exclude unnecessary dependencies
|
|
366
|
+
- Tree-shaking removes unused code
|
|
367
|
+
|
|
368
|
+
### 2. Loading Performance
|
|
369
|
+
- Lazy loading for Vue/React components
|
|
370
|
+
- Preloading critical OAuth dependencies
|
|
371
|
+
- Service worker integration for offline capability
|
|
372
|
+
|
|
373
|
+
### 3. Mobile Performance
|
|
374
|
+
- Automatic redirect vs popup optimization
|
|
375
|
+
- Touch-friendly UI components
|
|
376
|
+
- Reduced JavaScript payload for mobile
|
|
377
|
+
|
|
378
|
+
## Troubleshooting Guide ✅
|
|
379
|
+
|
|
380
|
+
### Common Issues
|
|
381
|
+
|
|
382
|
+
1. **Vite Plugin Not Working**
|
|
383
|
+
- Clear Vite cache: `rm -rf node_modules/.vite`
|
|
384
|
+
- Check plugin order in vite.config.js
|
|
385
|
+
- Verify import paths
|
|
386
|
+
|
|
387
|
+
2. **Blade Helpers Unavailable**
|
|
388
|
+
- Ensure `initializeOnairosForBlade()` is called
|
|
389
|
+
- Check browser console for initialization errors
|
|
390
|
+
- Verify script loading order
|
|
391
|
+
|
|
392
|
+
3. **Vue Component Not Rendering**
|
|
393
|
+
- Confirm Vue 3 is properly installed
|
|
394
|
+
- Check component registration
|
|
395
|
+
- Verify Vite Vue plugin configuration
|
|
396
|
+
|
|
397
|
+
4. **Mobile OAuth Issues**
|
|
398
|
+
- Test popup blockers disabled
|
|
399
|
+
- Verify redirect URLs are whitelisted
|
|
400
|
+
- Check mobile user agent detection
|
|
401
|
+
|
|
402
|
+
### Debug Commands
|
|
403
|
+
```javascript
|
|
404
|
+
// Check initialization status
|
|
405
|
+
console.log(typeof window.createOnairosButton); // Should be "function"
|
|
406
|
+
console.log(typeof window.OnairosConfig); // Should be "object"
|
|
407
|
+
|
|
408
|
+
// Test mobile detection
|
|
409
|
+
console.log(window.OnairosUtils.isMobile); // Boolean
|
|
410
|
+
|
|
411
|
+
// Verify Vite environment
|
|
412
|
+
console.log(import.meta.env.DEV); // Development mode
|
|
413
|
+
console.log(import.meta.env.VITE_ONAIROS_*); // Environment variables
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## Future Laravel Enhancements 🚀
|
|
417
|
+
|
|
418
|
+
### Planned Features
|
|
419
|
+
1. **Artisan Commands**: CLI commands for setup and configuration
|
|
420
|
+
2. **Laravel Packages**: Composer package for PHP-side integration
|
|
421
|
+
3. **Blade Directives**: Custom `@onairos` Blade directive
|
|
422
|
+
4. **Middleware Package**: Pre-built authentication middleware
|
|
423
|
+
5. **Model Traits**: Eloquent traits for user Onairos data
|
|
424
|
+
6. **Testing Helpers**: Laravel testing utilities for Onairos
|
|
425
|
+
|
|
426
|
+
### Experimental Features
|
|
427
|
+
1. **Server-Side Rendering**: Laravel + Inertia.js SSR support
|
|
428
|
+
2. **API Resource Integration**: Laravel API resource transformers
|
|
429
|
+
3. **Livewire Components**: Native Livewire component integration
|
|
430
|
+
4. **Laravel Sail**: Docker development environment support
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onairos",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@react-oauth/google": "^0.12.1",
|
|
6
6
|
"@telegram-apps/sdk-react": "^2.0.25",
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"copy-assets": "echo 'Assets copied by webpack'",
|
|
25
25
|
"dev": "webpack --mode development --watch",
|
|
26
26
|
"test": "react-scripts test",
|
|
27
|
+
"test:laravel": "vitest run --config tests/laravel/vitest.config.js",
|
|
28
|
+
"test:laravel:watch": "vitest --config tests/laravel/vitest.config.js",
|
|
29
|
+
"test:laravel:ui": "vitest --ui --config tests/laravel/vitest.config.js",
|
|
30
|
+
"test:all": "npm run test && npm run test:laravel",
|
|
27
31
|
"eject": "react-scripts eject"
|
|
28
32
|
},
|
|
29
33
|
"eslintConfig": {
|
|
@@ -60,6 +64,8 @@
|
|
|
60
64
|
"@rollup/plugin-json": "^6.1.0",
|
|
61
65
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
62
66
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
67
|
+
"@vitejs/plugin-vue": "^5.0.4",
|
|
68
|
+
"@vue/test-utils": "^2.4.4",
|
|
63
69
|
"assert": "^2.1.0",
|
|
64
70
|
"babel-loader": "^9.2.1",
|
|
65
71
|
"browserify-zlib": "^0.2.0",
|
|
@@ -68,6 +74,7 @@
|
|
|
68
74
|
"file-loader": "^6.2.0",
|
|
69
75
|
"html-webpack-plugin": "^5.6.3",
|
|
70
76
|
"https-browserify": "^1.0.0",
|
|
77
|
+
"jsdom": "^24.0.0",
|
|
71
78
|
"lucide-react": "^0.503.0",
|
|
72
79
|
"os-browserify": "^0.3.0",
|
|
73
80
|
"path-browserify": "^1.0.1",
|
|
@@ -78,7 +85,9 @@
|
|
|
78
85
|
"tailwindcss": "^3.3.5",
|
|
79
86
|
"terser-webpack-plugin": "^5.3.10",
|
|
80
87
|
"url": "^0.11.4",
|
|
88
|
+
"vitest": "^1.2.0",
|
|
81
89
|
"vm-browserify": "^1.1.2",
|
|
90
|
+
"vue": "^3.4.15",
|
|
82
91
|
"webpack": "^5.89.0",
|
|
83
92
|
"webpack-bundle-analyzer": "^4.10.1",
|
|
84
93
|
"webpack-cli": "^5.1.4"
|
|
@@ -96,6 +105,20 @@
|
|
|
96
105
|
"types": "onairos.d.ts",
|
|
97
106
|
"browser": "dist/onairos.bundle.js",
|
|
98
107
|
"react-native": "dist/onairos.native.js",
|
|
108
|
+
"laravel": "dist/onairos.laravel.js",
|
|
109
|
+
"exports": {
|
|
110
|
+
".": {
|
|
111
|
+
"import": "./dist/onairos.esm.js",
|
|
112
|
+
"require": "./dist/onairos.bundle.js",
|
|
113
|
+
"browser": "./dist/onairos.bundle.js"
|
|
114
|
+
},
|
|
115
|
+
"./laravel": {
|
|
116
|
+
"import": "./dist/onairos.laravel.js",
|
|
117
|
+
"require": "./dist/onairos.laravel.js"
|
|
118
|
+
},
|
|
119
|
+
"./blade": "./src/laravel/blade-helpers.js",
|
|
120
|
+
"./vite-plugin": "./src/laravel/vite-plugin.js"
|
|
121
|
+
},
|
|
99
122
|
"repository": {
|
|
100
123
|
"type": "git",
|
|
101
124
|
"url": "git+https://github.com/zd819/onairos-npm"
|
|
@@ -105,7 +128,13 @@
|
|
|
105
128
|
"Identity",
|
|
106
129
|
"Authentication",
|
|
107
130
|
"Data-Sharing",
|
|
108
|
-
"Privacy"
|
|
131
|
+
"Privacy",
|
|
132
|
+
"Laravel",
|
|
133
|
+
"Vite",
|
|
134
|
+
"Blade",
|
|
135
|
+
"Vue",
|
|
136
|
+
"React",
|
|
137
|
+
"PHP"
|
|
109
138
|
],
|
|
110
139
|
"author": "Zion Darko",
|
|
111
140
|
"license": "Apache-2.0",
|