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,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
@@ -1,164 +1,197 @@
1
- const path = require('path');
2
- const TerserPlugin = require('terser-webpack-plugin');
3
- const HtmlWebpackPlugin = require('html-webpack-plugin');
4
- const CopyWebpackPlugin = require('copy-webpack-plugin');
5
-
6
- const baseConfig = {
7
- externals: {
8
- react: {
9
- commonjs: 'react',
10
- commonjs2: 'react',
11
- amd: 'React',
12
- root: 'React'
13
- },
14
- 'react-dom': {
15
- commonjs: 'react-dom',
16
- commonjs2: 'react-dom',
17
- amd: 'ReactDOM',
18
- root: 'ReactDOM'
19
- },
20
- 'ajv': 'ajv',
21
- 'ajv/dist/runtime/validation_error': 'ajv/dist/runtime/validation_error',
22
- 'ajv/dist/runtime/equal': 'ajv/dist/runtime/equal',
23
- 'ajv/dist/runtime/ucs2length': 'ajv/dist/runtime/ucs2length',
24
- 'ajv/dist/runtime/uri': 'ajv/dist/runtime/uri',
25
- '@anthropic-ai/sdk': '@anthropic-ai/sdk',
26
- '@google/generative-ai': '@google/generative-ai',
27
- '@pinecone-database/pinecone': '@pinecone-database/pinecone',
28
- 'openai': 'openai'
29
- },
30
- optimization: {
31
- minimize: true,
32
- minimizer: [
33
- new TerserPlugin({
34
- terserOptions: {
35
- compress: {
36
- dead_code: true,
37
- },
38
- mangle: true,
39
- output: {
40
- comments: false,
41
- },
42
- },
43
- extractComments: false,
44
- }),
45
- ],
46
- },
47
- devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
48
- module: {
49
- rules: [
50
- {
51
- test: /\.jsx?$/,
52
- exclude: /node_modules/,
53
- use: {
54
- loader: 'babel-loader',
55
- options: {
56
- presets: ['@babel/preset-env', '@babel/preset-react']
57
- }
58
- }
59
- },
60
- {
61
- test: /\.(png|jpg|gif|svg)$/i,
62
- type: 'asset/resource',
63
- generator: {
64
- filename: 'static/[hash][ext][query]'
65
- }
66
- }
67
- ]
68
- },
69
- resolve: {
70
- extensions: ['.js', '.jsx', '.mjs'],
71
- alias: {
72
- '@': path.resolve(__dirname, 'src'),
73
- },
74
- fallback: {
75
- "crypto": require.resolve("crypto-browserify"),
76
- "stream": require.resolve("stream-browserify"),
77
- "assert": require.resolve("assert"),
78
- "http": require.resolve("stream-http"),
79
- "https": require.resolve("https-browserify"),
80
- "os": require.resolve("os-browserify/browser"),
81
- "url": require.resolve("url"),
82
- "zlib": require.resolve("browserify-zlib"),
83
- "path": require.resolve("path-browserify"),
84
- "vm": require.resolve("vm-browserify"),
85
- "fs": false,
86
- "net": false,
87
- "tls": false,
88
- "child_process": false
89
- }
90
- }
91
- };
92
-
93
- module.exports = [
94
- // UMD build for browsers
95
- {
96
- ...baseConfig,
97
- entry: {
98
- onairos: path.resolve(__dirname, 'src', 'onairos.jsx'),
99
- iframe: path.resolve(__dirname, 'src', 'iframe', 'data_request_page.js')
100
- },
101
- output: {
102
- path: path.resolve(__dirname, 'dist'),
103
- filename: (pathData) => {
104
- return pathData.chunk.name === 'onairos' ? 'onairos.bundle.js' : '[name].bundle.js';
105
- },
106
- libraryTarget: 'umd',
107
- library: 'Onairos',
108
- globalObject: 'this',
109
- umdNamedDefine: true,
110
- publicPath: 'auto',
111
- },
112
- plugins: [
113
- new HtmlWebpackPlugin({
114
- template: path.resolve(__dirname, 'src', 'iframe', 'data_request_iframe.html'),
115
- filename: 'data_request_iframe.html',
116
- chunks: ['iframe'],
117
- inject: true
118
- }),
119
- new CopyWebpackPlugin({
120
- patterns: [
121
- {
122
- from: path.resolve(__dirname, 'public', 'data_request_popup.html'),
123
- to: path.resolve(__dirname, 'dist', 'data_request_popup.html')
124
- },
125
- {
126
- from: path.resolve(__dirname, 'public', 'oauth-callback.html'),
127
- to: path.resolve(__dirname, 'dist', 'oauth-callback.html')
128
- }
129
- ]
130
- })
131
- ]
132
- },
133
- // ESM build
134
- {
135
- ...baseConfig,
136
- entry: path.resolve(__dirname, 'src', 'onairos.jsx'),
137
- experiments: {
138
- outputModule: true
139
- },
140
- output: {
141
- path: path.resolve(__dirname, 'dist'),
142
- filename: 'onairos.esm.js',
143
- library: {
144
- type: 'module'
145
- },
146
- environment: {
147
- module: true
148
- }
149
- },
150
- externals: {
151
- react: 'react',
152
- 'react-dom': 'react-dom',
153
- 'ajv': 'ajv',
154
- 'ajv/dist/runtime/validation_error': 'ajv/dist/runtime/validation_error',
155
- 'ajv/dist/runtime/equal': 'ajv/dist/runtime/equal',
156
- 'ajv/dist/runtime/ucs2length': 'ajv/dist/runtime/ucs2length',
157
- 'ajv/dist/runtime/uri': 'ajv/dist/runtime/uri',
158
- '@anthropic-ai/sdk': '@anthropic-ai/sdk',
159
- '@google/generative-ai': '@google/generative-ai',
160
- '@pinecone-database/pinecone': '@pinecone-database/pinecone',
161
- 'openai': 'openai'
162
- }
163
- }
1
+ const path = require('path');
2
+ const TerserPlugin = require('terser-webpack-plugin');
3
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
4
+ const CopyWebpackPlugin = require('copy-webpack-plugin');
5
+
6
+ const baseConfig = {
7
+ externals: {
8
+ react: {
9
+ commonjs: 'react',
10
+ commonjs2: 'react',
11
+ amd: 'React',
12
+ root: 'React'
13
+ },
14
+ 'react-dom': {
15
+ commonjs: 'react-dom',
16
+ commonjs2: 'react-dom',
17
+ amd: 'ReactDOM',
18
+ root: 'ReactDOM'
19
+ },
20
+ 'ajv': 'ajv',
21
+ 'ajv/dist/runtime/validation_error': 'ajv/dist/runtime/validation_error',
22
+ 'ajv/dist/runtime/equal': 'ajv/dist/runtime/equal',
23
+ 'ajv/dist/runtime/ucs2length': 'ajv/dist/runtime/ucs2length',
24
+ 'ajv/dist/runtime/uri': 'ajv/dist/runtime/uri',
25
+ '@anthropic-ai/sdk': '@anthropic-ai/sdk',
26
+ '@google/generative-ai': '@google/generative-ai',
27
+ '@pinecone-database/pinecone': '@pinecone-database/pinecone',
28
+ 'openai': 'openai'
29
+ },
30
+ optimization: {
31
+ minimize: true,
32
+ minimizer: [
33
+ new TerserPlugin({
34
+ terserOptions: {
35
+ compress: {
36
+ dead_code: true,
37
+ },
38
+ mangle: true,
39
+ output: {
40
+ comments: false,
41
+ },
42
+ },
43
+ extractComments: false,
44
+ }),
45
+ ],
46
+ },
47
+ devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
48
+ module: {
49
+ rules: [
50
+ {
51
+ test: /\.jsx?$/,
52
+ exclude: /node_modules/,
53
+ use: {
54
+ loader: 'babel-loader',
55
+ options: {
56
+ presets: ['@babel/preset-env', '@babel/preset-react']
57
+ }
58
+ }
59
+ },
60
+ {
61
+ test: /\.(png|jpg|gif|svg)$/i,
62
+ type: 'asset/resource',
63
+ generator: {
64
+ filename: 'static/[hash][ext][query]'
65
+ }
66
+ }
67
+ ]
68
+ },
69
+ resolve: {
70
+ extensions: ['.js', '.jsx', '.mjs'],
71
+ alias: {
72
+ '@': path.resolve(__dirname, 'src'),
73
+ },
74
+ fallback: {
75
+ "crypto": require.resolve("crypto-browserify"),
76
+ "stream": require.resolve("stream-browserify"),
77
+ "assert": require.resolve("assert"),
78
+ "http": require.resolve("stream-http"),
79
+ "https": require.resolve("https-browserify"),
80
+ "os": require.resolve("os-browserify/browser"),
81
+ "url": require.resolve("url"),
82
+ "zlib": require.resolve("browserify-zlib"),
83
+ "path": require.resolve("path-browserify"),
84
+ "vm": require.resolve("vm-browserify"),
85
+ "fs": false,
86
+ "net": false,
87
+ "tls": false,
88
+ "child_process": false
89
+ }
90
+ }
91
+ };
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
+
108
+ module.exports = [
109
+ // UMD build for browsers
110
+ {
111
+ ...baseConfig,
112
+ entry: {
113
+ onairos: path.resolve(__dirname, 'src', 'onairos.jsx'),
114
+ iframe: path.resolve(__dirname, 'src', 'iframe', 'data_request_page.js')
115
+ },
116
+ output: {
117
+ path: path.resolve(__dirname, 'dist'),
118
+ filename: (pathData) => {
119
+ return pathData.chunk.name === 'onairos' ? 'onairos.bundle.js' : '[name].bundle.js';
120
+ },
121
+ libraryTarget: 'umd',
122
+ library: 'Onairos',
123
+ globalObject: 'this',
124
+ umdNamedDefine: true,
125
+ publicPath: 'auto',
126
+ },
127
+ plugins: [
128
+ new HtmlWebpackPlugin({
129
+ template: path.resolve(__dirname, 'src', 'iframe', 'data_request_iframe.html'),
130
+ filename: 'data_request_iframe.html',
131
+ chunks: ['iframe'],
132
+ inject: true
133
+ }),
134
+ new CopyWebpackPlugin({
135
+ patterns: [
136
+ {
137
+ from: path.resolve(__dirname, 'public', 'data_request_popup.html'),
138
+ to: path.resolve(__dirname, 'dist', 'data_request_popup.html')
139
+ },
140
+ {
141
+ from: path.resolve(__dirname, 'public', 'oauth-callback.html'),
142
+ to: path.resolve(__dirname, 'dist', 'oauth-callback.html')
143
+ }
144
+ ]
145
+ })
146
+ ]
147
+ },
148
+
149
+ // Laravel-specific build
150
+ {
151
+ ...baseConfig,
152
+ entry: {
153
+ 'onairos-laravel': path.resolve(__dirname, 'src', 'laravel', 'blade-helpers.js')
154
+ },
155
+ output: {
156
+ path: path.resolve(__dirname, 'dist'),
157
+ filename: '[name].js',
158
+ libraryTarget: 'umd',
159
+ library: 'OnairosLaravel',
160
+ globalObject: 'this',
161
+ umdNamedDefine: true,
162
+ },
163
+ externals: {
164
+ // Laravel build shouldn't externalize React since blade-helpers.js doesn't use React
165
+ 'ajv': 'ajv',
166
+ 'ajv/dist/runtime/validation_error': 'ajv/dist/runtime/validation_error',
167
+ 'ajv/dist/runtime/equal': 'ajv/dist/runtime/equal',
168
+ 'ajv/dist/runtime/ucs2length': 'ajv/dist/runtime/ucs2length',
169
+ 'ajv/dist/runtime/uri': 'ajv/dist/runtime/uri',
170
+ '@anthropic-ai/sdk': '@anthropic-ai/sdk',
171
+ '@google/generative-ai': '@google/generative-ai',
172
+ '@pinecone-database/pinecone': '@pinecone-database/pinecone',
173
+ 'openai': 'openai'
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'
196
+ }
164
197
  ];