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.
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Laravel Integration Test Setup
3
+ *
4
+ * Sets up the testing environment for Laravel-specific functionality
5
+ */
6
+
7
+ import { vi } from 'vitest';
8
+
9
+ // Mock import.meta.env for Laravel Vite environment
10
+ global.import = {
11
+ meta: {
12
+ env: {
13
+ DEV: true,
14
+ PROD: false,
15
+ VITE_ONAIROS_API_KEY: 'test-api-key',
16
+ VITE_ONAIROS_TEST_MODE: 'true',
17
+ VITE_ONAIROS_BASE_URL: 'https://api2.onairos.uk'
18
+ }
19
+ }
20
+ };
21
+
22
+ // Mock window.open for OAuth popup tests
23
+ global.window.open = vi.fn(() => ({
24
+ closed: false,
25
+ close: vi.fn(),
26
+ location: { href: '' }
27
+ }));
28
+
29
+ // Mock fetch for API calls
30
+ global.fetch = vi.fn(() =>
31
+ Promise.resolve({
32
+ ok: true,
33
+ json: () => Promise.resolve({ success: true })
34
+ })
35
+ );
36
+
37
+ // Mock performance API
38
+ global.performance = {
39
+ now: vi.fn(() => Date.now())
40
+ };
41
+
42
+ // Mock localStorage
43
+ const localStorageMock = {
44
+ getItem: vi.fn(),
45
+ setItem: vi.fn(),
46
+ removeItem: vi.fn(),
47
+ clear: vi.fn()
48
+ };
49
+ global.localStorage = localStorageMock;
50
+
51
+ // Set up default viewport dimensions
52
+ Object.defineProperty(window, 'innerWidth', {
53
+ writable: true,
54
+ configurable: true,
55
+ value: 1024
56
+ });
57
+
58
+ Object.defineProperty(window, 'innerHeight', {
59
+ writable: true,
60
+ configurable: true,
61
+ value: 768
62
+ });
63
+
64
+ // Mock user agent for desktop by default
65
+ Object.defineProperty(window.navigator, 'userAgent', {
66
+ writable: true,
67
+ configurable: true,
68
+ value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
69
+ });
70
+
71
+ // Clean up after each test
72
+ afterEach(() => {
73
+ // Reset DOM
74
+ document.body.innerHTML = '';
75
+
76
+ // Clear all mocks
77
+ vi.clearAllMocks();
78
+
79
+ // Reset window properties
80
+ delete window.OnairosConfig;
81
+ delete window.OnairosUtils;
82
+ delete window.createOnairosButton;
83
+ delete window.initializeOnairosForBlade;
84
+ });
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import vue from '@vitejs/plugin-vue';
3
+ import { resolve } from 'path';
4
+
5
+ export default defineConfig({
6
+ plugins: [vue()],
7
+ test: {
8
+ environment: 'jsdom',
9
+ globals: true,
10
+ setupFiles: ['./setup.js']
11
+ },
12
+ resolve: {
13
+ alias: {
14
+ '@': resolve(__dirname, '../../src'),
15
+ 'onairos': resolve(__dirname, '../../src/index.js'),
16
+ 'onairos/blade': resolve(__dirname, '../../src/laravel/blade-helpers.js'),
17
+ 'onairos/vite-plugin': resolve(__dirname, '../../src/laravel/vite-plugin.js')
18
+ }
19
+ }
20
+ });
package/webpack.config.js CHANGED
@@ -90,6 +90,21 @@ const baseConfig = {
90
90
  }
91
91
  };
92
92
 
93
+ // ES Module specific externals configuration
94
+ const esmExternals = {
95
+ react: 'react',
96
+ 'react-dom': 'react-dom',
97
+ 'ajv': 'ajv',
98
+ 'ajv/dist/runtime/validation_error': 'ajv/dist/runtime/validation_error',
99
+ 'ajv/dist/runtime/equal': 'ajv/dist/runtime/equal',
100
+ 'ajv/dist/runtime/ucs2length': 'ajv/dist/runtime/ucs2length',
101
+ 'ajv/dist/runtime/uri': 'ajv/dist/runtime/uri',
102
+ '@anthropic-ai/sdk': '@anthropic-ai/sdk',
103
+ '@google/generative-ai': '@google/generative-ai',
104
+ '@pinecone-database/pinecone': '@pinecone-database/pinecone',
105
+ 'openai': 'openai'
106
+ };
107
+
93
108
  module.exports = [
94
109
  // UMD build for browsers
95
110
  {
@@ -130,26 +145,23 @@ module.exports = [
130
145
  })
131
146
  ]
132
147
  },
133
- // ESM build
148
+
149
+ // Laravel-specific build
134
150
  {
135
151
  ...baseConfig,
136
- entry: path.resolve(__dirname, 'src', 'onairos.jsx'),
137
- experiments: {
138
- outputModule: true
152
+ entry: {
153
+ 'onairos-laravel': path.resolve(__dirname, 'src', 'laravel', 'blade-helpers.js')
139
154
  },
140
155
  output: {
141
156
  path: path.resolve(__dirname, 'dist'),
142
- filename: 'onairos.esm.js',
143
- library: {
144
- type: 'module'
145
- },
146
- environment: {
147
- module: true
148
- }
157
+ filename: '[name].js',
158
+ libraryTarget: 'umd',
159
+ library: 'OnairosLaravel',
160
+ globalObject: 'this',
161
+ umdNamedDefine: true,
149
162
  },
150
163
  externals: {
151
- react: 'react',
152
- 'react-dom': 'react-dom',
164
+ // Laravel build shouldn't externalize React since blade-helpers.js doesn't use React
153
165
  'ajv': 'ajv',
154
166
  'ajv/dist/runtime/validation_error': 'ajv/dist/runtime/validation_error',
155
167
  'ajv/dist/runtime/equal': 'ajv/dist/runtime/equal',
@@ -160,5 +172,26 @@ module.exports = [
160
172
  '@pinecone-database/pinecone': '@pinecone-database/pinecone',
161
173
  'openai': 'openai'
162
174
  }
175
+ },
176
+
177
+ // ES Module build
178
+ {
179
+ ...baseConfig,
180
+ entry: path.resolve(__dirname, 'src', 'onairos.jsx'),
181
+ externals: esmExternals,
182
+ experiments: {
183
+ outputModule: true,
184
+ },
185
+ output: {
186
+ path: path.resolve(__dirname, 'dist'),
187
+ filename: 'onairos.esm.js',
188
+ library: {
189
+ type: 'module'
190
+ },
191
+ environment: {
192
+ module: true
193
+ }
194
+ },
195
+ target: 'es2020'
163
196
  }
164
197
  ];