@gameap/debug 0.2.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/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # GameAP Plugin Debug Harness
2
+
3
+ A full-fledged development environment for debugging GameAP frontend plugins. This harness runs the **real GameAP frontend** with **Mock Service Worker (MSW)** providing realistic API responses.
4
+
5
+ ## Features
6
+
7
+ - **Real Frontend**: Uses the actual GameAP frontend application, not a simplified mock
8
+ - **MSW Mock API**: All API endpoints are mocked with realistic data using Mock Service Worker
9
+ - **Debug Panel**: Floating panel to switch user types, adjust network delays, and change locales
10
+ - **Plugin Hot Reload**: Changes to your plugin source are reflected after rebuild
11
+ - **File Manager Testing**: Full file manager with mock file system
12
+ - **Server Management**: Mock servers with console, RCON, and file access
13
+ - **Authentication Testing**: Switch between admin, regular user, and guest modes
14
+
15
+ ## Quick Start
16
+
17
+ ### Prerequisites
18
+
19
+ 1. Install dependencies from the frontend root:
20
+ ```bash
21
+ cd /path/to/gameap-api/web/frontend
22
+ npm install
23
+ ```
24
+
25
+ 2. Initialize MSW service worker:
26
+ ```bash
27
+ cd packages/gameap-debug
28
+ npm run msw:init
29
+ ```
30
+
31
+ ### Running the Debug Harness
32
+
33
+ ```bash
34
+ # From the gameap-debug directory
35
+ cd packages/gameap-debug
36
+
37
+ # Run with default plugin (hex-editor-plugin)
38
+ npm run dev
39
+
40
+ # Or run with a custom plugin path
41
+ PLUGIN_PATH=/path/to/my-plugin/frontend/dist npm run dev
42
+ ```
43
+
44
+ The debug harness will start at `http://localhost:5174`
45
+
46
+ ### Testing Your Plugin
47
+
48
+ 1. **Build your plugin first:**
49
+ ```bash
50
+ cd /path/to/my-plugin/frontend
51
+ npm run build
52
+ ```
53
+
54
+ 2. **Run the debug harness with your plugin:**
55
+ ```bash
56
+ PLUGIN_PATH=/path/to/my-plugin/frontend/dist npm run dev
57
+ ```
58
+
59
+ ## Environment Variables
60
+
61
+ | Variable | Description | Default |
62
+ |----------|-------------|---------|
63
+ | `PLUGIN_PATH` | Path to your plugin's dist directory (built bundle) | hex-editor-plugin dist |
64
+ | `LOCALE` | Default locale (en/ru) | `en` |
65
+
66
+ ## Debug Panel
67
+
68
+ The debug panel appears in the bottom-right corner and allows you to:
69
+
70
+ - **User Type**: Switch between Admin, Regular User, and Guest (unauthenticated)
71
+ - **Network Delay**: Adjust API response delay (useful for testing loading states)
72
+ - **Locale**: Switch between English and Russian
73
+
74
+ Changes to user type require a page reload to take effect.
75
+
76
+ ## Mock Data
77
+
78
+ ### Servers
79
+
80
+ | ID | Name | Game | Port | Status |
81
+ |----|------|------|------|--------|
82
+ | 1 | Minecraft Survival | minecraft | 25565 | Running |
83
+ | 2 | CS2 Competitive | cs2 | 27015 | Stopped |
84
+
85
+ ### Users
86
+
87
+ | Type | Login | Access |
88
+ |------|-------|--------|
89
+ | Admin | admin | Full administrative access |
90
+ | User | player1 | Regular user permissions |
91
+ | Guest | - | Not authenticated |
92
+
93
+ ### Mock Files
94
+
95
+ | Path | Type | Description |
96
+ |------|------|-------------|
97
+ | `/server.properties` | text | Minecraft server config |
98
+ | `/cstrike/server.cfg` | text | CS server config |
99
+ | `/config/config.json` | text | JSON config file |
100
+ | `/readme.txt` | text | Plain text file |
101
+ | `/data/sample.dat` | binary | 256 bytes (0x00-0xFF) |
102
+ | `/data/complex.bin` | binary | 1KB with header pattern |
103
+
104
+ ## API Mocking
105
+
106
+ All GameAP API endpoints are mocked using MSW:
107
+
108
+ ### Available Endpoints
109
+
110
+ - **Auth**: `/api/profile`, `/api/user/servers_abilities`
111
+ - **Servers**: `/api/servers`, `/api/servers/:id`, `/api/servers/:id/abilities`
112
+ - **Server Control**: `/api/servers/:id/start|stop|restart`
113
+ - **Console**: `/api/servers/:id/console`
114
+ - **RCON**: `/api/servers/:id/rcon/*`
115
+ - **File Manager**: `/api/servers/:id/filemanager/*`
116
+ - **Games**: `/api/games`, `/api/game_mods`
117
+ - **Nodes**: `/api/dedicated_servers`
118
+ - **Users**: `/api/users`
119
+ - **Tasks**: `/api/gdaemon_tasks`
120
+ - **Plugins**: `/plugins.js`, `/plugins.css`
121
+
122
+ ### Customizing Mock Responses
123
+
124
+ You can customize mock behavior by modifying `src/mocks/handlers.ts`:
125
+
126
+ ```typescript
127
+ import { debugState } from './mocks/handlers'
128
+
129
+ // Change network delay
130
+ debugState.networkDelay = 500 // 500ms delay
131
+
132
+ // Change user type
133
+ debugState.userType = 'guest'
134
+
135
+ // Change locale
136
+ debugState.locale = 'ru'
137
+ ```
138
+
139
+ ## Plugin Development Workflow
140
+
141
+ 1. **Create your plugin** using the Plugin SDK
142
+ 2. **Build your plugin**: `npm run build`
143
+ 3. **Run the debug harness**: `PLUGIN_PATH=./dist npm run dev`
144
+ 4. **Make changes** to your plugin
145
+ 5. **Rebuild**: `npm run build`
146
+ 6. **Refresh** the debug harness page
147
+
148
+ ### Hot Reload Setup (Optional)
149
+
150
+ Add a watch script to your plugin's package.json:
151
+
152
+ ```json
153
+ {
154
+ "scripts": {
155
+ "dev:watch": "vite build --watch",
156
+ "debug": "PLUGIN_PATH=./dist vite --config ../../gameap-api/web/frontend/packages/gameap-debug/vite.config.ts"
157
+ }
158
+ }
159
+ ```
160
+
161
+ Run both in separate terminals:
162
+ ```bash
163
+ # Terminal 1: Watch plugin source
164
+ npm run dev:watch
165
+
166
+ # Terminal 2: Run debug harness
167
+ npm run debug
168
+ ```
169
+
170
+ ## Architecture
171
+
172
+ ```
173
+ packages/gameap-debug/
174
+ ├── src/
175
+ │ ├── main.ts # Entry point - initializes MSW, loads real app
176
+ │ └── mocks/
177
+ │ ├── browser.ts # MSW browser setup
178
+ │ ├── handlers.ts # API mock handlers
179
+ │ ├── files.ts # Mock file system data
180
+ │ ├── servers.ts # Mock server data
181
+ │ └── users.ts # Mock user data
182
+ ├── index.html # Debug harness HTML
183
+ ├── vite.config.ts # Vite config with aliases
184
+ └── package.json
185
+ ```
186
+
187
+ ## Troubleshooting
188
+
189
+ ### "Failed to load plugin bundle"
190
+
191
+ - Ensure your plugin is built (`npm run build`)
192
+ - Check that `PLUGIN_PATH` points to the `dist` directory
193
+ - Verify the plugin exports a valid `PluginDefinition`
194
+
195
+ ### MSW not intercepting requests
196
+
197
+ - Run `npm run msw:init` to create the service worker file
198
+ - Check browser console for MSW initialization messages
199
+ - Ensure requests go to the same origin (no CORS issues)
200
+
201
+ ### Plugin context hooks not working
202
+
203
+ The harness provides the same injection keys as the main app:
204
+ - `pluginContext` for `usePluginContext()`, `useServer()`, etc.
205
+ - `pluginI18n` for `usePluginTrans()`
206
+
207
+ ### Styles not loading
208
+
209
+ - Ensure your plugin CSS is exported as `style.css` in the dist folder
210
+ - Check browser console for CSS loading errors
211
+
212
+ ## Global Debug API
213
+
214
+ Access debug utilities from the browser console:
215
+
216
+ ```javascript
217
+ // Update debug state
218
+ window.gameapDebug.updateDebugState({ userType: 'guest' })
219
+
220
+ // Load new plugin content
221
+ window.gameapDebug.loadPlugin(jsContent, cssContent)
222
+ ```
@@ -0,0 +1,7 @@
1
+ // Empty plugin placeholder
2
+ // This file is used when no PLUGIN_PATH is specified
3
+ export const emptyPlugin = {
4
+ id: 'empty',
5
+ name: 'No Plugin Loaded',
6
+ version: '0.0.0',
7
+ }
package/index.html ADDED
@@ -0,0 +1,111 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>GameAP - Debug Mode</title>
7
+ <script>
8
+ // Load theme from localStorage and apply it immediately
9
+ (function() {
10
+ let theme = 'light';
11
+ try {
12
+ const settings = localStorage.getItem('gameap_ui_settings');
13
+ if (settings) {
14
+ const parsed = JSON.parse(settings);
15
+ theme = parsed.theme || 'light';
16
+ } else {
17
+ const oldTheme = localStorage.getItem('gameap_theme');
18
+ if (oldTheme) {
19
+ theme = oldTheme;
20
+ localStorage.setItem('gameap_ui_settings', JSON.stringify({ theme: oldTheme }));
21
+ localStorage.removeItem('gameap_theme');
22
+ }
23
+ }
24
+ } catch (e) {
25
+ console.error('Failed to load theme from localStorage:', e);
26
+ }
27
+ document.documentElement.classList.add(theme);
28
+ })();
29
+
30
+ // Initialize language detection
31
+ (function() {
32
+ function detectLanguage() {
33
+ try {
34
+ const settings = localStorage.getItem('gameap_ui_settings');
35
+ if (settings) {
36
+ const parsed = JSON.parse(settings);
37
+ if (parsed.language) {
38
+ return parsed.language;
39
+ }
40
+ } else {
41
+ const oldLang = localStorage.getItem('gameap_lang');
42
+ if (oldLang) {
43
+ return oldLang;
44
+ }
45
+ }
46
+ } catch (e) {
47
+ console.error('Failed to load language from localStorage:', e);
48
+ }
49
+
50
+ const browserLang = navigator.language || navigator.userLanguage;
51
+ if (browserLang) {
52
+ return browserLang.split('-')[0].toLowerCase();
53
+ }
54
+
55
+ const htmlLang = document.documentElement.lang;
56
+ if (htmlLang) {
57
+ return htmlLang;
58
+ }
59
+
60
+ return 'en';
61
+ }
62
+
63
+ const lang = detectLanguage();
64
+ const supportedLangs = ['en', 'ru'];
65
+ const finalLang = supportedLangs.includes(lang) ? lang : 'en';
66
+
67
+ document.documentElement.lang = finalLang;
68
+ window.gameapLang = finalLang;
69
+
70
+ // For debug mode, translations will be loaded via MSW mock
71
+ // Initialize with empty object, will be populated after MSW starts
72
+ window.i18n = {};
73
+
74
+ // Debug mode flag
75
+ window.gameapDebugMode = true;
76
+ })();
77
+ </script>
78
+ </head>
79
+ <body class="bg-white dark:bg-stone-800">
80
+ <div id="app">
81
+ <!-- Loading indicator while debug harness initializes -->
82
+ <div id="debug-loader" style="
83
+ display: flex;
84
+ flex-direction: column;
85
+ align-items: center;
86
+ justify-content: center;
87
+ height: 100vh;
88
+ font-family: system-ui, sans-serif;
89
+ color: #64748b;
90
+ ">
91
+ <div style="
92
+ width: 40px;
93
+ height: 40px;
94
+ border: 3px solid #e2e8f0;
95
+ border-top-color: #4f46e5;
96
+ border-radius: 50%;
97
+ animation: spin 1s linear infinite;
98
+ "></div>
99
+ <p style="margin-top: 16px; font-size: 14px;">Initializing Debug Harness...</p>
100
+ <p style="margin-top: 4px; font-size: 12px; opacity: 0.7;">Starting Mock Service Worker</p>
101
+ </div>
102
+ <style>
103
+ @keyframes spin {
104
+ to { transform: rotate(360deg); }
105
+ }
106
+ </style>
107
+ </div>
108
+ <!-- Debug harness entry point - loads MSW first, then the real app -->
109
+ <script type="module" src="/src/main.ts"></script>
110
+ </body>
111
+ </html>
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@gameap/debug",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "Debug harness for GameAP plugin development with mock API",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vue-tsc && vite build",
9
+ "preview": "vite preview",
10
+ "msw:init": "npx msw init ../../public --save",
11
+ "sync:translations": "cp ../../../internal/i18n/en.json src/mocks/translations-en.json && cp ../../../internal/i18n/ru.json src/mocks/translations-ru.json"
12
+ },
13
+ "dependencies": {
14
+ "@gameap/plugin-sdk": "^0.2.0",
15
+ "@gameap/frontend": "file:../gameap-frontend",
16
+ "msw": "^2.7.0"
17
+ },
18
+ "devDependencies": {
19
+ "@originjs/vite-plugin-commonjs": "^1.0.3",
20
+ "@vitejs/plugin-vue": "^6.0.1",
21
+ "sass": "^1.32.0",
22
+ "typescript": "^5.3.0",
23
+ "vite": "^7.1.0",
24
+ "vue-tsc": "^2.2.10"
25
+ },
26
+ "peerDependencies": {
27
+ "vue": "^3.5.0",
28
+ "vue-router": "^4.6.0",
29
+ "pinia": "^3.0.0",
30
+ "naive-ui": "^2.43.0",
31
+ "axios": "^1.12.0"
32
+ },
33
+ "msw": {
34
+ "workerDirectory": [
35
+ "../../public"
36
+ ]
37
+ }
38
+ }
@@ -0,0 +1,12 @@
1
+ const tailwindcss = require('tailwindcss');
2
+ const postcssPresetEnv = require('postcss-preset-env');
3
+ const path = require('path');
4
+
5
+ module.exports = {
6
+ plugins: [
7
+ postcssPresetEnv,
8
+ tailwindcss({
9
+ config: path.resolve(__dirname, 'tailwind.config.js'),
10
+ }),
11
+ ],
12
+ };