claw-dashboard 2.1.0 → 2.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/docs/API.md +1 -2
  3. package/index.js +32 -42
  4. package/package.json +23 -12
  5. package/src/auto-save.js +11 -5
  6. package/src/cli/export-snapshot.js +3 -1
  7. package/src/cli/import-snapshot.js +3 -1
  8. package/src/config.js +9 -15
  9. package/src/errors.js +0 -9
  10. package/src/security.js +6 -2
  11. package/src/snapshot.js +73 -26
  12. package/src/web-server.js +7 -10
  13. package/src/widgets/builtin-widgets.js +0 -94
  14. package/src/widgets/index.js +0 -1
  15. package/.c8rc.json +0 -38
  16. package/.dockerignore +0 -68
  17. package/.github/dependabot.yml +0 -45
  18. package/.github/pull_request_template.md +0 -39
  19. package/.github/workflows/ci.yml +0 -147
  20. package/.github/workflows/release.yml +0 -40
  21. package/.github/workflows/security.yml +0 -84
  22. package/.husky/pre-commit +0 -1
  23. package/.planning/codebase/ARCHITECTURE.md +0 -206
  24. package/.planning/codebase/INTEGRATIONS.md +0 -150
  25. package/.planning/codebase/STACK.md +0 -122
  26. package/.planning/codebase/STRUCTURE.md +0 -201
  27. package/CONTRIBUTING.md +0 -378
  28. package/Dockerfile +0 -54
  29. package/FEATURES.md +0 -307
  30. package/TODO.md +0 -28
  31. package/ai.openclaw.dashboard.plist +0 -35
  32. package/build-cjs.js +0 -127
  33. package/cjs-shim.js +0 -13
  34. package/dist/clawdash +0 -1729
  35. package/dist/clawdash.meta.json +0 -2236
  36. package/dist/widgets.cjs +0 -6511
  37. package/docker-compose.yml +0 -67
  38. package/esbuild.config.js +0 -158
  39. package/eslint.config.js +0 -56
  40. package/examples/plugins/README.md +0 -122
  41. package/examples/plugins/api-status/index.js +0 -294
  42. package/examples/plugins/api-status/plugin.json +0 -19
  43. package/examples/plugins/hello-world/index.js +0 -104
  44. package/examples/plugins/hello-world/plugin.json +0 -15
  45. package/examples/plugins/system-metrics-chart/index.js +0 -339
  46. package/examples/plugins/system-metrics-chart/plugin.json +0 -18
  47. package/examples/plugins/weather-widget/index.js +0 -136
  48. package/examples/plugins/weather-widget/plugin.json +0 -19
  49. package/index.cjs +0 -23005
  50. package/jest.config.js +0 -11
  51. package/scripts/release.js +0 -595
  52. package/src/database.js +0 -734
  53. package/tests/alerts.test.js +0 -437
  54. package/tests/auto-save.test.js +0 -529
  55. package/tests/cache.test.js +0 -317
  56. package/tests/cli.test.js +0 -351
  57. package/tests/command-palette.test.js +0 -320
  58. package/tests/config-processor.test.js +0 -452
  59. package/tests/config-validator.test.js +0 -710
  60. package/tests/config-watcher.test.js +0 -594
  61. package/tests/config.test.js +0 -755
  62. package/tests/database.test.js +0 -438
  63. package/tests/errors.test.js +0 -189
  64. package/tests/example-plugins.test.js +0 -624
  65. package/tests/integration.test.js +0 -1321
  66. package/tests/loading-states.test.js +0 -300
  67. package/tests/manifest-validation-on-load.test.js +0 -671
  68. package/tests/performance-monitor.test.js +0 -190
  69. package/tests/plugin-api-rate-limit.test.js +0 -302
  70. package/tests/plugin-errors.test.js +0 -311
  71. package/tests/plugin-lifecycle-e2e.test.js +0 -1036
  72. package/tests/plugin-reload.test.js +0 -764
  73. package/tests/rate-limiter.test.js +0 -539
  74. package/tests/retry.test.js +0 -308
  75. package/tests/security.test.js +0 -411
  76. package/tests/settings-modal.test.js +0 -226
  77. package/tests/theme-selector.test.js +0 -57
  78. package/tests/utils.js +0 -242
  79. package/tests/utils.test.js +0 -317
  80. package/tests/validate-plugin-cli.test.js +0 -359
  81. package/tests/validation.test.js +0 -837
  82. package/tests/web-server.test.js +0 -646
  83. package/tests/widget-arrange-mode.test.js +0 -183
  84. package/tests/widget-config-hot-reload.test.js +0 -465
  85. package/tests/widget-dependency.test.js +0 -591
  86. package/tests/widget-error-boundary.test.js +0 -749
  87. package/tests/widget-error-isolation.test.js +0 -469
  88. package/tests/widget-integration.test.js +0 -1147
  89. package/tests/widget-refresh-intervals.test.js +0 -284
  90. package/tests/worker-pool.test.js +0 -522
@@ -1,452 +0,0 @@
1
- /**
2
- * Tests for config-processor module
3
- * Environment variable interpolation, versioning, and migration
4
- */
5
-
6
- import {
7
- interpolateEnvVars,
8
- processConfigValues,
9
- processWidgetConfig,
10
- validateConfigVersion,
11
- migrateConfig,
12
- registerMigration,
13
- compareVersions,
14
- extractEnvRequirements,
15
- createConfigPreprocessor,
16
- CONFIG_VERSION,
17
- DEFAULT_PROCESSING_OPTIONS,
18
- } from '../src/widgets/config-processor.js';
19
-
20
- describe('config-processor', () => {
21
- // Save original env
22
- const originalEnv = process.env;
23
-
24
- beforeEach(() => {
25
- // Reset process.env before each test
26
- process.env = { ...originalEnv };
27
- });
28
-
29
- afterAll(() => {
30
- process.env = originalEnv;
31
- });
32
-
33
- describe('interpolateEnvVars', () => {
34
- test('should return non-string values unchanged', () => {
35
- expect(interpolateEnvVars(123)).toBe(123);
36
- expect(interpolateEnvVars(true)).toBe(true);
37
- expect(interpolateEnvVars(null)).toBe(null);
38
- expect(interpolateEnvVars(undefined)).toBe(undefined);
39
- expect(interpolateEnvVars({ key: 'value' })).toEqual({ key: 'value' });
40
- expect(interpolateEnvVars([1, 2, 3])).toEqual([1, 2, 3]);
41
- });
42
-
43
- test('should interpolate simple environment variables', () => {
44
- process.env.TEST_VAR = 'test_value';
45
- expect(interpolateEnvVars('${TEST_VAR}')).toBe('test_value');
46
- });
47
-
48
- test('should interpolate env vars within text', () => {
49
- process.env.USER_NAME = 'Alice';
50
- expect(interpolateEnvVars('Hello, ${USER_NAME}!')).toBe('Hello, Alice!');
51
- });
52
-
53
- test('should use default value when env var is not set', () => {
54
- delete process.env.MISSING_VAR;
55
- expect(interpolateEnvVars('${MISSING_VAR:-default}')).toBe('default');
56
- });
57
-
58
- test('should prefer env var over default when set', () => {
59
- process.env.EXISTING_VAR = 'actual_value';
60
- expect(interpolateEnvVars('${EXISTING_VAR:-default}')).toBe('actual_value');
61
- });
62
-
63
- test('should keep original pattern when env var missing and no default', () => {
64
- delete process.env.MISSING_VAR;
65
- expect(interpolateEnvVars('${MISSING_VAR}')).toBe('${MISSING_VAR}');
66
- });
67
-
68
- test('should handle multiple interpolations', () => {
69
- process.env.HOST = 'localhost';
70
- process.env.PORT = '3000';
71
- expect(interpolateEnvVars('http://${HOST}:${PORT}')).toBe('http://localhost:3000');
72
- });
73
-
74
- test('should handle mixed interpolations with and without defaults', () => {
75
- process.env.API_KEY = 'secret123';
76
- expect(interpolateEnvVars('Key: ${API_KEY}, Timeout: ${TIMEOUT:-5000}')).toBe('Key: secret123, Timeout: 5000');
77
- });
78
-
79
- test('should handle empty default values', () => {
80
- delete process.env.EMPTY_VAR;
81
- expect(interpolateEnvVars('${EMPTY_VAR:-}')).toBe('');
82
- });
83
-
84
- test('should handle custom env object', () => {
85
- const customEnv = { CUSTOM_VAR: 'custom_value' };
86
- expect(interpolateEnvVars('${CUSTOM_VAR}', customEnv)).toBe('custom_value');
87
- });
88
-
89
- test('should handle special characters in values', () => {
90
- process.env.SPECIAL = 'hello@world.com/path?query=1&other=2';
91
- expect(interpolateEnvVars('${SPECIAL}')).toBe('hello@world.com/path?query=1&other=2');
92
- });
93
- });
94
-
95
- describe('processConfigValues', () => {
96
- test('should process simple string values', () => {
97
- process.env.API_URL = 'https://api.example.com';
98
- const config = { url: '${API_URL}' };
99
- expect(processConfigValues(config)).toEqual({ url: 'https://api.example.com' });
100
- });
101
-
102
- test('should process nested objects', () => {
103
- process.env.DB_HOST = 'localhost';
104
- process.env.DB_PORT = '5432';
105
- const config = {
106
- database: {
107
- host: '${DB_HOST}',
108
- port: '${DB_PORT}',
109
- },
110
- };
111
- expect(processConfigValues(config)).toEqual({
112
- database: {
113
- host: 'localhost',
114
- port: '5432',
115
- },
116
- });
117
- });
118
-
119
- test('should process arrays', () => {
120
- process.env.FIRST = 'one';
121
- process.env.SECOND = 'two';
122
- const config = ['${FIRST}', '${SECOND}', 'static'];
123
- expect(processConfigValues(config)).toEqual(['one', 'two', 'static']);
124
- });
125
-
126
- test('should handle mixed types in arrays', () => {
127
- process.env.STR = 'string';
128
- const config = ['${STR}', 123, true, null];
129
- expect(processConfigValues(config)).toEqual(['string', 123, true, null]);
130
- });
131
-
132
- test('should process complex nested structures', () => {
133
- process.env.API_KEY = 'key123';
134
- process.env.BASE_URL = 'https://api.test';
135
- const config = {
136
- api: {
137
- key: '${API_KEY}',
138
- endpoints: [
139
- '${BASE_URL}/users',
140
- '${BASE_URL}/posts',
141
- ],
142
- timeout: 5000,
143
- },
144
- };
145
- expect(processConfigValues(config)).toEqual({
146
- api: {
147
- key: 'key123',
148
- endpoints: ['https://api.test/users', 'https://api.test/posts'],
149
- timeout: 5000,
150
- },
151
- });
152
- });
153
-
154
- test('should handle null values', () => {
155
- const config = { value: null, nested: { empty: null } };
156
- expect(processConfigValues(config)).toEqual({ value: null, nested: { empty: null } });
157
- });
158
-
159
- test('should handle circular references gracefully', () => {
160
- const config = { a: 'value' };
161
- config.self = config;
162
- const result = processConfigValues(config);
163
- expect(result.a).toBe('value');
164
- expect(result.self).toBe(config); // Circular ref preserved as-is
165
- });
166
-
167
- test('should preserve non-plain objects', () => {
168
- const date = new Date('2024-01-01');
169
- const config = { date, regex: /test/g };
170
- const result = processConfigValues(config);
171
- expect(result.date).toBe(date);
172
- expect(result.regex).toEqual(/test/g);
173
- });
174
- });
175
-
176
- describe('compareVersions', () => {
177
- test('should return 0 for equal versions', () => {
178
- expect(compareVersions('1.0.0', '1.0.0')).toBe(0);
179
- expect(compareVersions('2.5.3', '2.5.3')).toBe(0);
180
- });
181
-
182
- test('should return -1 when first version is lower', () => {
183
- expect(compareVersions('1.0.0', '1.0.1')).toBe(-1);
184
- expect(compareVersions('1.0.0', '1.1.0')).toBe(-1);
185
- expect(compareVersions('1.0.0', '2.0.0')).toBe(-1);
186
- });
187
-
188
- test('should return 1 when first version is higher', () => {
189
- expect(compareVersions('1.0.1', '1.0.0')).toBe(1);
190
- expect(compareVersions('1.1.0', '1.0.0')).toBe(1);
191
- expect(compareVersions('2.0.0', '1.0.0')).toBe(1);
192
- });
193
-
194
- test('should handle different length versions', () => {
195
- expect(compareVersions('1.0', '1.0.0')).toBe(0);
196
- expect(compareVersions('1', '1.0.0')).toBe(0);
197
- });
198
-
199
- test('should handle versions with non-numeric parts', () => {
200
- // Non-numeric parts are treated as 0 in simple comparison
201
- expect(compareVersions('1.0.0-alpha', '1.0.0')).toBe(0); // both become 1.0.0
202
- expect(compareVersions('2.0.0-beta', '2.0.0')).toBe(0);
203
- });
204
- });
205
-
206
- describe('validateConfigVersion', () => {
207
- test('should validate current version', () => {
208
- const config = { __version: CONFIG_VERSION.CURRENT };
209
- const result = validateConfigVersion(config);
210
- expect(result.valid).toBe(true);
211
- expect(result.version).toBe(CONFIG_VERSION.CURRENT);
212
- });
213
-
214
- test('should validate minimum supported version', () => {
215
- const config = { __version: CONFIG_VERSION.MIN_SUPPORTED };
216
- const result = validateConfigVersion(config);
217
- expect(result.valid).toBe(true);
218
- });
219
-
220
- test('should reject versions below minimum', () => {
221
- const config = { __version: '0.9.0' };
222
- const result = validateConfigVersion(config);
223
- expect(result.valid).toBe(false);
224
- expect(result.error).toContain('below minimum supported');
225
- });
226
-
227
- test('should reject versions above current', () => {
228
- const config = { __version: '99.0.0' };
229
- const result = validateConfigVersion(config);
230
- expect(result.valid).toBe(false);
231
- expect(result.error).toContain('newer than current');
232
- });
233
-
234
- test('should treat missing version as 1.0.0', () => {
235
- const config = {};
236
- const result = validateConfigVersion(config);
237
- expect(result.valid).toBe(true);
238
- expect(result.version).toBe('1.0.0');
239
- });
240
-
241
- test('should handle null/undefined config', () => {
242
- expect(validateConfigVersion(null).valid).toBe(true);
243
- expect(validateConfigVersion(undefined).valid).toBe(true);
244
- });
245
- });
246
-
247
- describe('migrateConfig', () => {
248
- beforeEach(() => {
249
- // Clear any registered migrations
250
- // Note: We can't easily clear the Map, so we work with what we have
251
- });
252
-
253
- test('should return same config if version matches', () => {
254
- const config = { __version: '1.0.0', data: 'test' };
255
- const result = migrateConfig(config, '1.0.0');
256
- expect(result.success).toBe(true);
257
- expect(result.config).toEqual(config);
258
- expect(result.path).toEqual([]);
259
- });
260
-
261
- test('should return error for invalid config', () => {
262
- const result = migrateConfig(null);
263
- expect(result.success).toBe(false);
264
- expect(result.error).toContain('Invalid config');
265
- });
266
-
267
- test('should return error when no migration path exists', () => {
268
- const config = { __version: '0.1.0' };
269
- const result = migrateConfig(config, '2.0.0');
270
- expect(result.success).toBe(false);
271
- expect(result.error).toContain('No migration path');
272
- });
273
-
274
- test('should apply registered migration', () => {
275
- // Register a simple migration
276
- registerMigration('1.0.0', '1.1.0', (config) => ({
277
- ...config,
278
- newField: 'migrated',
279
- }));
280
-
281
- const config = { __version: '1.0.0', oldField: 'value' };
282
- const result = migrateConfig(config, '1.1.0');
283
-
284
- expect(result.success).toBe(true);
285
- expect(result.config.newField).toBe('migrated');
286
- expect(result.config.oldField).toBe('value');
287
- expect(result.config.__version).toBe('1.1.0');
288
- });
289
- });
290
-
291
- describe('extractEnvRequirements', () => {
292
- test('should extract simple env vars', () => {
293
- const config = { url: '${API_URL}' };
294
- const reqs = extractEnvRequirements(config);
295
- expect(reqs).toEqual([{ name: 'API_URL', hasDefault: false }]);
296
- });
297
-
298
- test('should extract env vars with defaults', () => {
299
- const config = { timeout: '${TIMEOUT:-5000}' };
300
- const reqs = extractEnvRequirements(config);
301
- expect(reqs).toEqual([{ name: 'TIMEOUT', hasDefault: true, defaultValue: '5000' }]);
302
- });
303
-
304
- test('should extract from nested objects', () => {
305
- const config = {
306
- db: { host: '${DB_HOST}', port: '${DB_PORT:-5432}' },
307
- };
308
- const reqs = extractEnvRequirements(config);
309
- expect(reqs).toHaveLength(2);
310
- expect(reqs).toContainEqual({ name: 'DB_HOST', hasDefault: false });
311
- expect(reqs).toContainEqual({ name: 'DB_PORT', hasDefault: true, defaultValue: '5432' });
312
- });
313
-
314
- test('should extract from arrays', () => {
315
- const config = ['${VAR1}', '${VAR2:-default}'];
316
- const reqs = extractEnvRequirements(config);
317
- expect(reqs).toHaveLength(2);
318
- });
319
-
320
- test('should deduplicate env vars', () => {
321
- const config = {
322
- a: '${SAME_VAR}',
323
- b: '${SAME_VAR}',
324
- };
325
- const reqs = extractEnvRequirements(config);
326
- expect(reqs).toHaveLength(1);
327
- });
328
-
329
- test('should handle complex nested structures', () => {
330
- const config = {
331
- api: {
332
- key: '${API_KEY}',
333
- endpoints: ['${BASE_URL}/users', '${BASE_URL}/posts'],
334
- },
335
- timeout: '${TIMEOUT:-30000}',
336
- };
337
- const reqs = extractEnvRequirements(config);
338
- expect(reqs).toHaveLength(3);
339
- expect(reqs).toContainEqual({ name: 'API_KEY', hasDefault: false });
340
- expect(reqs).toContainEqual({ name: 'BASE_URL', hasDefault: false });
341
- expect(reqs).toContainEqual({ name: 'TIMEOUT', hasDefault: true, defaultValue: '30000' });
342
- });
343
- });
344
-
345
- describe('createConfigPreprocessor', () => {
346
- test('should return a function', () => {
347
- const preprocessor = createConfigPreprocessor();
348
- expect(typeof preprocessor).toBe('function');
349
- });
350
-
351
- test('should process config when called', () => {
352
- process.env.PREPROCESS_TEST = 'success';
353
- const preprocessor = createConfigPreprocessor({ interpolateEnv: true });
354
- const result = preprocessor({ value: '${PREPROCESS_TEST}' });
355
- expect(result.success).toBe(true);
356
- expect(result.config.value).toBe('success');
357
- });
358
- });
359
-
360
- describe('processWidgetConfig', () => {
361
- test('should successfully process valid config', () => {
362
- process.env.PROCESS_TEST = 'processed';
363
- const config = {
364
- __version: '1.0.0',
365
- value: '${PROCESS_TEST}',
366
- };
367
- const result = processWidgetConfig(config);
368
- expect(result.success).toBe(true);
369
- expect(result.config.value).toBe('processed');
370
- });
371
-
372
- test('should return warnings for migrations', () => {
373
- // Register a migration first
374
- registerMigration('1.0.0', CONFIG_VERSION.CURRENT, (config) => ({
375
- ...config,
376
- migrated: true,
377
- }));
378
-
379
- const config = { __version: '1.0.0' };
380
- const result = processWidgetConfig(config);
381
-
382
- // Should either succeed with warnings or succeed without (if already migrated)
383
- if (result.warnings) {
384
- expect(result.warnings.some(w => w.includes('Migrated'))).toBe(true);
385
- }
386
- });
387
-
388
- test('should skip env interpolation when disabled', () => {
389
- process.env.SKIP_TEST = 'should_not_appear';
390
- const config = { value: '${SKIP_TEST}' };
391
- const result = processWidgetConfig(config, { interpolateEnv: false });
392
- expect(result.success).toBe(true);
393
- expect(result.config.value).toBe('${SKIP_TEST}');
394
- });
395
-
396
- test('should handle errors gracefully', () => {
397
- const result = processWidgetConfig(null, { throwOnError: false });
398
- expect(result.success).toBe(true); // null is valid (returns as-is after processing)
399
- });
400
-
401
- test('should throw when throwOnError is true', () => {
402
- const config = { __version: '99.99.99' }; // Future version
403
- expect(() => {
404
- processWidgetConfig(config, { throwOnError: true });
405
- }).toThrow();
406
- });
407
-
408
- test('should skip version validation when disabled', () => {
409
- const config = { __version: '99.99.99' }; // Future version
410
- const result = processWidgetConfig(config, { validateVersion: false });
411
- expect(result.success).toBe(true);
412
- });
413
-
414
- test('should handle multiple processing steps', () => {
415
- process.env.MULTI_TEST = 'multi_value';
416
- const config = {
417
- __version: '1.0.0',
418
- nested: {
419
- array: ['${MULTI_TEST}', 'static'],
420
- number: 42,
421
- },
422
- };
423
- const result = processWidgetConfig(config);
424
- expect(result.success).toBe(true);
425
- expect(result.config.nested.array[0]).toBe('multi_value');
426
- expect(result.config.nested.array[1]).toBe('static');
427
- expect(result.config.nested.number).toBe(42);
428
- });
429
- });
430
-
431
- describe('DEFAULT_PROCESSING_OPTIONS', () => {
432
- test('should have correct default values', () => {
433
- expect(DEFAULT_PROCESSING_OPTIONS.interpolateEnv).toBe(true);
434
- expect(DEFAULT_PROCESSING_OPTIONS.supportLegacy).toBe(true);
435
- expect(DEFAULT_PROCESSING_OPTIONS.validateVersion).toBe(true);
436
- expect(DEFAULT_PROCESSING_OPTIONS.throwOnError).toBe(false);
437
- });
438
- });
439
-
440
- describe('CONFIG_VERSION', () => {
441
- test('should have CURRENT and MIN_SUPPORTED', () => {
442
- expect(CONFIG_VERSION.CURRENT).toBeDefined();
443
- expect(CONFIG_VERSION.MIN_SUPPORTED).toBeDefined();
444
- expect(typeof CONFIG_VERSION.CURRENT).toBe('string');
445
- expect(typeof CONFIG_VERSION.MIN_SUPPORTED).toBe('string');
446
- });
447
-
448
- test('CURRENT should be >= MIN_SUPPORTED', () => {
449
- expect(compareVersions(CONFIG_VERSION.CURRENT, CONFIG_VERSION.MIN_SUPPORTED)).toBeGreaterThanOrEqual(0);
450
- });
451
- });
452
- });