viberadar 0.3.160 → 0.3.162

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,OAAO,EAAE,UAAU,EAA4H,MAAM,YAAY,CAAC;AAGlK,UAAU,aAAa;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;CACrB;AAuhED,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAo/E1G"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,OAAO,EAAE,UAAU,EAA4H,MAAM,YAAY,CAAC;AAGlK,UAAU,aAAa;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;CACrB;AAuhED,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAwjF1G"}
@@ -4468,6 +4468,109 @@ a{color:var(--blue)}
4468
4468
  return;
4469
4469
  }
4470
4470
  // ── Load testing (k6) ─────────────────────────────────────────────────────
4471
+ // ── Saved k6 scripts library ──────────────────────────────────────────────
4472
+ const scriptsDir = path.join(projectRoot, '.viberadar', 'load-scripts');
4473
+ if (url === '/api/load/scripts' && req.method === 'GET') {
4474
+ try {
4475
+ fs.mkdirSync(scriptsDir, { recursive: true });
4476
+ const files = fs.readdirSync(scriptsDir).filter(f => f.endsWith('.json')).sort().reverse();
4477
+ const list = files.map(f => {
4478
+ try {
4479
+ return JSON.parse(fs.readFileSync(path.join(scriptsDir, f), 'utf-8'));
4480
+ }
4481
+ catch {
4482
+ return null;
4483
+ }
4484
+ }).filter(Boolean);
4485
+ res.writeHead(200, jsonH);
4486
+ res.end(JSON.stringify(list));
4487
+ }
4488
+ catch (e) {
4489
+ res.writeHead(500, jsonH);
4490
+ res.end(JSON.stringify({ error: e.message }));
4491
+ }
4492
+ return;
4493
+ }
4494
+ if (url === '/api/load/scripts' && req.method === 'POST') {
4495
+ let body = '';
4496
+ req.on('data', (d) => { body += d; });
4497
+ req.on('end', () => {
4498
+ try {
4499
+ const { name, script } = JSON.parse(body);
4500
+ if (!name || !script) {
4501
+ res.writeHead(400, jsonH);
4502
+ res.end(JSON.stringify({ error: 'name and script required' }));
4503
+ return;
4504
+ }
4505
+ fs.mkdirSync(scriptsDir, { recursive: true });
4506
+ const safeName = name.replace(/[^a-zA-Zа-яА-ЯёЁ0-9_\- ]/g, '_').slice(0, 80);
4507
+ const date = new Date().toISOString().slice(0, 16).replace('T', ' ');
4508
+ const fileName = `${Date.now()}-${safeName.replace(/\s+/g, '_')}.json`;
4509
+ const entry = { name: safeName, date, script, fileName };
4510
+ // overwrite if same name exists
4511
+ const existing = fs.readdirSync(scriptsDir).find(f => {
4512
+ try {
4513
+ return JSON.parse(fs.readFileSync(path.join(scriptsDir, f), 'utf-8')).name === safeName;
4514
+ }
4515
+ catch {
4516
+ return false;
4517
+ }
4518
+ });
4519
+ if (existing)
4520
+ fs.unlinkSync(path.join(scriptsDir, existing));
4521
+ fs.writeFileSync(path.join(scriptsDir, fileName), JSON.stringify(entry, null, 2), 'utf-8');
4522
+ res.writeHead(200, jsonH);
4523
+ res.end(JSON.stringify({ ok: true }));
4524
+ }
4525
+ catch (e) {
4526
+ res.writeHead(500, jsonH);
4527
+ res.end(JSON.stringify({ error: e.message }));
4528
+ }
4529
+ });
4530
+ return;
4531
+ }
4532
+ const scriptDeleteMatch = url.match(/^\/api\/load\/scripts\/(.+)$/) && req.method === 'DELETE' ? url.match(/^\/api\/load\/scripts\/(.+)$/) : null;
4533
+ if (scriptDeleteMatch) {
4534
+ try {
4535
+ const name = decodeURIComponent(scriptDeleteMatch[1]);
4536
+ fs.mkdirSync(scriptsDir, { recursive: true });
4537
+ const file = fs.readdirSync(scriptsDir).find(f => {
4538
+ try {
4539
+ return JSON.parse(fs.readFileSync(path.join(scriptsDir, f), 'utf-8')).name === name;
4540
+ }
4541
+ catch {
4542
+ return false;
4543
+ }
4544
+ });
4545
+ if (!file) {
4546
+ res.writeHead(404, jsonH);
4547
+ res.end(JSON.stringify({ error: 'Not found' }));
4548
+ return;
4549
+ }
4550
+ fs.unlinkSync(path.join(scriptsDir, file));
4551
+ res.writeHead(200, jsonH);
4552
+ res.end(JSON.stringify({ ok: true }));
4553
+ }
4554
+ catch (e) {
4555
+ res.writeHead(500, jsonH);
4556
+ res.end(JSON.stringify({ error: e.message }));
4557
+ }
4558
+ return;
4559
+ }
4560
+ // ── end saved scripts ──────────────────────────────────────────────────────
4561
+ if (url === '/api/load/ai-script' && req.method === 'GET') {
4562
+ const scriptPath = path.join(projectRoot, '.viberadar', 'load-script-generated.js');
4563
+ try {
4564
+ const script = fs.readFileSync(scriptPath, 'utf-8');
4565
+ res.writeHead(200, jsonH);
4566
+ res.end(JSON.stringify({ script }));
4567
+ }
4568
+ catch {
4569
+ res.writeHead(404, jsonH);
4570
+ res.end(JSON.stringify({ error: 'Script not found' }));
4571
+ }
4572
+ return;
4573
+ }
4471
4574
  if (url === '/api/load/check' && req.method === 'GET') {
4472
4575
  const k6 = (0, child_process_1.spawn)('k6', ['version'], { shell: WIN, stdio: 'pipe' });
4473
4576
  let ver = '';