vibex-sh 0.2.0 → 0.2.2

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 (2) hide show
  1. package/index.js +93 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -377,10 +377,13 @@ async function main() {
377
377
 
378
378
  // Auto-claim session if token is available and fetch auth code
379
379
  let authCode = null;
380
- if (token && !options.sessionId) {
381
- // Only auto-claim new sessions (not when reusing existing session)
380
+ if (token) {
381
+ // Try to claim session (works for both new and existing sessions)
382
+ // For new sessions, this will create and claim
383
+ // For existing sessions, this will return the auth code if user owns it
382
384
  authCode = await claimSession(sessionId, token, webUrl);
383
- if (authCode) {
385
+ if (authCode && !options.sessionId) {
386
+ // Only show claim message for new sessions
384
387
  console.log(' ✓ Session automatically claimed to your account\n');
385
388
  }
386
389
  }
@@ -428,14 +431,19 @@ async function main() {
428
431
  socket.on('connect', () => {
429
432
  isConnected = true;
430
433
  console.log(' ✓ Connected to server\n');
434
+ console.error(`[CLI DEBUG] Socket connected, socket.id: ${socket.id}`);
435
+ console.error(`[CLI DEBUG] About to emit join-session for: ${sessionId}`);
431
436
  // Rejoin session on reconnect
432
437
  socket.emit('join-session', sessionId);
438
+ console.error(`[CLI DEBUG] ✅ join-session emitted, waiting 100ms before setting hasJoinedSession`);
433
439
  // Wait a tiny bit for join-session to be processed
434
440
  setTimeout(() => {
435
441
  hasJoinedSession = true;
442
+ console.error(`[CLI DEBUG] hasJoinedSession set to true, processing ${logQueue.length} queued logs`);
436
443
  // Process any queued logs
437
444
  while (logQueue.length > 0) {
438
445
  const logData = logQueue.shift();
446
+ console.error(`[CLI DEBUG] Emitting queued cli-emit (connect) for sessionId: ${sessionId}`);
439
447
  socket.emit('cli-emit', {
440
448
  sessionId,
441
449
  ...logData,
@@ -446,11 +454,15 @@ async function main() {
446
454
 
447
455
  // Listen for auth code from socket.io (for unclaimed sessions)
448
456
  socket.on('session-auth-code', (data) => {
449
- if (data.sessionId === sessionId && data.authCode && !receivedAuthCode) {
450
- receivedAuthCode = data.authCode;
451
- // Display auth code when received (for both new and existing sessions)
452
- console.log(` 🔑 Auth Code: ${receivedAuthCode}`);
453
- console.log(` 📋 Dashboard: ${webUrl}/${sessionId}?auth=${receivedAuthCode}\n`);
457
+ if (data.sessionId === sessionId && data.authCode) {
458
+ // Always update and display auth code if received from socket
459
+ // This ensures we show it even if we didn't get it from claimSession
460
+ if (!receivedAuthCode || receivedAuthCode !== data.authCode) {
461
+ receivedAuthCode = data.authCode;
462
+ // Display auth code when received (for both new and existing sessions)
463
+ console.log(` 🔑 Auth Code: ${receivedAuthCode}`);
464
+ console.log(` 📋 Dashboard: ${webUrl}/${sessionId}?auth=${receivedAuthCode}\n`);
465
+ }
454
466
  }
455
467
  });
456
468
 
@@ -464,6 +476,7 @@ async function main() {
464
476
  // Process any queued logs
465
477
  while (logQueue.length > 0) {
466
478
  const logData = logQueue.shift();
479
+ console.error(`[CLI DEBUG] Emitting queued cli-emit (reconnect) for sessionId: ${sessionId}`);
467
480
  socket.emit('cli-emit', {
468
481
  sessionId,
469
482
  ...logData,
@@ -502,6 +515,67 @@ async function main() {
502
515
  }
503
516
  });
504
517
 
518
+ // Handle rate limit errors from server
519
+ socket.on('rate-limit-exceeded', (data) => {
520
+ console.error('\n ⚠️ Rate Limit Exceeded');
521
+ console.error(` ${data.message || 'Too many requests. Please try again later.'}`);
522
+ if (data.rateLimit) {
523
+ const { limit, remaining, resetAt, windowSeconds } = data.rateLimit;
524
+ if (limit !== undefined) {
525
+ console.error(` Limit: ${limit} requests`);
526
+ }
527
+ if (remaining !== undefined) {
528
+ console.error(` Remaining: ${remaining} requests`);
529
+ }
530
+ if (resetAt) {
531
+ const resetDate = new Date(resetAt);
532
+ const now = new Date();
533
+ const secondsUntilReset = Math.ceil((resetDate - now) / 1000);
534
+ if (secondsUntilReset > 0) {
535
+ console.error(` Resets in: ${secondsUntilReset} seconds`);
536
+ }
537
+ }
538
+ }
539
+ console.error('');
540
+ // Don't exit - let user decide, but clear the queue
541
+ logQueue.length = 0;
542
+ });
543
+
544
+ // Handle general errors from server
545
+ socket.on('error', (data) => {
546
+ // Check if it's a history limit error
547
+ if (data && data.error === 'History Limit Reached') {
548
+ console.error('\n 🚫 History Limit Reached');
549
+ console.error(` ${data.message || 'Session history limit reached'}`);
550
+ if (data.limit !== undefined && data.current !== undefined) {
551
+ console.error(` Current: ${data.current} / ${data.limit} logs`);
552
+ }
553
+ if (data.upgradeRequired) {
554
+ console.error(' 💡 Upgrade to Pro to unlock 30 days retention');
555
+ console.error(' 🌐 Visit: https://vibex.sh/pricing');
556
+ }
557
+ console.error('');
558
+ // Clear the queue and stop processing
559
+ logQueue.length = 0;
560
+ hasJoinedSession = false; // Prevent further logs from being sent
561
+ return;
562
+ }
563
+
564
+ // Handle other errors
565
+ console.error('\n ✗ Server Error');
566
+ if (typeof data === 'string') {
567
+ console.error(` ${data}`);
568
+ } else if (data && data.message) {
569
+ console.error(` ${data.message}`);
570
+ if (data.error) {
571
+ console.error(` Error: ${data.error}`);
572
+ }
573
+ } else {
574
+ console.error(' An unexpected error occurred');
575
+ }
576
+ console.error('');
577
+ });
578
+
505
579
  const rl = readline.createInterface({
506
580
  input: process.stdin,
507
581
  output: process.stdout,
@@ -509,8 +583,10 @@ async function main() {
509
583
  });
510
584
 
511
585
  rl.on('line', (line) => {
586
+ console.error(`[CLI DEBUG] Received line from stdin: "${line}"`);
512
587
  const trimmedLine = line.trim();
513
588
  if (!trimmedLine) {
589
+ console.error(`[CLI DEBUG] Line is empty, skipping`);
514
590
  return;
515
591
  }
516
592
 
@@ -522,22 +598,31 @@ async function main() {
522
598
  payload: parsed,
523
599
  timestamp: Date.now(),
524
600
  };
601
+ console.error(`[CLI DEBUG] Parsed as JSON log`);
525
602
  } catch (e) {
526
603
  logData = {
527
604
  type: 'text',
528
605
  payload: trimmedLine,
529
606
  timestamp: Date.now(),
530
607
  };
608
+ console.error(`[CLI DEBUG] Parsed as text log`);
531
609
  }
532
610
 
611
+ console.error(`[CLI DEBUG] Connection state - isConnected: ${isConnected}, hasJoinedSession: ${hasJoinedSession}, socket.connected: ${socket?.connected}`);
612
+
533
613
  // If connected and joined session, send immediately; otherwise queue it
534
614
  if (isConnected && hasJoinedSession && socket.connected) {
615
+ console.error(`[CLI DEBUG] ✅ Ready to emit - Emitting cli-emit for sessionId: ${sessionId}`);
616
+ console.error(`[CLI DEBUG] Log data:`, JSON.stringify(logData, null, 2));
535
617
  socket.emit('cli-emit', {
536
618
  sessionId,
537
619
  ...logData,
538
620
  });
621
+ console.error(`[CLI DEBUG] ✅ cli-emit event emitted successfully`);
539
622
  } else {
623
+ console.error(`[CLI DEBUG] ⏸️ Queueing log - isConnected: ${isConnected}, hasJoinedSession: ${hasJoinedSession}, socket.connected: ${socket?.connected}`);
540
624
  logQueue.push(logData);
625
+ console.error(`[CLI DEBUG] Queue now has ${logQueue.length} items`);
541
626
  }
542
627
  });
543
628
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibex-sh",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Zero-config observability CLI - pipe logs and visualize instantly",
5
5
  "type": "module",
6
6
  "bin": {